Skip to content

fix: ResourceClassInfoTrait::isResourceClass() is always true#7924

Merged
soyuka merged 1 commit intoapi-platform:4.3from
Maxcastel:fix-isResourceClass-always-true
Apr 27, 2026
Merged

fix: ResourceClassInfoTrait::isResourceClass() is always true#7924
soyuka merged 1 commit intoapi-platform:4.3from
Maxcastel:fix-isResourceClass-always-true

Conversation

@Maxcastel
Copy link
Copy Markdown
Contributor

@Maxcastel Maxcastel commented Apr 21, 2026

Q A
Branch? 4.3
Tickets Closes #..., closes #...
License MIT

Problem

final class ParameterResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
{
    use ResourceClassInfoTrait;

    public function __construct(
        private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
        private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory,
        private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null,
        private readonly ?ContainerInterface $filterLocator = null,
        private readonly ?NameConverterInterface $nameConverter = null,
        private readonly ?LoggerInterface $logger = null,
        ?ResourceClassResolverInterface $resourceClassResolver = null,
    ) {
        $this->resourceClassResolver = $resourceClassResolver;
    }

}

$this->resourceClassResolver and $this->resourceMetadataFactory are always null, so the fallback always returns true, even if the class is not an API resource (does not have #[ApiResource]):

private function isResourceClass(string $class): bool
{
    // dump($this->resourceClassResolver); //null
    // dd($this->resourceMetadataFactory); //null
    if ($this->resourceClassResolver instanceof ResourceClassResolverInterface) {
        return $this->resourceClassResolver->isResourceClass($class);
    }

    if ($this->resourceMetadataFactory) {
        return \count($this->resourceMetadataFactory->create($class)) > 0;
    }

    return true;
}

Solution

  • ResourceClassInfoTrait::isResourceClass(): changed the fallback to false so that the conditions remain the source of truth
  • Added tests for ResourceClassInfoTrait (there were tests for ClassInfoTrait, but none for ResourceClassInfoTrait)

@Maxcastel Maxcastel changed the title test fix: ResourceClassInfoTrait::isResourceClass() is always true Apr 21, 2026
@Maxcastel Maxcastel marked this pull request as draft April 21, 2026 12:24
@Maxcastel Maxcastel force-pushed the fix-isResourceClass-always-true branch 3 times, most recently from 11bc68b to 454397b Compare April 23, 2026 07:52
@Maxcastel Maxcastel force-pushed the fix-isResourceClass-always-true branch from eb60335 to 2b67bac Compare April 23, 2026 12:13
@Maxcastel Maxcastel marked this pull request as ready for review April 23, 2026 12:13
@soyuka soyuka merged commit d08eb7f into api-platform:4.3 Apr 27, 2026
148 of 151 checks passed
@soyuka
Copy link
Copy Markdown
Member

soyuka commented Apr 27, 2026

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