Total Complexity | 7 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | final class FrameCollection extends ArrayObject implements IFrameCollection |
||
20 | { |
||
21 | /** |
||
22 | * @throws InvalidArgumentException |
||
23 | */ |
||
24 | public function __construct(Traversable $frames) |
||
25 | { |
||
26 | parent::__construct(); |
||
27 | $this->initialize($frames); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @throws InvalidArgumentException |
||
32 | */ |
||
33 | private function initialize(Traversable $frames): void |
||
34 | { |
||
35 | /** @var T $frame */ |
||
36 | foreach ($frames as $frame) { |
||
37 | self::assertFrame($frame); |
||
38 | $this->append($frame); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @throws InvalidArgumentException |
||
44 | */ |
||
45 | private static function assertFrame(mixed $frame): void |
||
46 | { |
||
47 | if (!$frame instanceof IFrame) { |
||
48 | throw new InvalidArgumentException( |
||
49 | sprintf( |
||
50 | 'Frame must be instance of %s. %s given.', // TODO: clarify message |
||
51 | IFrame::class, |
||
52 | get_debug_type($frame) |
||
53 | ) |
||
54 | ); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** @inheritdoc */ |
||
59 | public function lastIndex(): int |
||
65 | } |
||
66 | |||
67 | public function get(int $index): IFrame |
||
70 | } |
||
71 | } |
||
72 |