Lines
66.66%
2 / 3
Functions and Methods
66.66%
2 / 3
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| EveryNthOccurrence | 66.66% | 2 / 3 | 66.66% | 2 / 3 | 5.93 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| forRepeatedWarnings | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| includesOccurrence | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Logging; | |
| 6 | ||
| 7 | final readonly class EveryNthOccurrence | |
| 8 | { | |
| 9 | private const int REPEATED_WARNING_INTERVAL = 100; | |
| 10 | ||
| 11 | public function __construct(private int $every) {} | |
| 12 | ||
| 13 | public static function forRepeatedWarnings(): self | |
| 14 | { | |
| 15 | return new self(self::REPEATED_WARNING_INTERVAL); | |
| 16 | } | |
| 17 | ||
| 18 | public function includesOccurrence(int $occurrence): bool | |
| 19 | { | |
| 20 | return $occurrence === 1 || ($occurrence > 0 && $occurrence % $this->every === 0); | |
| 21 | } | |
| 22 | } |