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
Some Phpstan fix for level 6 #7176
Some Phpstan fix for level 6 #7176
Conversation
1dcc08e
to
c984fc8
Compare
c984fc8
to
6c47cb3
Compare
if (null === $value) { | ||
return null; | ||
} |
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 transform
method were supporting null
(and returning null
in this case).
So if the transform support FilterData|null => array<string, mixed>|null
,
I assume the reverseTransport should support array<string, mixed>|null => FilterData|null
.
@@ -90,7 +90,7 @@ public function __construct( | |||
*/ | |||
public function reverseTransform($value) | |||
{ | |||
if (empty($value)) { | |||
if (null === $value || [] === $value || '' === $value) { |
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.
This avoid issue with 0
or '0'
, and I don't see any reason to support false
.
@@ -99,6 +99,10 @@ public function reverseTransform($value) | |||
} | |||
|
|||
if (!$this->multiple) { | |||
if (\is_array($value)) { |
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.
find
only support string|int
.
* | ||
* @phpstan-return T|null | ||
*/ | ||
public function reverseTransform($value): ?object | ||
{ | ||
if (empty($value) && !\in_array($value, ['0', 0], true)) { | ||
if (null === $value || '' === $value) { |
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.
find
only supports string|int
so I don't see reason to support []
or false
.
@@ -53,11 +53,11 @@ public function __construct(ModelManagerInterface $modelManager, string $class) | |||
} | |||
|
|||
/** | |||
* @param object[]|null $value | |||
* @param \Traversable<object>|null $value |
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.
reverseTransform
returns a Collection
.
@@ -93,7 +95,6 @@ public function reverseTransform($value) | |||
if ([] === $value) { | |||
$result = $value; | |||
} else { | |||
$value = array_map('strval', $value); |
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.
I don't think this is useful. addIdentifiersToQuery
supports both int
and string
.
And we shouldn't support any other value since transform
return a string[]
.
@@ -150,7 +150,7 @@ public function executeQuery(object $query); | |||
public function getExportFields(string $class): array; | |||
|
|||
/** | |||
* @param array<int, int|string> $idx | |||
* @param array<int|string> $idx |
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.
I don't see reason to restrict the keys.
dbfe55b
to
8ffca37
Compare
continue; | ||
} | ||
|
||
$value[$key] = (string) $id; |
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.
addIdentifiersToQuery supports both int
and string
so it's not needed to cast it.
Please take a look @sonata-project/contributors |
Friendly ping @sonata-project/contributors |
tests/DependencyInjection/Compiler/ObjectAclManipulatorCompilerPassTest.php
Outdated
Show resolved
Hide resolved
@@ -30,8 +37,10 @@ public function reverseTransform($value): FilterData | |||
|
|||
/** | |||
* @param FilterData|null $value | |||
* | |||
* @return array<string, mixed>|null |
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.
* @return array<string, mixed>|null | |
* @return array<string, mixed>|null | |
* @phpstan-return array{type: int|null, value?: mixed}|null |
@@ -68,6 +70,9 @@ public function testReverseTransform(?array $value): void | |||
} | |||
} | |||
|
|||
/** | |||
* @return iterable<array{array<int|string>|null}> |
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.
* @return iterable<array{array<int|string>|null}> | |
* @phpstan-return iterable<array{array<int|string>|null}> |
No description provided.