| Total Complexity | 14 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 7 | class TimeKeeper |
||
| 8 | { |
||
| 9 | private int $_expirationIntervalSeconds; |
||
| 10 | private DateTimeImmutable | null $_expiresAt = null; |
||
|
|
|||
| 11 | |||
| 12 | 44 | public function __construct(int $intervalInSeconds) |
|
| 13 | { |
||
| 14 | 44 | $this->_expirationIntervalSeconds = $intervalInSeconds; |
|
| 15 | 44 | } |
|
| 16 | |||
| 17 | 1 | public static function create(int $intervalInSeconds): self |
|
| 18 | { |
||
| 19 | 1 | return new static($intervalInSeconds); |
|
| 20 | } |
||
| 21 | |||
| 22 | 28 | public function getExpiration(): ?DateTimeImmutable |
|
| 23 | { |
||
| 24 | 28 | return $this->_expiresAt; |
|
| 25 | } |
||
| 26 | |||
| 27 | 4 | public function setExpiration(DateTimeImmutable $expiresAt): self |
|
| 28 | { |
||
| 29 | 4 | $this->_expiresAt = $expiresAt; |
|
| 30 | |||
| 31 | 4 | return $this; |
|
| 32 | } |
||
| 33 | |||
| 34 | 33 | private function _getTimeDiff(): ?int |
|
| 35 | { |
||
| 36 | 33 | if ($this->_expiresAt === null) { |
|
| 37 | 1 | return null; |
|
| 38 | } |
||
| 39 | |||
| 40 | 33 | return $this->_expiresAt->getTimestamp() - SystemClock::create()->now()->getTimestamp(); |
|
| 41 | } |
||
| 42 | |||
| 43 | 32 | public function getRemainingSeconds(): int |
|
| 44 | { |
||
| 45 | 32 | if ($this->_expiresAt === null) { |
|
| 46 | 1 | return $this->_expirationIntervalSeconds; |
|
| 47 | } |
||
| 48 | |||
| 49 | 31 | $diff = $this->_getTimeDiff(); |
|
| 50 | |||
| 51 | 31 | return $diff !== null && $diff >= 0 ? $diff : $this->_expirationIntervalSeconds; |
|
| 52 | } |
||
| 53 | |||
| 54 | 29 | public function isExpired(): bool |
|
| 55 | { |
||
| 56 | 29 | $diff = $this->_getTimeDiff(); |
|
| 57 | 29 | if ($diff === null) { |
|
| 58 | 1 | return false; |
|
| 59 | } |
||
| 60 | |||
| 61 | 29 | return $diff <= 0; |
|
| 62 | } |
||
| 63 | |||
| 64 | 3 | public function reset(): void |
|
| 67 | 3 | } |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Initialize the expiration date for the request timer. |
||
| 71 | */ |
||
| 72 | 35 | public function start(): void |
|
| 75 | 35 | } |
|
| 76 | } |
||
| 77 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths