SourceCollection::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Extractor\Model;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
final class SourceCollection implements \Countable, \IteratorAggregate
18
{
19
    /**
20
     * @var SourceLocation[]
21
     */
22
    private $sourceLocations = [];
23
24
    /**
25
     * @var Error[]
26
     */
27
    private $errors = [];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    public function getIterator(): \Traversable
33
    {
34 2
        return new \ArrayIterator($this->sourceLocations);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 32
    public function count(): int
41
    {
42 32
        return \count($this->sourceLocations);
43
    }
44
45 33
    public function addLocation(SourceLocation $location): void
46
    {
47 33
        $this->sourceLocations[] = $location;
48 33
    }
49
50 10
    public function addError(Error $error): void
51
    {
52 10
        $this->errors[] = $error;
53 10
    }
54
55 9
    public function first(): ?SourceLocation
56
    {
57 9
        if (empty($this->sourceLocations)) {
58
            return null;
59
        }
60
61 9
        return reset($this->sourceLocations);
62
    }
63
64 21
    public function get(string $key): ?SourceLocation
65
    {
66 21
        if (!isset($this->sourceLocations[$key])) {
67
            return null;
68
        }
69
70 21
        return $this->sourceLocations[$key];
71
    }
72
73 9
    public function getErrors(): array
74
    {
75 9
        return $this->errors;
76
    }
77
}
78