Passed
Push — master ( 92054c...3577c6 )
by Andrey
04:17
created

RecipientProperty::setRecipient()   C

Complexity

Conditions 13
Paths 36

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 23
c 1
b 0
f 0
nc 36
nop 1
dl 0
loc 39
rs 6.6166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Daaner\NovaPoshta\Traits;
4
5
trait RecipientProperty
6
{
7
8
    protected $RecipientType;
9
10
    /**
11
     * @param string $Recipient
12
     * Устанавливаем значение получателя
13
     * @return this
14
     */
15
    public function setRecipient($Recipient)
16
    {
17
        if (isset($Recipient['RecipientsPhone'])) {
18
            $this->methodProperties['RecipientsPhone'] = $Recipient['RecipientsPhone'];
1 ignored issue
show
Bug Best Practice introduced by
The property methodProperties does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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'] = isset($Recipient['RecipientArea']) ? $Recipient['RecipientArea'] : '';
48
            $this->methodProperties['RecipientAreaRegions'] = isset($Recipient['RecipientAreaRegions']) ? $Recipient['RecipientAreaRegions'] : '';
49
            $this->methodProperties['RecipientHouse'] = isset($Recipient['RecipientHouse']) ? $Recipient['RecipientHouse'] : '';
50
            $this->methodProperties['RecipientFlat'] = isset($Recipient['RecipientFlat']) ? $Recipient['RecipientFlat'] : '';
51
        }
52
53
        return $this;
54
    }
55
56
57
    /**
58
     * @param string $SeatsAmount
59
     * Устанавливаем тип груза. По умолчанию значение из конфига
60
     * @see https://devcenter.novaposhta.ua/docs/services/55702570a0fe4f0cf4fc53ed/operations/55702571a0fe4f0b64838909
61
     * @return this
62
     */
63
    public function setRecipientType($RecipientType)
64
    {
65
        $this->RecipientType = $RecipientType;
66
67
        return $this;
68
    }
69
70
    public function getRecipientType()
71
    {
72
        if (! $this->RecipientType) {
73
            $this->RecipientType = config('novaposhta.recipient_type');
74
        }
75
        $this->methodProperties['RecipientType'] = $this->RecipientType;
1 ignored issue
show
Bug Best Practice introduced by
The property methodProperties does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
76
77
        return $this;
78
    }
79
80
}
81