src/Service/EntityEraser/DependencyResultCollection.php
private function addTraversable(\Traversable $result)
    {
        /*
         * Since we only know, that $result is an instance of \Traversable
         * (and thus, usable in a foreach), we cannot relay on methods like first()
         * which are defined in the \Iterable interface.
         * We must use a foreach to get the first item.
         *
         * Because PHP does not unset the loop variable, this works.
         */
        foreach ($result as $item) {
            break;
        }

        /* @var null|object|mixed $item */
        if (!$item instanceof EntityInterface) {
            throw new \InvalidArgumentException('Traversable objects must be a non-empty collection of Entity instances.');
        }

        $name = get_class($item);

        return $this->addArray([
            'name' => $name,
            'entities' => $result,
        ]);
    }
private function addTraversable(\Traversable $result)
    {
        /*
         * Since we only know, that $result is an instance of \Traversable
         * (and thus, usable in a foreach), we cannot relay on methods like first()
         * which are defined in the \Iterable interface.
         * We must use a foreach to get the first item.
         *
         * Because PHP does not unset the loop variable, this works.
         */
        foreach ($result as $item) {
            break;
        }

        /* @var null|object|mixed $item */
        if (!$item instanceof EntityInterface) {
            throw new \InvalidArgumentException('Traversable objects must be a non-empty collection of Entity instances.');
        }

        $name = get_class($item);

        return $this->addArray([
            'name' => $name,
            'entities' => $result,
        ]);
    }
private function addTraversable ( \ Traversable $ result ) { /*
         * Since we only know, that $result is an instance of \Traversable
         * (and thus, usable in a foreach), we cannot relay on methods like first()
         * which are defined in the \Iterable interface.
         * We must use a foreach to get the first item.
         *
         * Because PHP does not unset the loop variable, this works.
         */ foreach ( $ result as $ item ) { break ; } /* @var null|object|mixed $item */ if ( ! $ item instanceof EntityInterface ) { throw new \ InvalidArgumentException ( 'Traversable objects must be a non-empty collection of Entity instances.' ) ; } $ name = get_class ( $ item ) ; return $ this -> addArray ( [ 'name' => $ name , 'entities' => $ result , ] ) ; }
Add a \Traversable object.

Sets the name of the result to the class name of the first item in the object collection.
Therefor, the \Traversable object must not be empty.

@param \Traversable $result

@return DependencyResultCollection
@throws \InvalidArgumentException
Add a \ Traversable object .