Completed
Push — master ( bdaaad...4f4372 )
by personal
04:35 queued 45s
created

Violations::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Hal\Violation;
3
4
5
/**
6
 * Class Violations
7
 * @package Hal\Violation
8
 */
9
class Violations implements \IteratorAggregate, \Countable
10
{
11
    /**
12
     * @var array
13
     */
14
    private $data = [];
15
16
    /**
17
     * @inheritdoc
18
     */
19
    public function getIterator()
20
    {
21
        return new \ArrayIterator($this->data);
22
    }
23
24
    /**
25
     * @param Violation $violation
26
     */
27
    public function add(Violation $violation)
28
    {
29
        $this->data[] = clone $violation;
30
    }
31
32
    /**
33
     * @return int
34
     */
35
    public function count()
36
    {
37
        return sizeof($this->data);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function __toString()
44
    {
45
        $string = '';
46
        foreach ($this->data as $violation) {
47
            $string .= $violation->getName() . ',';
48
        }
49
        return $string;
50
    }
51
}
52