UrlCollection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 71
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 6 2
A contains() 0 4 1
A count() 0 4 1
A reset() 0 4 1
A toArray() 0 9 2
A pop() 0 9 2
1
<?php
2
3
namespace MediaMonks\Crawler\Url;
4
5
use MediaMonks\Crawler\Exception\EmptyCollectionException;
6
use MediaMonks\Crawler\Url;
7
8
class UrlCollection implements \Countable
9
{
10
11
    /**
12
     * @var Url[]
13
     */
14
    private $urls = [];
15
16
    /**
17
     * @param Url $url
18
     */
19 11
    public function push(Url $url)
20
    {
21 11
        if (!$this->contains($url)) {
22 11
            $this->urls[$url->__toString()] = $url;
23 11
        }
24 11
    }
25
26
    /**
27
     * @return Url|false
28
     * @throws EmptyCollectionException
29
     */
30 10
    public function pop()
31
    {
32 10
        $url = array_pop($this->urls);
33 10
        if (empty($url)) {
34 7
            return false;
35
        }
36
37 10
        return $url;
38
    }
39
40
    /**
41
     * @param Url $url
42
     *
43
     * @return bool
44
     */
45 11
    public function contains(Url $url)
46
    {
47 11
        return isset($this->urls[$url->__toString()]);
48
    }
49
50
    /**
51
     * @return int
52
     */
53 1
    public function count()
54
    {
55 1
        return count($this->urls);
56
    }
57
58
    /**
59
     * @return void
60
     */
61 11
    public function reset()
62
    {
63 11
        $this->urls = [];
64 11
    }
65
66
    /**
67
     * @return array
68
     */
69 9
    public function toArray()
70
    {
71 9
        $stringified = [];
72 9
        foreach ($this->urls as $url) {
73 8
            $stringified[] = $url->__toString();
74 9
        }
75
76 9
        return $stringified;
77
    }
78
}
79