Passed
Pull Request — develop (#152)
by Laurent
01:25
created

DoctrineSettingsFinder::createSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
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\Finders\Doctrine;
15
16
use Administration\Application\Protocol\Finders\SettingsFinderProtocol;
17
use Administration\Application\Settings\ReadModel\Settings as SettingsReadModel;
18
use Administration\Infrastructure\Settings\Mapper\SettingsModelMapper;
19
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Connection 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\DBAL\Exception;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Exception 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
22
class DoctrineSettingsFinder implements SettingsFinderProtocol
23
{
24
    private Connection $connection;
25
26
    public function __construct(Connection $connection)
27
    {
28
        $this->connection = $connection;
29
    }
30
31
    /**
32
     * @throws Exception
33
     */
34
    public function findOne(): ?SettingsReadModel
35
    {
36
        $query = $this->connection->createQueryBuilder()
37
            ->select('uuid', 'currency', 'locale')
38
            ->from('settings')
39
        ;
40
        $result = $query->execute()->fetchAssociative();
41
42
        if (false !== $result) {
43
            return (new SettingsModelMapper())->getReadModelFromArray($result);
44
        }
45
46
        return null;
47
    }
48
49
    /**
50
     * @throws Exception
51
     */
52
    public function findByLocale(string $locale): ?SettingsReadModel
53
    {
54
        $query = $this->connection->createQueryBuilder()
55
            ->select('uuid', 'currency', 'locale')
56
            ->from('settings')
57
            ->where('locale = :locale')
58
            ->setParameter('locale', $locale)
59
        ;
60
        $result = $query->execute()->fetchAssociative();
61
62
        if (false !== $result) {
63
            return (new SettingsModelMapper())->getReadModelFromArray($result);
64
        }
65
66
        return null;
67
    }
68
69
    /**
70
     * @throws Exception
71
     */
72
    public function findByCurrency(string $currency): ?SettingsReadModel
73
    {
74
        $query = $this->connection->createQueryBuilder()
75
            ->select('uuid', 'currency', 'locale')
76
            ->from('settings')
77
            ->where('currency = :currency')
78
            ->setParameter('currency', $currency)
79
        ;
80
        $result = $query->execute()->fetchAssociative();
81
82
        if (false !== $result) {
83
            return (new SettingsModelMapper())->getReadModelFromArray($result);
84
        }
85
86
        return null;
87
    }
88
}
89