Passed
Push — feature-family-log ( 655216...bb34f0 )
by Laurent
02:05
created

DoctrineFamilyLogRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Infrastructure\Persistence\DoctrineOrm\Repositories;
15
16
use Administration\Domain\FamilyLog\Model\FamilyLog;
17
use Administration\Domain\Protocol\Repository\FamilyLogRepositoryProtocol;
18
use Administration\Infrastructure\Finders\Exceptions\FamilyLogNotFound;
19
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...
20
use Doctrine\ORM\NonUniqueResultException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\NonUniqueResultException 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...
21
use Doctrine\ORM\ORMException;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\ORMException 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...
22
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...
23
24
class DoctrineFamilyLogRepository extends ServiceEntityRepository implements FamilyLogRepositoryProtocol
25
{
26
    public function __construct(ManagerRegistry $registry)
27
    {
28
        parent::__construct($registry, FamilyLog::class);
29
    }
30
31
    /**
32
     * @throws ORMException
33
     */
34
    public function add(FamilyLog $familyLog): void
35
    {
36
        $this->getEntityManager()->persist($familyLog);
37
    }
38
39
    /**
40
     * @throws NonUniqueResultException
41
     */
42
    public function findByUuid(string $uuid): FamilyLog
43
    {
44
        $result = $this->createQueryBuilder('fl')
45
            ->where('fl.uuid = :uuid')
46
            ->setParameter('uuid', $uuid)
47
            ->getQuery()
48
            ->getOneOrNullResult()
49
        ;
50
51
        if (null === $result) {
52
            throw new FamilyLogNotFound();
53
        }
54
55
        return $result;
56
    }
57
58
    /**
59
     * @throws NonUniqueResultException
60
     */
61
    public function existWithLabel(string $label, ?string $parentUuid): bool
62
    {
63
        $resultParent = false;
64
        $statement = $this->createQueryBuilder('fl')
65
            ->select(['1'])
66
            ->where('fl.label = :label')
67
            ->setParameter('label', $label)
68
            ->getQuery()
69
            ->getOneOrNullResult()
70
        ;
71
        $result = !(null === $statement);
72
73
        if (null !== $parentUuid) {
74
            $parent = $this->findByUuid($parentUuid);
75
            $resultParent = \in_array($label, $parent->children(), true);
0 ignored issues
show
Bug introduced by
It seems like $parent->children() can also be of type null; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

75
            $resultParent = \in_array($label, /** @scrutinizer ignore-type */ $parent->children(), true);
Loading history...
76
        }
77
78
        return null === $result && false === $resultParent;
79
    }
80
}
81