ViolationIterator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 47
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A count() 0 3 1
A current() 0 3 1
A jsonSerialize() 0 3 1
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard\Violation;
8
9
use ArrayIterator;
10
use IteratorIterator;
11
12
class ViolationIterator extends IteratorIterator implements
13
    ViolationIteratorInterface
14
{
15
    /** @var int */
16
    private $numViolations;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param ViolationInterface ...$violations
22
     */
23 3
    public function __construct(ViolationInterface ...$violations)
24
    {
25 3
        $this->numViolations = count($violations);
26 3
        parent::__construct(
27 3
            new ArrayIterator($violations)
28
        );
29 3
    }
30
31
    /**
32
     * Get the current violation.
33
     *
34
     * @return ViolationInterface
35
     */
36 2
    public function current(): ViolationInterface
37
    {
38 2
        return parent::current();
39
    }
40
41
    /**
42
     * Get the number of violations.
43
     *
44
     * @return int
45
     */
46 3
    public function count(): int
47
    {
48 3
        return $this->numViolations;
49
    }
50
51
    /**
52
     * Specify data that should be serialized to JSON.
53
     *
54
     * @return array
55
     */
56 3
    public function jsonSerialize(): array
57
    {
58 3
        return iterator_to_array($this);
59
    }
60
}
61