1 | <?php |
||
71 | class Collection extends AbstractCollection |
||
72 | { |
||
73 | /** |
||
74 | * Constructs a collection object of the specified type, optionally with the |
||
75 | * specified data. |
||
76 | * |
||
77 | * @param mixed $data |
||
78 | * <p> |
||
79 | * The initial items to store in the |
||
80 | * collection. |
||
81 | * </p> |
||
82 | * @param string $iteratorClass optional <p> |
||
83 | * You can overwrite the |
||
84 | * ArrayyIterator, but mostly you |
||
85 | * don't need this option. |
||
86 | * </p> |
||
87 | * @param bool $checkPropertiesInConstructor optional <p> |
||
88 | * You need to extend the |
||
89 | * "Arrayy"-class and you need to set |
||
90 | * the |
||
91 | * $checkPropertiesMismatchInConstructor |
||
92 | * class property to true, otherwise |
||
93 | * this option didn't not work |
||
94 | * anyway. |
||
95 | * </p> |
||
96 | * @param TypeInterface|null $type |
||
97 | * |
||
98 | * @psalm-param array<array-key,T>|array<TKey,T>|\Arrayy\Arrayy<TKey,T> $data |
||
99 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
100 | */ |
||
101 | 64 | public function __construct( |
|
102 | $data = [], |
||
103 | string $iteratorClass = null, |
||
104 | bool $checkPropertiesInConstructor = null, |
||
105 | TypeInterface $type = null |
||
106 | ) { |
||
107 | // fallback |
||
108 | 64 | if ($iteratorClass === null) { |
|
109 | 50 | $iteratorClass = ArrayyIterator::class; |
|
110 | } |
||
111 | 64 | if ($checkPropertiesInConstructor === null) { |
|
112 | 50 | $checkPropertiesInConstructor = true; |
|
113 | } |
||
114 | |||
115 | 64 | if ($type !== null) { |
|
116 | 9 | $this->properties = $type; |
|
|
|||
117 | } |
||
118 | |||
119 | 64 | parent::__construct( |
|
120 | 64 | $data, |
|
121 | $iteratorClass, |
||
122 | $checkPropertiesInConstructor |
||
123 | ); |
||
124 | 51 | } |
|
125 | |||
126 | /** |
||
127 | * @param string|TypeCheckArray|TypeCheckInterface[] $type |
||
128 | * @param array<mixed> $data |
||
129 | * @param bool $checkPropertiesInConstructorAndType |
||
130 | * |
||
131 | * @return static |
||
132 | * |
||
133 | * @template TKeyConstruct of array-key |
||
134 | * @template TConstruct |
||
135 | * @psalm-param string|class-string|class-string<TConstruct>|TypeInterface|TypeCheckArray<array-key,TypeCheckInterface>|array<TypeCheckInterface> $type |
||
136 | * @psalm-param array<TKeyConstruct,TConstruct> $data |
||
137 | * @psalm-return static<TKeyConstruct,TConstruct> |
||
138 | */ |
||
139 | 6 | public static function construct( |
|
140 | $type, |
||
141 | $data = [], |
||
142 | bool $checkPropertiesInConstructorAndType = true |
||
143 | ): self { |
||
144 | 6 | $type = self::convertIntoTypeCheckArray($type); |
|
145 | |||
146 | 6 | return new static( |
|
147 | 6 | $data, |
|
148 | 6 | ArrayyIterator::class, |
|
149 | $checkPropertiesInConstructorAndType, |
||
150 | $type |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
156 | * |
||
157 | * @return \Iterator |
||
158 | * <p>An iterator for the values in the array.</p> |
||
159 | * |
||
160 | * @psalm-return \Iterator<T> |
||
161 | * |
||
162 | * @noinspection SenselessProxyMethodInspection |
||
163 | */ |
||
164 | public function getIterator(): \Iterator |
||
168 | |||
169 | /** |
||
170 | * The type (FQCN) associated with this collection. |
||
171 | * |
||
172 | * @return string|TypeCheckArray|TypeCheckInterface[] |
||
173 | * |
||
174 | * @psalm-return string|class-string|class-string<T>|TypeInterface|TypeCheckArray<TKey,T>|TypeCheckArray<int|string,mixed>|array<TypeCheckInterface>|array<array-key,TypeCheckInterface> |
||
175 | */ |
||
176 | 8 | public function getType() |
|
180 | |||
181 | /** |
||
182 | * Get a base Collection instance from this Collection. |
||
183 | * |
||
184 | * @return self |
||
185 | * |
||
186 | * @psalm-return self<TKey,T> |
||
187 | * |
||
188 | * @psalm-suppress InvalidReturnStatement - why? |
||
189 | * @psalm-suppress InvalidReturnType - why? |
||
190 | */ |
||
191 | 1 | public function toBase(): self |
|
198 | } |
||
199 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..