Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

Settings   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
c 0
b 0
f 0
dl 0
loc 69
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocale() 0 3 1
A getCurrency() 0 3 1
A toModel() 0 6 1
A setCurrency() 0 5 1
A fromModel() 0 6 1
A __construct() 0 5 1
A update() 0 6 1
A setLocale() 0 5 1
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 Company\Infrastructure\Doctrine\Entity;
15
16
use Company\Domain\Model\Settings as SettingsModel;
17
use Company\Domain\Model\VO\Currency;
18
use Company\Domain\Model\VO\Locale;
19
use Company\Domain\Storage\Settings\SettingsEntity;
20
use Core\Domain\Common\Model\VO\ResourceUuid;
21
use Core\Infrastructure\Doctrine\Entity\ResourceUuid as ResourceUuidTrait;
22
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping 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
/**
25
 * @ORM\Table(name="settings")
26
 * @ORM\Entity(repositoryClass="Company\Infrastructure\Doctrine\Repository\SettingsRepository")
27
 */
28
class Settings implements SettingsEntity
29
{
30
    use ResourceUuidTrait;
31
32
    /**
33
     * @ORM\Column(type="string", name="locale", nullable=false)
34
     */
35
    private string $locale;
36
37
    /**
38
     * @ORM\Column(type="string", name="currency", nullable=false)
39
     */
40
    private string $currency;
41
42
    public function __construct(string $uuid, string $locale, string $currency)
43
    {
44
        $this->uuid = $uuid;
45
        $this->locale = $locale;
46
        $this->currency = $currency;
47
    }
48
49
    public static function fromModel(SettingsModel $settingsModel): self
50
    {
51
        return new self(
52
            ResourceUuid::fromUuid($settingsModel->uuid()),
53
            Locale::fromLocale($settingsModel->locale()),
54
            Currency::fromCurrency($settingsModel->currency())
55
        );
56
    }
57
58
    public function toModel(): SettingsModel
59
    {
60
        return SettingsModel::create(
61
            ResourceUuid::fromString($this->uuid),
62
            Locale::fromString($this->getLocale()),
63
            Currency::fromString($this->getCurrency())
64
        );
65
    }
66
67
    public function update(SettingsEntity $settingsEntity): self
68
    {
69
        $this->setCurrency($settingsEntity->getCurrency());
70
        $this->setLocale($settingsEntity->getLocale());
71
72
        return $this;
73
    }
74
75
    public function getLocale(): string
76
    {
77
        return $this->locale;
78
    }
79
80
    public function getCurrency(): string
81
    {
82
        return $this->currency;
83
    }
84
85
    private function setLocale(string $locale): self
86
    {
87
        $this->locale = $locale;
88
89
        return $this;
90
    }
91
92
    private function setCurrency(string $currency): self
93
    {
94
        $this->currency = $currency;
95
96
        return $this;
97
    }
98
}
99