Worlds   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 64
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 9 4
A get() 0 13 3
A push() 0 4 1
A getIterator() 0 3 1
A count() 0 3 1
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
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
        $filter = function( $world, /** @scrutinizer ignore-unused */ $id ) use ($id_or_slug) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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