Completed
Push — master ( b529c8...c95386 )
by Tobias
02:42
created

SourceCollection::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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
    public function getIterator()
30
    {
31
        return new \ArrayIterator($this->sourceLocations);
32
    }
33
34 17
    public function count()
35
    {
36 17
        return count($this->sourceLocations);
37
    }
38
39
    /**
40
     * @param SourceLocation $location
41
     */
42 17
    public function addLocation(SourceLocation $location)
43
    {
44 17
        $this->sourceLocations[] = $location;
45 17
    }
46
47
    /**
48
     * @param Error $error
49
     */
50 5
    public function addError(Error $error)
51
    {
52 5
        $this->errors[] = $error;
53 5
    }
54
55
    /**
56
     * @return SourceLocation|null
57
     */
58 8
    public function first()
59
    {
60 8
        if (empty($this->sourceLocations)) {
61
            return;
62
        }
63
64 8
        return reset($this->sourceLocations);
65
    }
66
67
    /**
68
     * @param $key
69
     *
70
     * @return null|SourceLocation
71
     */
72 8
    public function get($key)
73
    {
74 8
        if (!isset($this->sourceLocations[$key])) {
75
            return;
76
        }
77
78 8
        return $this->sourceLocations[$key];
79
    }
80
81 3
    public function getErrors()
82
    {
83 3
        return $this->errors;
84
    }
85
}
86