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