IssueCollection::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Issue;
5
6
use Helmich\TypoScriptLint\Linter\Report\Issue;
7
use Pluswerk\TypoScriptAutoFixer\Issue\AbstractIssue;
8
9
class IssueCollection implements \Countable, \Iterator
10
{
11
    /**
12
     * @var AbstractIssue[]
13
     */
14
    private $issues = [];
15
16
    /**
17
     * @param AbstractIssue $issue
18
     */
19
    public function add(AbstractIssue $issue): void
20
    {
21
        $this->issues[] = $issue;
22
        usort($this->issues, static function ($a, $b) {
23
            /** @var AbstractIssue $a */
24
            /** @var AbstractIssue $b */
25
            if ($a->line() > $b->line()) {
26
                return 1;
27
            }
28
            if ($a->line() < $b->line()) {
29
                return -1;
30
            }
31
            if ($a->line() === $b->line()) {
32
                return 0;
33
            }
34
        });
35
    }
36
37
    /**
38
     * @return AbstractIssue
39
     */
40
    public function current(): AbstractIssue
41
    {
42
        return current($this->issues);
43
    }
44
45
    /**
46
     * @return void
47
     */
48
    public function next(): void
49
    {
50
        next($this->issues);
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function key(): int
57
    {
58
        return key($this->issues);
0 ignored issues
show
Bug Best Practice introduced by
The expression return key($this->issues) could return the type null|string which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function valid(): bool
65
    {
66
        return key($this->issues) !== null;
67
    }
68
69
    /**
70
     * @return void
71
     */
72
    public function rewind(): void
73
    {
74
        reset($this->issues);
75
    }
76
77
    /**
78
     * @return int
79
     */
80
    public function count(): int
81
    {
82
        return count($this->issues);
83
    }
84
}
85