Package::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 9.8333
cc 3
nc 1
nop 1
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\BaseTypes;
6
7
use JMS\Serializer\Annotation\Type;
8
9
/**
10
 * Class Package
11
 * @package CdekSDK2\BaseTypes
12
 */
13
class Package extends Base
14
{
15
    /**
16
     * Номер упаковки
17
     * @Type("string")
18
     * @var string
19
     */
20
    public $number;
21
22
    /**
23
     * Общий вес (в граммах)
24
     * @Type("int")
25
     * @var int
26
     */
27
    public $weight;
28
29
    /**
30
     * Объемный вес (в граммах)
31
     * @Type("int")
32
     * @var int
33
     */
34
    public $weight_volume;
35
36
    /**
37
     * Расчетный вес (в граммах)
38
     * @Type("int")
39
     * @var int
40
     */
41
    public $weight_calc;
42
43
    /**
44
     * Габариты упаковки. Длина (в сантиметрах)
45
     * @Type("int")
46
     * @var int
47
     */
48
    public $length;
49
50
    /**
51
     * Габариты упаковки. Ширина (в сантиметрах)
52
     * @Type("int")
53
     * @var int
54
     */
55
    public $width;
56
57
    /**
58
     * Габариты упаковки. Высота (в сантиметрах)
59
     * @Type("int")
60
     * @var int
61
     */
62
    public $height;
63
64
    /**
65
     * Комментарий к упаковке
66
     * @Type("string")
67
     * @var string
68
     */
69
    public $comment;
70
71
    /**
72
     * Позиции товаров в упаковке
73
     * @Type("array<CdekSDK2\BaseTypes\Item>")
74
     * @var Item[]
75
     */
76
    public $items;
77
78
    /**
79
     * Package constructor.
80
     * @param array $param
81
     */
82
    public function __construct(array $param = [])
83
    {
84
        parent::__construct($param);
85
        $this->rules = [
86
            'number' => 'required',
87
            'weight' => 'required|numeric',
88
            'length' => 'required|numeric',
89
            'width' => 'required|numeric',
90
            'height' => 'required|numeric',
91
            'items' => [
92
                'required', 'array',
93
                function ($value) {
94
                    foreach ($value as $item) {
95
                        if ($item instanceof Item) {
96
                            $item->validate();
97
                        }
98
                    }
99
                }
100
            ],
101
        ];
102
    }
103
}
104