Test Failed
Push — develop ( 92c10d...ff12cf )
by Daniel
05:05
created

ComponentLocationRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findByDynamicPage() 0 20 4
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Repository\Component;
6
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Silverback\ApiComponentBundle\Entity\Component\ComponentLocation;
11
use Symfony\Bridge\Doctrine\RegistryInterface;
12
13
/**
14
 * @method ComponentLocation|null find($id, $lockMode = null, $lockVersion = null)
15
 * @method ComponentLocation|null findOneBy(array $criteria, array $orderBy = null)
16
 * @method ComponentLocation[]    findAll()
17
 * @method ComponentLocation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
18
 */
19
class ComponentLocationRepository extends ServiceEntityRepository
20
{
21
    public function __construct(RegistryInterface $registry)
22
    {
23
        parent::__construct($registry, ComponentLocation::class);
24
    }
25
26
    public function findByDynamicPage(string $dynamicPageClass): Collection
27
    {
28
        $qb = $this->createQueryBuilder('location');
29
        $qb
30
            ->andWhere(
31
                $qb->expr()->eq('location.dynamicPageClass', ':cls')
32
            )
33
            ->setParameter('cls', $dynamicPageClass)
34
            ->addOrderBy('location.sort', 'ASC');
35
36
        $result = new ArrayCollection($qb->getQuery()->getResult());
37
38
        $uow = $this->getEntityManager()->getUnitOfWork();
39
        $scheduledInsertions = $uow->getScheduledEntityInsertions();
40
        foreach ($scheduledInsertions as $scheduledInsertion) {
41
            if ($scheduledInsertion instanceof ComponentLocation && $scheduledInsertion->getDynamicPageClass() === $dynamicPageClass) {
0 ignored issues
show
Bug introduced by
The method getDynamicPageClass() does not exist on Silverback\ApiComponentB...onent\ComponentLocation. ( Ignorable by Annotation )

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

41
            if ($scheduledInsertion instanceof ComponentLocation && $scheduledInsertion->/** @scrutinizer ignore-call */ getDynamicPageClass() === $dynamicPageClass) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
                $result->add($scheduledInsertion);
43
            }
44
        }
45
        return $result;
46
    }
47
}
48