-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utilize PHPStan Type interface in TypeNormalizer #6478
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,11 @@ public function __construct( | |
*/ | ||
public function normalizeArrayOfUnionToUnionArray(Type $type, int $arrayNesting = 1): Type | ||
{ | ||
if (! $type instanceof ArrayType && ! $type instanceof ConstantArrayType) { | ||
if (! $type->isArray()->yes()) { | ||
return $type; | ||
} | ||
|
||
if ($type instanceof ConstantArrayType && $arrayNesting === 1) { | ||
if ($type->isConstantArray()->yes() && $arrayNesting === 1) { | ||
return $type; | ||
} | ||
|
||
|
@@ -52,16 +52,17 @@ public function normalizeArrayOfUnionToUnionArray(Type $type, int $arrayNesting | |
$this->collectedNestedArrayTypes = []; | ||
} | ||
|
||
if ($type->getItemType() instanceof ArrayType) { | ||
$itemType = $type->getIterableValueType(); | ||
if ($itemType instanceof ArrayType) { | ||
++$arrayNesting; | ||
$this->normalizeArrayOfUnionToUnionArray($type->getItemType(), $arrayNesting); | ||
} elseif ($type->getItemType() instanceof UnionType) { | ||
$this->collectNestedArrayTypeFromUnionType($type->getItemType(), $arrayNesting); | ||
$this->normalizeArrayOfUnionToUnionArray($itemType, $arrayNesting); | ||
} elseif ($itemType instanceof UnionType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be due to downgrade error: until we have more fixture tests, I think we can keep using strict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, lets do it less aggressive: #6479 |
||
$this->collectNestedArrayTypeFromUnionType($itemType, $arrayNesting); | ||
} else { | ||
$this->collectedNestedArrayTypes[] = new NestedArrayType( | ||
$type->getItemType(), | ||
$itemType, | ||
$arrayNesting, | ||
$type->getKeyType() | ||
$type->getIterableKeyType() | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the root cause is that we call
getItemType
which is not defined inType
, therefore will crash depending on the used type