for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Silverback\ApiComponentBundle\EventSubscriber\EntitySubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\AbstractDynamicPage;
use Silverback\ApiComponentBundle\Entity\SortableInterface;
use Silverback\ApiComponentBundle\Repository\ContentRepository;
class SortableInterfaceSubscriber implements EntitySubscriberInterface
{
private $contentRepository;
public function __construct(
ContentRepository $contentRepository
)
$this->contentRepository = $contentRepository;
}
/**
* @return array
*/
public function getSubscribedEvents(): array
return [
Events::prePersist
];
public function supportsEntity($entity = null): bool
return $entity instanceof SortableInterface;
* @param LifecycleEventArgs $eventArgs
* @param SortableInterface $entity
public function prePersist(LifecycleEventArgs $eventArgs, SortableInterface $entity): void
$eventArgs
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function prePersist(/** @scrutinizer ignore-unused */ LifecycleEventArgs $eventArgs, SortableInterface $entity): void
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
if ($entity->getSort() === null) {
$collection = $entity->getSortCollection();
if ($collection === null && $entity instanceof AbstractDynamicPage) {
$collection = $this->contentRepository->findPageByType(get_class($entity));
$entity->setSort($entity->calculateSort(true, $collection));
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.