Contact::__construct()   A
last analyzed

Complexity

Conditions 6
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 15
cp 0
rs 9.2222
cc 6
nc 1
nop 1
crap 42
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CdekSDK2\BaseTypes;
6
7
use JMS\Serializer\Annotation\SkipWhenEmpty;
8
use JMS\Serializer\Annotation\Type;
9
10
/**
11
 * Class Contact
12
 * @package CdekSDK2\BaseTypes
13
 */
14
class Contact extends Base
15
{
16
    /**
17
     * Название компании
18
     * @SkipWhenEmpty()
19
     * @Type("string")
20
     * @var string
21
     */
22
    public $company = '';
23
24
    /**
25
     * ФИО контактного лица
26
     * @Type("string")
27
     * @var string
28
     */
29
    public $name = '';
30
31
    /**
32
     * Электронный адрес
33
     * @SkipWhenEmpty()
34
     * @Type("string")
35
     * @var string
36
     */
37
    public $email = '';
38
39
    /**
40
     * Список телефонов
41
     * @Type("array<CdekSDK2\BaseTypes\Phone>")
42
     * @var Phone[]
43
     */
44
    public $phones = [];
45
46
    /**
47
     * Серия паспорта получателя(только для международных заказов)
48
     * @SkipWhenEmpty()
49
     * @Type("string")
50
     * @var string
51
     */
52
    public $passport_series;
53
54
    /**
55
     * Номер паспорта получателя (только для международных заказов)
56
     * @SkipWhenEmpty()
57
     * @Type("string")
58
     * @var string
59
     */
60
    public $passport_number;
61
62
    /**
63
     * Дата выдачи паспорта получателя (только для международных заказов)
64
     * @SkipWhenEmpty()
65
     * @Type("string")
66
     * @var string
67
     */
68
    public $passport_date_of_issue;
69
70
    /**
71
     * Орган выдачи паспорта получателя (только для международных заказов)
72
     * @SkipWhenEmpty()
73
     * @Type("string")
74
     * @var string
75
     */
76
    public $passport_organization;
77
78
    /**
79
     * Дата рождения получателя (только для международных заказов)
80
     * @SkipWhenEmpty()
81
     * @Type("string")
82
     * @var string
83
     */
84
    public $passport_date_of_birth;
85
86
    /**
87
     * ИНН получателя (только для международных заказов)
88
     * @SkipWhenEmpty()
89
     * @Type("string")
90
     * @var string
91
     */
92
    public $tin;
93
94
95
    /**
96
     * Contact constructor.
97
     * @param array $param
98
     */
99
    public function __construct(array $param = [])
100
    {
101
        parent::__construct($param);
102
        $this->rules = [
103
            'name' => 'required',
104
            'email' => 'email',
105
            'phones' => [
106
                'required',
107
                function ($value) {
108
                    if (!is_array($value) || empty($value) || count($value) < 1) {
109
                        return false;
110
                    }
111
                    $i = 0;
112
                    foreach ($value as $item) {
113
                        if ($item instanceof Phone) {
114
                            /* @var $item Phone */
115
                            $i += (int)$item->validate();
116
                        }
117
                    }
118
                    return ($i === count($value));
119
                }
120
            ]
121
        ];
122
    }
123
}
124