getByConfigAndSubjectClass()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
ccs 0
cts 19
cp 0
rs 9.4555
c 0
b 0
f 0
cc 5
nc 4
nop 3
crap 30
1
<?php
2
3
namespace LSB\NumberingBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use LSB\NumberingBundle\Entity\NumberingCounterData;
7
8
/**
9
 * Class NumberingCounterDataRepository
10
 * @package LSB\NumberingBundle\Repository
11
 */
12
class NumberingCounterDataRepository extends EntityRepository
13
{
14
15
    /**
16
     * @param array $config
17
     * @param string $subjectClass
18
     * @param string|null $contextObjectValue
19
     * @return NumberingCounterData|null
20
     * @throws \Doctrine\ORM\NonUniqueResultException
21
     */
22
    public function getByConfigAndSubjectClass(array $config, string $subjectClass, string $contextObjectValue = null): ?NumberingCounterData
23
    {
24
        $qb = $this->createQueryBuilder('ncd')
25
            ->where('ncd.subjectFQCN = :subjectClass')
26
            ->andWhere('ncd.configName = :configName')
27
            ->setParameters([':subjectClass' => $subjectClass, ':configName' => $config['name']]);
28
29
        if (isset($config['time_context']) && !empty($config['time_context'])) {
30
            $qb
31
                ->andWhere('ncd.timeContext = :timeContext')
32
                ->setParameter(':timeContext', $config['time_context']);
33
        }
34
35
        if (isset($config['context_object_fqcn']) && !empty($config['context_object_fqcn'])) {
36
            $qb
37
                ->andWhere('ncd.contextObjectFQCN = :contextObjectFQCN')
38
                ->andWhere('ncd.contextObjectValue = :contextObjectValue')
39
                ->setParameter(':contextObjectFQCN', $config['context_object_fqcn'])
40
                ->setParameter(':contextObjectValue', $contextObjectValue);
41
        }
42
43
44
        return $qb->getQuery()->getOneOrNullResult();
45
    }
46
47
48
}
49