Passed
Pull Request — develop (#118)
by Laurent
05:08 queued 02:44
created

Article::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
c 0
b 0
f 0
rs 9.9332
cc 1
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 Domain\Article\Model;
15
16
use Domain\Article\Model\Entities\ZoneStorage;
17
use Domain\Article\Model\VO\Packaging;
18
use Domain\Common\Model\Entities\FamilyLog;
19
use Domain\Common\Model\Entities\Taxes;
20
use Domain\Common\Model\VO\NameField;
21
use Domain\Supplier\Model\Supplier;
22
23
final class Article
24
{
25
    private string $uuid;
26
    private string $name;
27
    private string $supplier;
28
    private Packaging $packaging;
29
    private float $price;
30
    private string $taxes;
31
    private float $quantity;
32
    private float $minStock;
33
34
    /**
35
     * @var ZoneStorage[]
36
     */
37
    private array $zoneStorages;
38
    private string $familyLog;
39
    private bool $active;
40
    private string $slug;
41
42
    public function __construct(
43
        ArticleUuid $uuid,
44
        NameField $name,
45
        Supplier $supplier,
46
        Packaging $packaging,
47
        float $price,
48
        Taxes $taxes,
49
        float $minStock,
50
        array $zoneStorages,
51
        FamilyLog $familyLog,
52
        ?float $quantity = 0.000,
53
        ?bool $active = true
54
    ) {
55
        $this->uuid = $uuid->toString();
56
        $this->name = $name->getValue();
57
        $this->supplier = $supplier->name();
58
        $this->packaging = $packaging;
59
        $this->price = $price;
60
        $this->taxes = $taxes->name();
61
        $this->quantity = $quantity ?? 0.000;
62
        $this->minStock = $minStock;
63
        $this->zoneStorages = $zoneStorages;
64
        $this->familyLog = $familyLog->path();
65
        $this->active = $active ?? true;
66
        $this->slug = $name->slugify();
67
    }
68
69
    /**
70
     * @param ZoneStorage[] $zoneStorages
71
     */
72
    public static function create(
73
        ArticleUuid $uuid,
74
        NameField $name,
75
        Supplier $supplier,
76
        Packaging $packaging,
77
        float $price,
78
        Taxes $taxes,
79
        float $minStock,
80
        array $zoneStorages,
81
        FamilyLog $familyLog
82
    ): self {
83
        return new self(
84
            $uuid,
85
            $name,
86
            $supplier,
87
            $packaging,
88
            $price,
89
            $taxes,
90
            $minStock,
91
            $zoneStorages,
92
            $familyLog
93
        );
94
    }
95
96
    public function uuid(): string
97
    {
98
        return $this->uuid;
99
    }
100
101
    public function name(): string
102
    {
103
        return $this->name;
104
    }
105
106
    public function supplier(): string
107
    {
108
        return $this->supplier;
109
    }
110
111
    public function packaging(): Packaging
112
    {
113
        return $this->packaging;
114
    }
115
116
    public function price(): float
117
    {
118
        return $this->price;
119
    }
120
121
    public function taxes(): string
122
    {
123
        return $this->taxes;
124
    }
125
126
    public function quantity(): float
127
    {
128
        return $this->quantity;
129
    }
130
131
    public function minStock(): float
132
    {
133
        return $this->minStock;
134
    }
135
136
    /**
137
     * @return ZoneStorage[]
138
     */
139
    public function zoneStorages(): array
140
    {
141
        return $this->zoneStorages;
142
    }
143
144
    public function familyLog(): string
145
    {
146
        return $this->familyLog;
147
    }
148
149
    public function isActive(): bool
150
    {
151
        return $this->active;
152
    }
153
154
    public function slug(): string
155
    {
156
        return $this->slug;
157
    }
158
159
    public function renameArticle(NameField $name): void
160
    {
161
        $this->name = $name->getValue();
162
        $this->slug = $name->slugify();
163
    }
164
}
165