Passed
Push — main ( 341aa7...1aa4cc )
by Daniel
13:35
created

findByPageDataProperties()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
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\Persistence\ManagerRegistry;
18
use Silverback\ApiComponentsBundle\Entity\Core\ComponentInterface;
19
use Silverback\ApiComponentsBundle\Entity\Core\ComponentPosition;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 *
24
 * @method ComponentPosition|null find($id, $lockMode = null, $lockVersion = null)
25
 * @method ComponentPosition|null findOneBy(array $criteria, array $orderBy = null)
26
 * @method ComponentPosition[]    findAll()
27
 * @method ComponentPosition[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
28
 */
29
class ComponentPositionRepository extends ServiceEntityRepository
30
{
31
    public function __construct(ManagerRegistry $registry)
32
    {
33
        parent::__construct($registry, ComponentPosition::class);
34
    }
35
36
    public function findByComponent(ComponentInterface $component): array
37
    {
38
        return $this->findBy([
39
            'component' => $component,
40
        ]);
41
    }
42
43
    public function findByPageDataProperties(array $properties): array
44
    {
45
        $qb = $this->createQueryBuilder('pd');
46
        $expr = $qb->expr();
47
        foreach ($properties as $index => $property) {
48
            $key = sprintf(':positionName%d', $index);
49
            $qb->orWhere($expr->eq('pd.pageDataProperty', $key));
50
            $qb->setParameter($key, $property);
51
        }
52
53
        return $qb->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $qb->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...
54
    }
55
}
56