ResultList::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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