Identifier   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 79
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 3 1
A current() 0 3 1
A reverseItems() 0 6 2
A valid() 0 3 1
A next() 0 3 1
A key() 0 3 1
A count() 0 3 1
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Pluswerk\TypoScriptAutoFixer\Fixer\NestingConsistency;
5
6
final class Identifier implements \Iterator, \Countable
7
{
8
    /**
9
     * @var array
10
     */
11
    private $items;
12
13
    /**
14
     * @var Identifier
15
     */
16
    private $reverseItems = null;
17
18
    /**
19
     * Identifier constructor.
20
     *
21
     * @param string $identifier
22
     */
23
    public function __construct(string $identifier)
24
    {
25
        $this->items = explode('.', $identifier);
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function current(): string
32
    {
33
        return current($this->items);
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    public function next(): void
40
    {
41
        next($this->items);
42
    }
43
44
    /**
45
     * @return int
46
     */
47
    public function key(): int
48
    {
49
        return key($this->items);
0 ignored issues
show
Bug Best Practice introduced by
The expression return key($this->items) 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...
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function valid(): bool
56
    {
57
        return key($this->items) !== null;
58
    }
59
60
    /**
61
     * @return void
62
     */
63
    public function rewind(): void
64
    {
65
        reset($this->items);
66
    }
67
68
    /**
69
     * @return int
70
     */
71
    public function count(): int
72
    {
73
        return count($this->items);
74
    }
75
76
    /**
77
     * @return Identifier
78
     */
79
    public function reverseItems(): Identifier
80
    {
81
        if (!($this->reverseItems instanceof Identifier)) {
0 ignored issues
show
introduced by
$this->reverseItems is always a sub-type of Pluswerk\TypoScriptAutoF...gConsistency\Identifier.
Loading history...
82
            $this->reverseItems = new Identifier(implode('.', array_reverse($this->items)));
83
        }
84
        return $this->reverseItems;
85
    }
86
}
87