Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
79.17% |
19 / 24 |
|
55.56% |
5 / 9 |
CRAP | |
0.00% |
0 / 1 |
| Profiler | |
79.17% |
19 / 24 |
|
55.56% |
5 / 9 |
18.31 | |
0.00% |
0 / 1 |
| __construct | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| setDebugger | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getDebugger | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| debugger | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasDebugger | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addStep | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| getSteps | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCurrentStep | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __get | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Db\Adapter\Profiler; |
| 16 | |
| 17 | use Pop\Utils\DebuggerInterface; |
| 18 | |
| 19 | /** |
| 20 | * MySQL database adapter profiler class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Db |
| 24 | * @author Nick Sagona, III <nick@popphp.org> |
| 25 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 7.0.0 |
| 28 | * |
| 29 | * @property-read ?Step $current Current step |
| 30 | */ |
| 31 | class Profiler extends AbstractProfiler |
| 32 | { |
| 33 | |
| 34 | /** |
| 35 | * Profiler current step index |
| 36 | * @var int |
| 37 | */ |
| 38 | protected int $currentIndex = 0; |
| 39 | |
| 40 | /** |
| 41 | * Profiler steps |
| 42 | * @var array |
| 43 | */ |
| 44 | protected array $steps = []; |
| 45 | |
| 46 | /** |
| 47 | * Debugger |
| 48 | * @var ?DebuggerInterface |
| 49 | */ |
| 50 | protected ?DebuggerInterface $debugger = null; |
| 51 | |
| 52 | /** |
| 53 | * Constructor |
| 54 | * |
| 55 | * Instantiate the profiler object |
| 56 | * @param ?DebuggerInterface $debugger |
| 57 | */ |
| 58 | public function __construct(?DebuggerInterface $debugger = null) |
| 59 | { |
| 60 | parent::__construct(); |
| 61 | if ($debugger !== null) { |
| 62 | $this->setDebugger($debugger); |
| 63 | } |
| 64 | } |
| 65 | /** |
| 66 | |
| 67 | * Set debugger |
| 68 | * |
| 69 | * @param DebuggerInterface $debugger |
| 70 | * @return Profiler |
| 71 | */ |
| 72 | public function setDebugger(DebuggerInterface $debugger): Profiler |
| 73 | { |
| 74 | $this->debugger = $debugger; |
| 75 | return $this; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get debugger |
| 80 | * |
| 81 | * @return ?DebuggerInterface |
| 82 | */ |
| 83 | public function getDebugger(): ?DebuggerInterface |
| 84 | { |
| 85 | return $this->debugger; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get debugger (alias) |
| 90 | * |
| 91 | * @return ?DebuggerInterface |
| 92 | */ |
| 93 | public function debugger(): ?DebuggerInterface |
| 94 | { |
| 95 | return $this->debugger; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Has debugger |
| 100 | * |
| 101 | * @return bool |
| 102 | */ |
| 103 | public function hasDebugger(): bool |
| 104 | { |
| 105 | return ($this->debugger !== null); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Add step |
| 110 | * |
| 111 | * @param ?Step $step |
| 112 | * @return Profiler |
| 113 | */ |
| 114 | public function addStep(?Step $step = null): Profiler |
| 115 | { |
| 116 | if ($step === null) { |
| 117 | $step = new Step(); |
| 118 | } |
| 119 | $this->steps[] = $step; |
| 120 | $this->currentIndex = count($this->steps) - 1; |
| 121 | |
| 122 | return $this; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Get steps |
| 127 | * |
| 128 | * @return array |
| 129 | */ |
| 130 | public function getSteps(): array |
| 131 | { |
| 132 | return $this->steps; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Get current step |
| 137 | * |
| 138 | * @return ?Step |
| 139 | */ |
| 140 | public function getCurrentStep(): ?Step |
| 141 | { |
| 142 | return $this->steps[$this->currentIndex] ?? null; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Magic method to support shorthand calls to certain values in the profiler |
| 147 | * |
| 148 | * @param string $name |
| 149 | * @return mixed |
| 150 | */ |
| 151 | public function __get(string $name) |
| 152 | { |
| 153 | switch ($name) { |
| 154 | case 'start': |
| 155 | return $this->start; |
| 156 | case 'finish': |
| 157 | return $this->finish; |
| 158 | case 'current': |
| 159 | return $this->getCurrentStep(); |
| 160 | case 'elapsed': |
| 161 | return $this->getElapsed(); |
| 162 | default: |
| 163 | return null; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | } |