GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArrayObject   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 49
dl 0
loc 153
rs 10
c 2
b 0
f 0
wmc 18

12 Methods

Rating   Name   Duplication   Size   Complexity  
A hasNextItem() 0 3 1
A getSize() 0 3 1
A setToNextItem() 0 3 1
A checkItemsType() 0 7 2
A serialize() 0 6 1
A add() 0 7 1
A toArray() 0 7 2
A getCurrentItem() 0 6 1
A unserialize() 0 6 1
A __construct() 0 17 5
A addWithkey() 0 7 1
A get() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\Common\Model;
6
7
use LM\Common\Type\TypeCheckerTrait;
8
use Serializable;
9
use UnexpectedValueException;
10
11
/**
12
 * Object that provides the features of an array as an object.
13
 *
14
 * @deprecated
15
 * @todo Delete?
16
 */
17
class ArrayObject implements Serializable
18
{
19
    use TypeCheckerTrait;
0 ignored issues
show
Deprecated Code introduced by
The trait LM\Common\Type\TypeCheckerTrait has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

19
    use /** @scrutinizer ignore-deprecated */ TypeCheckerTrait;

This trait has been deprecated. The supplier of the trait has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead.

Loading history...
20
21
    /** @var int */
22
    private $currentItemIndex;
23
24
    /** @var mixed[] */
25
    private $items;
26
27
    /** @var string */
28
    private $type;
29
30
    /**
31
     * @param mixed[] $items An array of items to initialise the objec with. The
32
     * constructor checks they are of the type $type.
33
     * @param string $type The type of the items of the array object.
34
     */
35
    public function __construct(array $items, string $type)
36
    {
37
        $this->items = [];
38
        foreach ($items as $key => $item) {
39
            $this->checkType($item, $type);
40
            if ($this->isStringType($type)) {
41
                $this->items[$key] = $item;
42
            } elseif ($this->isIntegerType($type)) {
43
                $this->items[$key] = $item;
44
            } elseif ($this->isClassOrInterfaceName($type)) {
45
                $this->items[$key] = $item;
46
            } else {
47
                throw new UnexpectedValueException();
48
            }
49
        }
50
        $this->currentItemIndex = 0;
51
        $this->type = $type;
52
    }
53
54
    /**
55
     * Returns a copy of the object with a value added to it.
56
     *
57
     * @param mixed $value The item to add to the array object.
58
     * @todo Rename to append.
59
     * @todo Remove $type parameter.
60
     */
61
    public function add($value, string $type = null): self
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function add($value, /** @scrutinizer ignore-unused */ string $type = null): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        $this->checkType($value, $this->type);
64
        $items = $this->items;
65
        $items[] = $value;
66
67
        return new self($items, $this->type);
68
    }
69
70
    /**
71
     * @todo Remove type parameter.
72
     */
73
    public function checkItemsType(string $type = null): self
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
    public function checkItemsType(/** @scrutinizer ignore-unused */ string $type = null): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        foreach ($this->items as $item) {
76
            $this->checkType($item, $this->type);
77
        }
78
79
        return $this;
80
    }
81
82
    /**
83
     * @todo Delete
84
     * @todo Rename to add.
85
     * @todo Remove type parameter.
86
     */
87
    public function addWithkey($key, $value, string $type): self
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function addWithkey($key, $value, /** @scrutinizer ignore-unused */ string $type): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
        $this->checkType($value, $this->type);
90
        $items = $this->items;
91
        $items[$key] = $value;
92
93
        return new self($items, $this->type);
94
    }
95
96
    /**
97
     * @return bool Whether the array object's current item has a successor.
98
     */
99
    public function hasNextItem(): bool
100
    {
101
        return $this->currentItemIndex + 1 < count($this->items);
102
    }
103
104
    /**
105
     * @param string $key The key of the item.
106
     * @todo Remove type parameter.
107
     */
108
    public function get($key, string $type = null)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

108
    public function get($key, /** @scrutinizer ignore-unused */ string $type = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
    {
110
        $item = $this->items[$key];
111
        $this->checkType($item, $this->type);
112
113
        return $item;
114
    }
115
116
    /**
117
     * @return $mixed The current item.
0 ignored issues
show
Documentation Bug introduced by
The doc comment $mixed at position 0 could not be parsed: Unknown type name '$mixed' at position 0 in $mixed.
Loading history...
118
     */
119
    public function getCurrentItem(string $class)
120
    {
121
        $currentItem = $this->items[$this->currentItemIndex];
122
        $this->checkType($currentItem, $class);
123
124
        return $currentItem;
125
    }
126
127
    /**
128
     * @todo Mutable object!
129
     */
130
    public function setToNextItem(): void
131
    {
132
        $this->currentItemIndex++;
133
    }
134
135
    /**
136
     * @return int The number of items the object holds.
137
     */
138
    public function getSize(): int
139
    {
140
        return count($this->items);
141
    }
142
143
    /**
144
     * @return array An array representation of the object.
145
     */
146
    public function toArray(string $type): array
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

146
    public function toArray(/** @scrutinizer ignore-unused */ string $type): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
147
    {
148
        foreach ($this->items as $item) {
149
            $this->checkType($item, $this->type);
150
        }
151
152
        return $this->items;
153
    }
154
155
    public function serialize(): string
156
    {
157
        return serialize([
158
            $this->currentItemIndex,
159
            $this->items,
160
            $this->type,
161
        ]);
162
    }
163
164
    public function unserialize($serialized): void
165
    {
166
        list(
167
            $this->currentItemIndex,
168
            $this->items,
169
            $this->type) = unserialize($serialized);
170
    }
171
}
172