schmittjoh / JMSJobQueueBundle

Run and Schedule Symfony Console Commands as Background Jobs
http://jmsyst.com/bundles/JMSJobQueueBundle
335 stars 254 forks source link

assert() with string argument is deprecated in PHP 7.2 #211

Closed l33tleandrew closed 6 years ago

l33tleandrew commented 6 years ago

Hi guys, I'm having a small problem with this bundle because a couple of functions are not PHP 7.2 compatible. These are the two functions involved:

private function getRelatedEntityIdentifier($entity)
    {
        assert('is_object($entity)');

        if ($entity instanceof \Doctrine\Common\Persistence\Proxy) {
            $entity->__load();
        }

        $relClass = ClassUtils::getClass($entity);
        $relId = $this->registry->getManagerForClass($relClass)->getMetadataFactory()
                    ->getMetadataFor($relClass)->getIdentifierValues($entity);
        asort($relId);

        if ( ! $relId) {
            throw new \InvalidArgumentException(sprintf('The identifier for entity of class "%s" was empty.', $relClass));
        }

        return array($relClass, json_encode($relId));
    }
public function addRelatedEntity($entity)
    {
        assert('is_object($entity)');

        if ($this->relatedEntities->contains($entity)) {
            return;
        }

        $this->relatedEntities->add($entity);
    }

As you can see these two functions are not compatible with PHP 7.2 because they contain an assert() function call using a string argument. See here for more informations. If it's possibile I will fix this two functions and create a pull request.

zvenni commented 6 years ago

Ran into same issue on updating to PHP 7.2.1. Suggest to throw an (InvalidArgument) Exception instead.

Thanks a lot!

schmittjoh commented 6 years ago

fixed in the latest version