Skip to content

orm:mapping:describe crashes for entities with entity listeners #12392

Description

@svwezel

Bug Report

Q A
Version 3.6.2

Summary

\Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand::formatEntityListeners crashes with get_class(): Argument #1 ($object) must be of type object, array given when the described entity has entity listeners registered.

Current behavior

Run orm:mapping:describe <YourEntity> when the entity has entity listeners and get the crash described above.

Expected behavior

Run orm:mapping:describe <YourEntity> when the entity has entity listeners and get a nicely formatted output including the entity listeners.

How to reproduce

  • Create a new Symfony project, added doctrine-bundle/orm, added an entity and an entity listener.
  • Run bin/console doctrine:mapping:describe

Suggested fix

    /**
     * Format the entity listeners
     *
     * @phpstan-param array<string, list<array{class: class-string, method: string}>> $entityListeners
     *
     * @return string[]
     * @phpstan-return array{0: string, 1: string}
     */
    private function formatEntityListeners(array $entityListeners): array
    {
        $listeners = [];

        foreach ($entityListeners as $eventName => $eventListeners) {
            foreach ($eventListeners as $listener) {
                $listeners[] = sprintf('%s: %s::%s', $eventName, $listener['class'], $listener['method']);
            }
        }

        return $this->formatField('Entity listeners', $listeners);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions