Skip to content

Commit 656e6e2

Browse files
committed
add separate Type method
1 parent 66a11e4 commit 656e6e2

17 files changed

+114
-38
lines changed

Diff for: src/Type/Accessory/AccessoryArrayListType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ public function unsetOffset(Type $offsetType): Type
172172
return new ErrorType();
173173
}
174174

175-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
175+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
176+
{
177+
return $this->getKeysArray();
178+
}
179+
180+
public function getKeysArray(): Type
176181
{
177182
return $this;
178183
}

Diff for: src/Type/Accessory/HasOffsetType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,14 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
343343
return new BooleanType();
344344
}
345345

346-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
346+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
347347
{
348-
return new NonEmptyArrayType();
348+
return $this->getKeysArray();
349+
}
350+
351+
public function getKeysArray(): Type
352+
{
353+
return $this->getKeysArray();
349354
}
350355

351356
public function getValuesArray(): Type

Diff for: src/Type/Accessory/HasOffsetValueType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ public function unsetOffset(Type $offsetType): Type
195195
return $this;
196196
}
197197

198-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
198+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
199+
{
200+
return $this->getKeysArray();
201+
}
202+
203+
public function getKeysArray(): Type
199204
{
200205
return new NonEmptyArrayType();
201206
}

Diff for: src/Type/Accessory/NonEmptyArrayType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ public function unsetOffset(Type $offsetType): Type
159159
return new ErrorType();
160160
}
161161

162-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
162+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
163+
{
164+
return $this->getKeysArray();
165+
}
166+
167+
public function getKeysArray(): Type
163168
{
164169
return $this;
165170
}

Diff for: src/Type/Accessory/OversizedArrayType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ public function unsetOffset(Type $offsetType): Type
154154
return new ErrorType();
155155
}
156156

157-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
157+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
158+
{
159+
return $this->getKeysArray();
160+
}
161+
162+
public function getKeysArray(): Type
158163
{
159164
return $this;
160165
}

Diff for: src/Type/ArrayType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ public function generalizeValues(): self
170170
return new self($this->keyType, $this->itemType->generalize(GeneralizePrecision::lessSpecific()));
171171
}
172172

173-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
173+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
174+
{
175+
return $this->getKeysArray();
176+
}
177+
178+
public function getKeysArray(): Type
174179
{
175180
return TypeCombinator::intersect(new self(new IntegerType(), $this->getIterableKeyType()), new AccessoryArrayListType());
176181
}

Diff for: src/Type/Constant/ConstantArrayType.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -1250,21 +1250,22 @@ public function generalizeValues(): self
12501250
return new self($this->keyTypes, $valueTypes, $this->nextAutoIndexes, $this->optionalKeys, $this->isList);
12511251
}
12521252

1253-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
1253+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
12541254
{
12551255
$keysArray = $this->getKeysOrValuesArray($this->keyTypes);
12561256

1257-
if ($filterValueType !== null) {
1258-
return TypeCombinator::intersect(
1259-
new ArrayType(
1260-
$keysArray->getIterableKeyType()->generalize(GeneralizePrecision::lessSpecific()),
1261-
$keysArray->getIterableValueType()->generalize(GeneralizePrecision::lessSpecific()),
1262-
),
1263-
new AccessoryArrayListType(),
1264-
);
1265-
}
1257+
return TypeCombinator::intersect(
1258+
new ArrayType(
1259+
$keysArray->getIterableKeyType()->generalize(GeneralizePrecision::lessSpecific()),
1260+
$keysArray->getIterableValueType()->generalize(GeneralizePrecision::lessSpecific()),
1261+
),
1262+
new AccessoryArrayListType(),
1263+
);
1264+
}
12661265

1267-
return $keysArray;
1266+
public function getKeysArray(): self
1267+
{
1268+
return $this->getKeysOrValuesArray($this->keyTypes);
12681269
}
12691270

12701271
public function getValuesArray(): self

Diff for: src/Type/IntersectionType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,14 @@ public function unsetOffset(Type $offsetType): Type
799799
return $this->intersectTypes(static fn (Type $type): Type => $type->unsetOffset($offsetType));
800800
}
801801

802-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
802+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
803803
{
804-
return $this->intersectTypes(static fn (Type $type): Type => $type->getKeysArray($filterValueType, $strict));
804+
return $this->intersectTypes(static fn (Type $type): Type => $type->getKeysArrayFiltered($filterValueType, $strict));
805+
}
806+
807+
public function getKeysArray(): Type
808+
{
809+
return $this->intersectTypes(static fn (Type $type): Type => $type->getKeysArray());
805810
}
806811

807812
public function getValuesArray(): Type

Diff for: src/Type/MixedType.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ public function unsetOffset(Type $offsetType): Type
179179
return $this;
180180
}
181181

182-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
182+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
183+
{
184+
return $this->getKeysArray();
185+
}
186+
187+
public function getKeysArray(): Type
183188
{
184189
if ($this->isArray()->no()) {
185190
return new ErrorType();

Diff for: src/Type/NeverType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,14 @@ public function unsetOffset(Type $offsetType): Type
273273
return new NeverType();
274274
}
275275

276-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
276+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
277277
{
278-
return new NeverType();
278+
return $this->getKeysArray();
279+
}
280+
281+
public function getKeysArray(): Type
282+
{
283+
return $this->getKeysArray();
279284
}
280285

281286
public function getValuesArray(): Type

Diff for: src/Type/Php/ArrayKeysFunctionDynamicReturnTypeExtension.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3636
return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType();
3737
}
3838

39-
$strict = false;
40-
$filterType = null;
4139
if (count($functionCall->getArgs()) >= 2) {
4240
$filterType = $scope->getType($functionCall->getArgs()[1]->value);
41+
42+
$strict = false;
43+
if (count($functionCall->getArgs()) >= 3) {
44+
$strict = $scope->getType($functionCall->getArgs()[2]->value)->isTrue()->yes();
45+
}
46+
47+
return $arrayType->getKeysArrayFiltered($filterType, $strict);
4348
}
44-
if (count($functionCall->getArgs()) >= 3) {
45-
$strict = $scope->getType($functionCall->getArgs()[2]->value)->isTrue()->yes();
46-
}
47-
return $arrayType->getKeysArray($filterType, $strict);
49+
50+
return $arrayType->getKeysArray();
4851
}
4952

5053
}

Diff for: src/Type/StaticType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,14 @@ public function unsetOffset(Type $offsetType): Type
396396
return $this->getStaticObjectType()->unsetOffset($offsetType);
397397
}
398398

399-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
399+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
400400
{
401-
return $this->getStaticObjectType()->getKeysArray($filterValueType, $strict);
401+
return $this->getStaticObjectType()->getKeysArrayFiltered($filterValueType, $strict);
402+
}
403+
404+
public function getKeysArray(): Type
405+
{
406+
return $this->getStaticObjectType()->getKeysArray();
402407
}
403408

404409
public function getValuesArray(): Type

Diff for: src/Type/Traits/LateResolvableTypeTrait.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,14 @@ public function unsetOffset(Type $offsetType): Type
248248
return $this->resolve()->unsetOffset($offsetType);
249249
}
250250

251-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
251+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
252252
{
253-
return $this->resolve()->getKeysArray($filterValueType, $strict);
253+
return $this->resolve()->getKeysArrayFiltered($filterValueType, $strict);
254+
}
255+
256+
public function getKeysArray(): Type
257+
{
258+
return $this->resolve()->getKeysArray();
254259
}
255260

256261
public function getValuesArray(): Type

Diff for: src/Type/Traits/MaybeArrayTypeTrait.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public function isList(): TrinaryLogic
3939
return TrinaryLogic::createMaybe();
4040
}
4141

42-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
42+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
43+
{
44+
return $this->getKeysArray();
45+
}
46+
47+
public function getKeysArray(): Type
4348
{
4449
return new ErrorType();
4550
}

Diff for: src/Type/Traits/NonArrayTypeTrait.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public function isList(): TrinaryLogic
3939
return TrinaryLogic::createNo();
4040
}
4141

42-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
42+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
43+
{
44+
return $this->getKeysArray();
45+
}
46+
47+
public function getKeysArray(): Type
4348
{
4449
return new ErrorType();
4550
}

Diff for: src/Type/Type.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ public function setExistingOffsetValueType(Type $offsetType, Type $valueType): T
134134

135135
public function unsetOffset(Type $offsetType): Type;
136136

137-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type;
137+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type;
138+
139+
public function getKeysArray(): Type;
138140

139141
public function getValuesArray(): Type;
140142

Diff for: src/Type/UnionType.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,14 @@ public function unsetOffset(Type $offsetType): Type
730730
return $this->unionTypes(static fn (Type $type): Type => $type->unsetOffset($offsetType));
731731
}
732732

733-
public function getKeysArray(?Type $filterValueType = null, bool $strict = false): Type
733+
public function getKeysArrayFiltered(Type $filterValueType, bool $strict): Type
734734
{
735-
return $this->unionTypes(static fn (Type $type): Type => $type->getKeysArray($filterValueType, $strict));
735+
return $this->unionTypes(static fn (Type $type): Type => $type->getKeysArrayFiltered($filterValueType, $strict));
736+
}
737+
738+
public function getKeysArray(): Type
739+
{
740+
return $this->unionTypes(static fn (Type $type): Type => $type->getKeysArray());
736741
}
737742

738743
public function getValuesArray(): Type

0 commit comments

Comments
 (0)