1 | <?php |
||
2 | namespace Germania\Worlds; |
||
3 | |||
4 | use Germania\Worlds\Exceptions\WorldNotFoundException; |
||
5 | |||
6 | |||
7 | class Worlds implements WorldsInterface |
||
8 | { |
||
9 | public $worlds = array(); |
||
10 | |||
11 | |||
12 | public function push( WorldInterface $world ) |
||
13 | { |
||
14 | $this->worlds[ $world->getId() ] = $world; |
||
15 | return $this; |
||
16 | } |
||
17 | |||
18 | /** |
||
19 | * @implements ContainerInterface |
||
20 | * @return WorldInterface |
||
21 | */ |
||
22 | public function get( $id_or_slug ) |
||
23 | { |
||
24 | $filter = function( $world, $id ) use ($id_or_slug) { |
||
0 ignored issues
–
show
|
|||
25 | return ($world->getId() == $id_or_slug |
||
26 | or $world->getSlug() == $id_or_slug); |
||
27 | }; |
||
28 | |||
29 | $worlds = new \CallbackFilterIterator( $this->getIterator(), $filter); |
||
30 | $worlds->rewind(); |
||
31 | if ($worlds->valid()): |
||
32 | return $worlds->current(); |
||
33 | else: |
||
34 | throw new WorldNotFoundException("Could not find product world with ID or slug '$id_or_slug'"); |
||
35 | endif; |
||
36 | } |
||
37 | |||
38 | |||
39 | |||
40 | /** |
||
41 | * @implements ContainerInterface |
||
42 | * @return boolean |
||
43 | */ |
||
44 | public function has ($id_or_slug ) |
||
45 | { |
||
46 | foreach ($this->worlds as $world) { |
||
47 | if ($world->getId() == $id_or_slug |
||
48 | or $world->getSlug() == $id_or_slug) { |
||
49 | return true; |
||
50 | } |
||
51 | } |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @implements IteratorAggregate |
||
58 | */ |
||
59 | public function getIterator() |
||
60 | { |
||
61 | return new \ArrayIterator($this->worlds); |
||
62 | } |
||
63 | |||
64 | |||
65 | /** |
||
66 | * @implements Countable |
||
67 | */ |
||
68 | public function count() |
||
69 | { |
||
70 | return count($this->worlds); |
||
71 | } |
||
72 | } |
||
73 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.