Test Failed
Push — develop ( d382d0...28e0cd )
by Daniel
10:59
created

SortableInterfaceSubscriber::supportsEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\EventSubscriber\EntitySubscriber;
6
7
use Doctrine\ORM\Event\LifecycleEventArgs;
8
use Doctrine\ORM\Events;
9
use Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\AbstractDynamicPage;
10
use Silverback\ApiComponentBundle\Entity\SortableInterface;
11
use Silverback\ApiComponentBundle\Repository\ContentRepository;
12
13
class SortableInterfaceSubscriber implements EntitySubscriberInterface
14
{
15
    private $contentRepository;
16
17
    public function __construct(
18
        ContentRepository $contentRepository
19
    )
20
    {
21
        $this->contentRepository = $contentRepository;
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public function getSubscribedEvents(): array
28
    {
29
        return [
30
            Events::prePersist
31
        ];
32
    }
33
34
    public function supportsEntity($entity = null): bool
35
    {
36
        return $entity instanceof SortableInterface;
37
    }
38
39
    /**
40
     * @param LifecycleEventArgs $eventArgs
41
     * @param SortableInterface $entity
42
     */
43
    public function prePersist(LifecycleEventArgs $eventArgs, SortableInterface $entity): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventArgs is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    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.

Loading history...
44
    {
45
        if ($entity->getSort() === null) {
46
            $collection = $entity->getSortCollection();
47
            if ($collection === null && $entity instanceof AbstractDynamicPage) {
48
                $collection = $this->contentRepository->findPageByType(get_class($entity));
49
            }
50
            $entity->setSort($entity->calculateSort(true, $collection));
51
        }
52
    }
53
}
54