Passed
Push — feature-family-log ( 655216 )
by Laurent
01:49
created

DoctrineFamilyLogFinder::findBySlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 11
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 15
rs 9.9
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\Finders\DoctrineOrm;
15
16
use Administration\Application\FamilyLog\ReadModel\FamilyLog as FamilyLogModel;
17
use Administration\Application\FamilyLog\ReadModel\FamilyLogs;
18
use Administration\Application\Protocol\Finders\FamilyLogFinderProtocol;
19
use Administration\Domain\FamilyLog\Model\FamilyLog;
20
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...
21
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...
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 DoctrineFamilyLogFinder extends ServiceEntityRepository implements FamilyLogFinderProtocol
25
{
26
    public function __construct(ManagerRegistry $registry)
27
    {
28
        parent::__construct($registry, FamilyLog::class);
29
    }
30
31
    /**
32
     * @throws NonUniqueResultException
33
     */
34
    public function findBySlug(string $slug): FamilyLogModel
35
    {
36
        $result = $this->createQueryBuilder('fl')
37
            ->where('fl.slug = :slug')
38
            ->setParameter('slug', $slug)
39
            ->getQuery()
40
            ->getOneOrNullResult()
41
        ;
42
43
        return new FamilyLogModel(
44
            $result->name(),
45
            $result->parent(),
46
            $result->children(),
47
            $result->path(),
48
            $result->slug()
49
        );
50
    }
51
52
    public function findAll(): FamilyLogs
53
    {
54
        $statement = $this->createQueryBuilder('fl')
55
            ->getQuery()
56
            ->getResult()
57
        ;
58
59
        return new FamilyLogs(
60
            ...\array_map(static function (FamilyLog $familyLog) {
61
                return new FamilyLogModel(
62
                    $familyLog->name(),
63
                    $familyLog->parent(),
0 ignored issues
show
Bug introduced by
It seems like $familyLog->parent() can also be of type Administration\Domain\FamilyLog\Model\FamilyLog; however, parameter $parent of Administration\Applicati...amilyLog::__construct() does only seem to accept null|string, 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

63
                    /** @scrutinizer ignore-type */ $familyLog->parent(),
Loading history...
64
                    $familyLog->children(),
65
                    $familyLog->path(),
66
                    $familyLog->slug()
67
                );
68
            }, $statement)
69
        );
70
    }
71
}
72