Test Failed
Push — master ( 09495e...5db298 )
by Daniel
04:30
created

AbstractPageDataRepository::findByComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 22
nc 1
nop 1
dl 0
loc 31
ccs 0
cts 22
cp 0
crap 2
rs 9.568
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Repository\Core;
15
16
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
17
use Doctrine\ORM\Query\Expr\Join;
18
use Doctrine\Persistence\ManagerRegistry;
19
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
20
use Silverback\ApiComponentsBundle\Entity\Core\AbstractPageData;
21
22
/**
23
 * @author Daniel West <[email protected]>
24
 *
25
 * @method AbstractPageData|null find($id, $lockMode = null, $lockVersion = null)
26
 * @method AbstractPageData|null findOneBy(array $criteria, array $orderBy = null)
27
 * @method AbstractPageData[]    findAll()
28
 * @method AbstractPageData[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
29
 */
30
class AbstractPageDataRepository extends ServiceEntityRepository
31
{
32
    public function __construct(ManagerRegistry $registry)
33
    {
34
        parent::__construct($registry, AbstractPageData::class);
35
    }
36
37
    /**
38
     * @return AbstractPageData[]
39
     */
40
    public function findByNestedComponent(AbstractComponent $component): array
41
    {
42
        $queryBuilder = $this->createQueryBuilder('pageData');
43
        $queryBuilder
44
            ->leftJoin(
45
                'pageData.page',
46
                'pageData_page',
47
                Join::WITH,
48
                $queryBuilder->expr()->eq('pageData_page', 'pageData.page')
49
            )
50
            ->leftJoin(
51
                'pageData_page.componentCollections',
52
                'page_data_cc'
53
            )
54
            ->leftJoin(
55
                'page_data_cc.componentPositions',
56
                'page_data_pos'
57
            )
58
            ->leftJoin(
59
                'page_data_pos.component',
60
                'page_data_component',
61
                Join::WITH,
62
                $queryBuilder->expr()->eq('page_data_pos.component', 'page_data_component')
63
            )
64
            ->andWhere(
65
                $queryBuilder->expr()->eq('page_data_component', ':component')
66
            )
67
            ->setParameter('component', $component);
68
69
        return $queryBuilder->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queryBuilder->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
}
72