ViolationIterator::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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