ResultList   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A addResult() 0 4 1
A getResults() 0 6 1
A getIterator() 0 4 1
1
<?php
2
namespace CViniciusSDias\GoogleCrawler;
3
4
use Ds\Vector;
5
6
/**
7
 * List of Results
8
 *
9
 * @package CViniciusSDias\GoogleCrawler
10
 * @author Vinicius Dias
11
 */
12
class ResultList implements \IteratorAggregate
13
{
14
    /** @var Vector $results */
15
    private $results;
16
17
    /**
18
     * Initializes the result Vector
19
     *
20
     * @param int|null $capacity If informed, the vector is initialized with this capacity
21
     */
22 3
    public function __construct(int $capacity = null)
23
    {
24 3
        $this->results = new Vector();
25
26 3
        if (!is_null($capacity)) {
27 2
            $this->results->allocate($capacity);
28
        }
29 3
    }
30
31
    /**
32
     * Adds a result to the list
33
     *
34
     * @param Result $result
35
     */
36 2
    public function addResult(Result $result)
37
    {
38 2
        $this->results->push($result);
39 2
    }
40
41
    /**
42
     * Gets all the results.
43
     * This method returns a unmodifiable copy of the original collection
44
     *
45
     * @return Vector
46
     */
47 2
    public function getResults(): Vector
48
    {
49
        /** @var Vector $copy */
50 2
        $copy = $this->results->copy();
51 2
        return $copy;
52
    }
53
54
    /** {@inheritdoc} */
55 1
    public function getIterator(): \Iterator
56
    {
57 1
        return new \IteratorIterator($this->results);
58
    }
59
}
60