Skip to content

chore: more phpstan fixes#7265

Merged
soyuka merged 3 commits into
api-platform:mainfrom
VincentLanglet:morePhpstanFixes
Jul 1, 2025
Merged

chore: more phpstan fixes#7265
soyuka merged 3 commits into
api-platform:mainfrom
VincentLanglet:morePhpstanFixes

Conversation

@VincentLanglet

Copy link
Copy Markdown
Contributor
Q A
Branch? main
Tickets Closes #..., closes #...
License MIT
Doc PR api-platform/docs#...

Comment thread phpstan.neon.dist
- tests/Fixtures/TestBundle/Entity/
- src/OpenApi/Factory/OpenApiFactory.php
-
message: '#is never assigned .* so it can be removed from the property type.#'

Copy link
Copy Markdown
Contributor Author

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.

) {
$this->types = \is_string($types) ? (array) $types : $types;
$this->serialize = \is_array($serialize) ? $serialize : [$serialize];
$this->serialize = (null === $serialize || \is_array($serialize)) ? $serialize : [$serialize];

Copy link
Copy Markdown
Contributor Author

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]

* @param array<string, mixed> $context
*
* @throws RuntimeException
* @throws InvalidArgumentException

Copy link
Copy Markdown
Contributor Author

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

* @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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for catch.neverThrown

/**
* @author Kévin Dunglas <kevin@dunglas.dev>
*
* @phpstan-ignore trait.unused

Copy link
Copy Markdown
Contributor Author

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

{
$actual = (array) $this->getValueOfNode($node);

if (!\is_array($actual)) {

Copy link
Copy Markdown
Contributor Author

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

return false;
}

if (!\in_array($subject, array_keys(self::RBAC), true) || !\is_array(self::RBAC[$subject])) {

Copy link
Copy Markdown
Contributor Author

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

@VincentLanglet VincentLanglet marked this pull request as ready for review June 30, 2025 18:13
}

return $aliasMap;
return array_combine($rootAliases, $rootEntities);

Copy link
Copy Markdown
Contributor Author

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


$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());

Copy link
Copy Markdown
Contributor Author

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

{
/** @var HttpClientInterface $client */
$client = new class implements ClientInterface {
$client = new class implements HttpClientInterface {

Copy link
Copy Markdown
Contributor Author

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

@soyuka soyuka merged commit 82ab5ef into api-platform:main Jul 1, 2025
111 of 114 checks passed
@soyuka

soyuka commented Jul 1, 2025

Copy link
Copy Markdown
Member

awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants