| Total Complexity | 4 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 7 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | abstract class Source implements IteratorAggregate |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The configuration. |
||
| 18 | * |
||
| 19 | * @var Config |
||
| 20 | */ |
||
| 21 | protected Config $config; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The cached size of the JSON source. |
||
| 25 | * |
||
| 26 | * @var int|null |
||
| 27 | */ |
||
| 28 | protected ?int $size; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Whether the JSON size has already been calculated. |
||
| 32 | * Avoid re-calculations when the size is NULL (not computable). |
||
| 33 | * |
||
| 34 | * @var bool |
||
| 35 | */ |
||
| 36 | protected bool $sizeWasSet = false; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Retrieve the JSON fragments |
||
| 40 | * |
||
| 41 | * @return Traversable<int, string> |
||
| 42 | */ |
||
| 43 | abstract public function getIterator(): Traversable; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Determine whether the JSON source can be handled |
||
| 47 | * |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | abstract public function matches(): bool; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Retrieve the calculated size of the JSON source |
||
| 54 | * |
||
| 55 | * @return int|null |
||
| 56 | */ |
||
| 57 | abstract protected function calculateSize(): ?int; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Enforce the factory method to instantiate the class. |
||
| 61 | * |
||
| 62 | * @param mixed $source |
||
| 63 | * @param Config|null $config |
||
| 64 | */ |
||
| 65 | 352 | final public function __construct(protected mixed $source, Config $config = null) |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Retrieve the size of the JSON source and cache it |
||
| 72 | * |
||
| 73 | * @return int|null |
||
| 74 | */ |
||
| 75 | 329 | public function size(): ?int |
|
| 85 |