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