| Total Complexity | 10 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | abstract class RunContext |
||
| 11 | { |
||
| 12 | private $startTime; |
||
| 13 | private $duration; |
||
| 14 | private $memory; |
||
| 15 | |||
| 16 | 78 | public function __construct() |
|
| 17 | { |
||
| 18 | 78 | $this->startTime = \time(); |
|
| 19 | 78 | } |
|
| 20 | |||
| 21 | abstract public function __toString(): string; |
||
| 22 | |||
| 23 | 36 | final public function startTime(): int |
|
| 24 | { |
||
| 25 | 36 | return $this->startTime; |
|
| 26 | } |
||
| 27 | |||
| 28 | 36 | final public function hasRun(): bool |
|
| 29 | { |
||
| 30 | 36 | return null !== $this->memory; |
|
| 31 | } |
||
| 32 | |||
| 33 | 13 | final public function getDuration(): int |
|
| 34 | { |
||
| 35 | 13 | $this->ensureHasRun(); |
|
| 36 | |||
| 37 | 13 | return $this->duration; |
|
| 38 | } |
||
| 39 | |||
| 40 | 13 | final public function getFormattedDuration(): string |
|
| 41 | { |
||
| 42 | 13 | return Helper::formatTime($this->getDuration()); |
|
|
|
|||
| 43 | } |
||
| 44 | |||
| 45 | 13 | final public function getMemory(): int |
|
| 46 | { |
||
| 47 | 13 | $this->ensureHasRun(); |
|
| 48 | |||
| 49 | 13 | return $this->memory; |
|
| 50 | } |
||
| 51 | |||
| 52 | 13 | final public function getFormattedMemory(): string |
|
| 55 | } |
||
| 56 | |||
| 57 | 34 | final protected function markAsRun(int $memory): void |
|
| 61 | 34 | } |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @throws \LogicException if has not yet run |
||
| 65 | */ |
||
| 66 | 36 | final protected function ensureHasRun(): void |
|
| 67 | { |
||
| 73 |