Passed
Push — master ( 9180f5...852136 )
by Luiz Kim
08:12
created

getParticularsByPeopleAndContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 27
rs 9.9332
1
<?php
2
3
namespace ControleOnline\Repository;
4
5
use ControleOnline\Entity\Particulars\Particulars;
6
use ControleOnline\Entity\People;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Doctrine...ServiceEntityRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Doctrine\Persistence\ManagerRegistry;
0 ignored issues
show
Bug introduced by
The type Doctrine\Persistence\ManagerRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Doctrine\ORM\Query\ResultSetMapping;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Query\ResultSetMapping was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
/**
12
 * @method Particulars|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Particulars|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Particulars[]    findAll()
15
 * @method Particulars[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class ParticularsRepository extends ServiceEntityRepository
18
{
19
    public function __construct(ManagerRegistry $registry)
20
    {
21
        parent::__construct($registry, Particulars::class);
22
    }
23
24
    public function getParticularsByPeopleAndFieldType(People $people, array $fieldTypes): array
25
    {
26
        $sql = "
27
            SELECT
28
                par.id,
29
                pty.id AS type_id,
30
                pty.type_value,
31
                par.particular_value AS value
32
            FROM particulars par
33
                INNER JOIN particulars_type pty ON pty.id = par.particulars_type_id
34
            WHERE
35
                par.people_id = :people_id AND pty.field_type IN (:field_types)
36
        ";
37
38
        $rsm = new ResultSetMapping();
39
40
        $rsm->addScalarResult('id'        , 'id'        , 'integer');
41
        $rsm->addScalarResult('type_id'   , 'type_id'   , 'integer');
42
        $rsm->addScalarResult('type_value', 'type_value', 'string');
43
        $rsm->addScalarResult('value'     , 'value'     , 'string');
44
45
        $nqu = $this->getEntityManager()->createNativeQuery($sql, $rsm);
46
47
        $nqu->setParameter('people_id'  , $people->getId());
48
        $nqu->setParameter('field_types', $fieldTypes);
49
50
        return $nqu->getArrayResult();
51
    }
52
53
    public function getParticularsByPeopleAndContext(People $people, string $context): array
54
    {
55
        $sql = "
56
            SELECT
57
                par.id,
58
                pty.id AS type_id,
59
                pty.type_value,
60
                par.particular_value AS value
61
            FROM particulars par
62
                INNER JOIN particulars_type pty ON pty.id = par.particulars_type_id
63
            WHERE
64
                par.people_id = :people_id AND pty.context LIKE :context
65
        ";
66
67
        $rsm = new ResultSetMapping();
68
69
        $rsm->addScalarResult('id'        , 'id'        , 'integer');
70
        $rsm->addScalarResult('type_id'   , 'type_id'   , 'integer');
71
        $rsm->addScalarResult('type_value', 'type_value', 'string');
72
        $rsm->addScalarResult('value'     , 'value'     , 'string');
73
74
        $nqu = $this->getEntityManager()->createNativeQuery($sql, $rsm);
75
76
        $nqu->setParameter('people_id', $people->getId());
77
        $nqu->setParameter('context'  , '%' . $context . '%');
78
79
        return $nqu->getArrayResult();
80
    }
81
}
82