Packaging::fromArray()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 6
nop 1
dl 0
loc 18
rs 9.6111
c 0
b 0
f 0
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\Domain\Article\Model\VO;
15
16
final class Packaging
17
{
18
    private array $parcel;
19
    private ?array $subPackage;
20
    private ?array $consumerUnit;
21
22
    public function __construct(array $parcel, ?array $subPackage = null, ?array $consumerUnit = null)
23
    {
24
        $this->parcel = $parcel;
25
        $this->subPackage = $subPackage;
26
        $this->consumerUnit = $consumerUnit;
27
    }
28
29
    public static function fromArray(array $packages): self
30
    {
31
        $parcel = Storage::fromArray($packages[0])->toArray();
32
        $subPackage = null;
33
        $consumerUnit = null;
34
35
        for ($i = 1; $i < 3; ++$i) {
36
            if (null !== $packages[$i]) {
37
                if (1 === $i) {
38
                    $subPackage = Storage::fromArray($packages[$i])->toArray();
39
                }
40
                if (2 === $i) {
41
                    $consumerUnit = Storage::fromArray($packages[$i])->toArray();
42
                }
43
            }
44
        }
45
46
        return new self($parcel, $subPackage, $consumerUnit);
47
    }
48
49
    public function parcel(): array
50
    {
51
        return $this->parcel;
52
    }
53
54
    public function subPackage(): ?array
55
    {
56
        return $this->subPackage;
57
    }
58
59
    public function consumerUnit(): ?array
60
    {
61
        return $this->consumerUnit;
62
    }
63
}
64