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

ComponentPositionRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 25
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findByComponent() 0 4 1
A findByPageDataProperties() 0 11 2
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