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

SourceCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
lcom 2
cbo 0
dl 0
loc 69
c 1
b 0
f 1
ccs 16
cts 20
cp 0.8
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 4 1
A count() 0 4 1
A addLocation() 0 4 1
A addError() 0 4 1
A first() 0 8 2
A get() 0 8 2
A getErrors() 0 4 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
    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