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

Packaging::subPackage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Domain\Model\Article\VO;
6
7
final class Packaging
8
{
9
    /**
10
     * @var array
11
     */
12
    private $parcel;
13
14
    /**
15
     * @var array|null
16
     */
17
    private $subPackage;
18
19
    /**
20
     * @var array|null
21
     */
22
    private $consumerUnit;
23
24
    /**
25
     * Packaging constructor.
26
     *
27
     * @param array      $parcel
28
     * @param array|null $subPackage
29
     * @param array|null $consumerUnit
30
     */
31
    public function __construct(array $parcel, ?array $subPackage = null, ?array $consumerUnit = null)
32
    {
33
        $this->parcel = $parcel;
34
        $this->subPackage = $subPackage;
35
        $this->consumerUnit = $consumerUnit;
36
    }
37
38
    /**
39
     * @param array $packages
40
     *
41
     * @return Packaging
42
     */
43
    public static function fromArray(array $packages): self
44
    {
45
        $parcel = Storage::fromArray($packages[0])->toArray();
46
        $subPackage = null;
47
        $consumerUnit = null;
48
49
        for ($iteration = 1; $iteration < 3; ++$iteration) {
50
            if (null !== $packages[$iteration]) {
51
                if (1 == $iteration) {
52
                    $subPackage = Storage::fromArray($packages[$iteration])->toArray();
53
                }
54
                if (2 == $iteration) {
55
                    $consumerUnit = Storage::fromArray($packages[$iteration])->toArray();
56
                }
57
            }
58
        }
59
60
        return new self($parcel, $subPackage, $consumerUnit);
61
    }
62
63
    public function parcel(): array
64
    {
65
        return $this->parcel;
66
    }
67
68
    public function subPackage(): ?array
69
    {
70
        return $this->subPackage;
71
    }
72
73
    public function consumerUnit(): ?array
74
    {
75
        return $this->consumerUnit;
76
    }
77
}
78