Skip to content

Add generic return type to AbstractCrudController::getContext() - #7772

Open
ERuban wants to merge 1 commit into
EasyCorp:5.xfrom
ERuban:add_generic_return_to_getcontext
Open

Add generic return type to AbstractCrudController::getContext()#7772
ERuban wants to merge 1 commit into
EasyCorp:5.xfrom
ERuban:add_generic_return_to_getcontext

Conversation

@ERuban

@ERuban ERuban commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

EasyAdmin 5 made the CRUD stack generic: AbstractCrudController declares @template TEntity of object, all action methods are annotated with @param AdminContext<TEntity> $context, and the chain continues through AdminContextInterface<TEntity>::getEntity(): EntityDto<TEntity> down to EntityDto::getInstance(): TEntity|null.

One link is missing: getContext() has no @return annotation, so the generic type is lost right at the start of the chain:

/** @extends AbstractCrudController<Product> */
final class ProductCrudController extends AbstractCrudController
{
    public function someAction(): void
    {
        $product = $this->getContext()?->getEntity()->getInstance();
        // PHPStan infers object|null, expected Product|null
    }
}

This forces consumers to keep manual /** @var Product|null */ annotations, although the point of the 5.0 generics (see the "Static Analysis" section in UPGRADE.md) is to remove them.

This PR adds the missing @return AdminContext|null annotation, matching the existing @param AdminContext annotations of the action methods. With it, PHPStan infers Product|null in the example above.

Docblock-only change, no runtime impact.

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.

1 participant