Total Complexity | 8 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class UniqueObjectCollection implements ObjectCollectionInterface |
||
6 | { |
||
7 | /** |
||
8 | * @var \SplObjectStorage |
||
9 | */ |
||
10 | protected $objects; |
||
11 | |||
12 | public function __construct() |
||
13 | { |
||
14 | $this->objects = new \SplObjectStorage(); |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | public function addOne($object) |
||
21 | { |
||
22 | if (!is_object($object)) { |
||
23 | $object = new NonObjectWrapper($object); |
||
24 | } |
||
25 | |||
26 | $this->objects->attach($object); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function addMany(array $objects) |
||
33 | { |
||
34 | foreach ($objects as $object) { |
||
35 | $this->addOne($object); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function getAll(): array |
||
52 | } |
||
53 | } |
||
54 |