-
-
Notifications
You must be signed in to change notification settings - Fork 927
chore: more phpstan fixes #7265
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
Conversation
VincentLanglet
commented
Jun 30, 2025
Q | A |
---|---|
Branch? | main |
Tickets | Closes #..., closes #... |
License | MIT |
Doc PR | api-platform/docs#... |
@@ -54,6 +54,18 @@ parameters: | |||
- tests/Fixtures/TestBundle/Document/ | |||
- tests/Fixtures/TestBundle/Entity/ | |||
- src/OpenApi/Factory/OpenApiFactory.php | |||
- | |||
message: '#is never assigned .* so it can be removed from the property type.#' |
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.
false positive because private ?int $id
is not set with a setter but with doctrine magic.
@@ -230,7 +230,7 @@ public function __construct( | |||
private array $extraProperties = [], | |||
) { | |||
$this->types = \is_string($types) ? (array) $types : $types; | |||
$this->serialize = \is_array($serialize) ? $serialize : [$serialize]; | |||
$this->serialize = (null === $serialize || \is_array($serialize)) ? $serialize : [$serialize]; |
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.
Before, null
was transformed into [null]
@@ -28,6 +29,7 @@ interface IdentifiersExtractorInterface | |||
* @param array<string, mixed> $context | |||
* | |||
* @throws RuntimeException | |||
* @throws InvalidArgumentException |
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.
Catch somewhere, so we need to update the phpdoc to avoid a catch.neverThrown
error
@@ -40,6 +41,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation | |||
* @param object|class-string $resource | |||
* @param array<string, mixed>|array{force_resource_class?: string|class-string, item_uri_template?: string, uri_variables?: array<string, string>} $context | |||
* | |||
* @throws OperationNotFoundException |
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.
same for catch.neverThrown
@@ -15,6 +15,8 @@ | |||
|
|||
/** | |||
* @author Kévin Dunglas <kevin@dunglas.dev> | |||
* | |||
* @phpstan-ignore trait.unused |
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.
Never used in api platform code base
@@ -121,10 +121,6 @@ public function theJsonNodeShouldBeSorted(string $node = ''): void | |||
{ | |||
$actual = (array) $this->getValueOfNode($node); | |||
|
|||
if (!\is_array($actual)) { |
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.
$actual is caster line 122
@@ -45,7 +45,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter | |||
return false; | |||
} | |||
|
|||
if (!\in_array($subject, array_keys(self::RBAC), true) || !\is_array(self::RBAC[$subject])) { |
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 second condition was always true
c538257
to
72a1020
Compare
ebba787
to
5228a77
Compare
} | ||
|
||
return $aliasMap; | ||
return array_combine($rootAliases, $rootEntities); |
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.
array_combine never return false since php 8 and you require 8.2
@@ -496,18 +483,17 @@ public function testGetNodeInterface(): void | |||
$this->assertNull($nodeInterface->resolveType([], [], $this->prophesize(ResolveInfo::class)->reveal())); | |||
|
|||
$this->typesContainerProphecy->has('Dummy')->shouldBeCalled()->willReturn(false); | |||
$this->assertNull($nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal())); | |||
$resolvedType = $nodeInterface->resolveType([ItemNormalizer::ITEM_RESOURCE_CLASS_KEY => Dummy::class], [], $this->prophesize(ResolveInfo::class)->reveal()); |
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.
setting a variable avoid a phpstan bug
@@ -59,35 +57,24 @@ private function generateXResourcesTags(int $number, int $minimum = 0): array | |||
|
|||
public function testMultiChunkedTags(): void | |||
{ | |||
/** @var HttpClientInterface $client */ | |||
$client = new class implements ClientInterface { | |||
$client = new class implements HttpClientInterface { |
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 used a real HttpClientInterface instead of the Guzzle one
awesome thanks! |