Skip to content

Commit

Permalink
Fixes null object call on generate:entities
Browse files Browse the repository at this point in the history
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities

This seems to be related to the following issue filed on the doctrine github:

doctrine/orm#4459

and the following pull request:

doctrine/orm#1345

The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed:

From:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if ($metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

To:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
  • Loading branch information
manticorp authored Sep 7, 2016
1 parent d6e2c9f commit 89a31d5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mappings/Subscribers/MappedEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function isInstantiable(ClassMetadata $metadata)
return false;
}

if ($metadata->getReflectionClass()->isAbstract()) {
if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
return false;
}

Expand Down

0 comments on commit 89a31d5

Please sign in to comment.