RecipientProperty::getRecipientType()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Daaner\NovaPoshta\Traits;
4
5
trait RecipientProperty
6
{
7
    protected $RecipientType;
8
9
    /**
10
     * Устанавливаем значение получателя.
11
     *
12
     * @param  array  $Recipient  Массив данных получателя
13
     * @return $this
14
     */
15
    public function setRecipient(array $Recipient): self
16
    {
17
        if (isset($Recipient['RecipientsPhone'])) {
18
            $this->methodProperties['RecipientsPhone'] = $Recipient['RecipientsPhone'];
19
        }
20
21
        //указываем идентификаторами проверяем и вставляем
22
        if (isset($Recipient['Recipient']) &&
23
            isset($Recipient['ContactRecipient']) &&
24
            isset($Recipient['CityRecipient']) &&
25
            isset($Recipient['RecipientAddress'])
26
        ) {
27
            $this->methodProperties['Recipient'] = $Recipient['Recipient'];
28
            $this->methodProperties['ContactRecipient'] = $Recipient['ContactRecipient'];
29
            $this->methodProperties['CityRecipient'] = $Recipient['CityRecipient'];
30
            $this->methodProperties['RecipientAddress'] = $Recipient['RecipientAddress'];
31
32
            return $this;
33
        }
34
35
        //указываем строками проверяем и вставляем
36
        if (isset($Recipient['RecipientName']) &&     //имя получателя
37
            isset($Recipient['RecipientCityName']) && //город
38
            isset($Recipient['RecipientAddressName']) //отделение или улица
39
        ) {
40
            //создаем новый адрес
41
            $this->methodProperties['NewAddress'] = 1;
42
43
            $this->methodProperties['RecipientName'] = $Recipient['RecipientName'];
44
            $this->methodProperties['RecipientCityName'] = $Recipient['RecipientCityName'];
45
            $this->methodProperties['RecipientAddressName'] = $Recipient['RecipientAddressName'];
46
47
            $this->methodProperties['RecipientArea'] = $Recipient['RecipientArea'] ?? '';
48
            $this->methodProperties['RecipientAreaRegions'] = $Recipient['RecipientAreaRegions'] ?? '';
49
            $this->methodProperties['RecipientHouse'] = $Recipient['RecipientHouse'] ?? '';
50
            $this->methodProperties['RecipientFlat'] = $Recipient['RecipientFlat'] ?? '';
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * Устанавливаем тип получателя.
58
     *
59
     * @param  string  $RecipientType  Тип получателя ('PrivatePerson', 'Organization')
60
     * @return $this
61
     */
62
    public function setRecipientType(string $RecipientType): self
63
    {
64
        $this->RecipientType = $RecipientType;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Тип получателя. По-умолчанию значение конфига.
71
     *
72
     * @return void
73
     */
74
    public function getRecipientType(): void
75
    {
76
        $this->methodProperties['RecipientType'] = $this->RecipientType ?: config('novaposhta.recipient_type');
77
    }
78
}
79