| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 6 | class TimerTaskDecorator implements TaskDecorator |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @var TimerEvents |
||
| 10 | */ |
||
| 11 | private $events; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var float[] |
||
| 15 | */ |
||
| 16 | private $startTimeStack = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var Clock |
||
| 20 | */ |
||
| 21 | private $clock; |
||
| 22 | |||
| 23 | 9 | public function __construct(?Clock $clock = null) |
|
| 24 | { |
||
| 25 | 9 | $this->events = new TimerEvents(); |
|
| 26 | 9 | $this->clock = $clock ?? new SystemClock(); |
|
| 27 | 9 | } |
|
| 28 | |||
| 29 | 3 | public function name(): string |
|
| 30 | { |
||
| 31 | 3 | return 'timer'; |
|
| 32 | } |
||
| 33 | |||
| 34 | 9 | public function callbackBefore(string $taskName): callable |
|
| 35 | { |
||
| 36 | return function () use ($taskName) { |
||
| 37 | 9 | \array_push($this->startTimeStack, $this->clock->microtime()); |
|
| 38 | 9 | $this->events->append(new TimerEvent(TimerEvent::TYPE_BEGIN, $taskName, $this->clock->microtime(), 0)); |
|
| 39 | 9 | }; |
|
| 40 | } |
||
| 41 | |||
| 42 | 9 | public function callbackAfter(string $taskName): callable |
|
| 49 | ); |
||
| 50 | 9 | }; |
|
| 51 | } |
||
| 52 | |||
| 53 | 9 | public function resultsAsCsv(): string |
|
| 56 | } |
||
| 57 | } |
||
| 58 |