Completed
Push — main ( fffb13...d8afdd )
by Laurent
139:07 queued 124:29
created

Article   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 155
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 24 1
A create() 0 21 1
A renameArticle() 0 5 1
A makeZoneStorageEntities() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Domain\Model\Article;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Domain\Model\Article\Entities\ZoneStorage;
9
use Domain\Model\Article\VO\Packaging;
10
use Domain\Model\Common\Entities\FamilyLog;
11
use Domain\Model\Common\Entities\Taxes;
12
use Domain\Model\Common\VO\NameField;
13
use Domain\Model\Supplier\Supplier;
14
15
/**
16
 * Article.
17
 *
18
 * @category Entity
19
 */
20
class Article
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $articleId;
26
27
    /**
28
     * @var string Name of article
29
     */
30
    protected $name;
31
32
    /**
33
     * @var string Name of supplier
34
     */
35
    protected $supplier;
36
37
    /**
38
     * @var array Packaging (subdivision of parcel)
39
     */
40
    protected $packaging;
41
42
    /**
43
     * @var float Price of article
44
     */
45
    protected $price;
46
47
    /**
48
     * @var string Rate of VAT
49
     */
50
    protected $taxes;
51
52
    /**
53
     * @var float Quantity in stock
54
     */
55
    protected $quantity;
56
57
    /**
58
     * @var float Minimum stock
59
     */
60
    protected $minStock;
61
62
    /**
63
     * @var ArrayCollection Storage area(s)
64
     */
65
    protected $zoneStorages;
66
67
    /**
68
     * @var string Logistics family
69
     */
70
    protected $familyLog;
71
72
    /**
73
     * @var bool Active/Inactive
74
     */
75
    protected $active;
76
77
    /**
78
     * @var string
79
     */
80
    protected $slug;
81
82
    /**
83
     * Article constructor.
84
     *
85
     * @param NameField  $name
86
     * @param Supplier   $supplier
87
     * @param Packaging  $packaging
88
     * @param float      $price
89
     * @param Taxes      $taxes
90
     * @param float      $minStock
91
     * @param array      $zoneStorages
92
     * @param FamilyLog  $familyLog
93
     * @param float|null $quantity
94
     * @param bool|null  $active
95
     */
96
    public function __construct(
97
        NameField $name,
98
        Supplier $supplier,
99
        Packaging $packaging,
100
        float $price,
101
        Taxes $taxes,
102
        float $minStock,
103
        array $zoneStorages,
104
        FamilyLog $familyLog,
105
        ?float $quantity = 0.000,
106
        ?bool $active = true
107
    ) {
108
        $this->name = $name->getValue();
109
        $this->supplier = $supplier->name();
110
        $this->packaging = $packaging;
0 ignored issues
show
Documentation Bug introduced by
It seems like $packaging of type object<Domain\Model\Article\VO\Packaging> is incompatible with the declared type array of property $packaging.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
111
        $this->price = $price;
112
        $this->taxes = $taxes->name();
113
        $this->quantity = $quantity;
114
        $this->minStock = $minStock;
115
        $this->zoneStorages = new ArrayCollection($this->makeZoneStorageEntities($zoneStorages));
116
        $this->familyLog = $familyLog->path();
117
        $this->active = $active;
118
        $this->slug = $name->slugify();
119
    }
120
121
    /**
122
     * Create an Article.
123
     *
124
     * @param NameField $name
125
     * @param Supplier  $supplier
126
     * @param Packaging $packaging
127
     * @param float     $price
128
     * @param Taxes     $taxes
129
     * @param float     $minStock
130
     * @param array     $zoneStorages
131
     * @param FamilyLog $familyLog
132
     *
133
     * @return Article
134
     */
135
    public static function create(
136
        NameField $name,
137
        Supplier $supplier,
138
        Packaging $packaging,
139
        float $price,
140
        Taxes $taxes,
141
        float $minStock,
142
        array $zoneStorages,
143
        FamilyLog $familyLog
144
    ): self {
145
        return new self(
146
            $name,
147
            $supplier,
148
            $packaging,
149
            $price,
150
            $taxes,
151
            $minStock,
152
            $zoneStorages,
153
            $familyLog
154
        );
155
    }
156
157
    final public function renameArticle(NameField $name): void
158
    {
159
        $this->name = $name->getValue();
160
        $this->slug = $name->slugify();
161
    }
162
163
    /**
164
     * @param array $zoneStorages
165
     *
166
     * @return ZoneStorage[]
167
     */
168
    private function makeZoneStorageEntities(array $zoneStorages): array
169
    {
170
        return array_map(static function ($zone) {
171
            return new ZoneStorage(NameField::fromString($zone));
172
        }, $zoneStorages);
173
    }
174
}
175