Passed
Push — master ( 6bd912...2e1381 )
by Jhao
03:15
created

CalculationRequest::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 6
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Requests;
6
7
use Appwilio\RussianPostSDK\Dispatching\DataAware;
8
use Appwilio\RussianPostSDK\Dispatching\Enum\MailType;
9
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable;
10
11
final class CalculationRequest implements Arrayable
12
{
13
    use DataAware;
14
15
    public static function create(string $to, int $weight): self
16
    {
17
        return new self(...\func_get_args());
18
    }
19
20
    public function __construct(string $to, int $weight)
21
    {
22
        $this->data = [
23
            'index-to' => $to,
24
            'mass'     => $weight,
25
        ];
26
    }
27
28
    public function ofEntriesType(string $entriesType)
29
    {
30
        $this->data['entries-type'] = $entriesType;
31
32
        return $this;
33
    }
34
35
    public function ofMailCategory(string $mailCategory)
36
    {
37
        $this->data['mail-category'] = $mailCategory;
38
39
        return $this;
40
    }
41
42
    public function ofMailType(string $mailType)
43
    {
44
        $this->data['mail-type'] = $mailType;
45
46
        return $this;
47
    }
48
49
    public function transport(string $value)
50
    {
51
        $this->data['transport-type'] = $value;
52
53
        return $this;
54
    }
55
56
    public function dimensions(int $height, int $width, int $length)
57
    {
58
        $this->data['dimension'] = \compact('height', 'width', 'length');
59
60
        return $this;
61
    }
62
63
    public function fragile(bool $value = true)
64
    {
65
        $this->data['fragile'] = $value;
66
67
        return $this;
68
    }
69
70
    public function viaCourier(bool $value = true)
71
    {
72
        $this->data['courier'] = $value;
73
74
        return $this;
75
    }
76
77
    public function withDeclaredValue(int $value)
78
    {
79
        $this->data['declared-value'] = $value;
80
81
        return $this;
82
    }
83
84
    public function withCompletenessChecking(bool $value = true)
85
    {
86
        $this->data['completeness-checking'] = $value;
87
88
        return $this;
89
    }
90
91
    public function withContentChecking(bool $value = true)
92
    {
93
        $this->data['contents-checking'] = $value;
94
95
        return $this;
96
    }
97
98
    public function withInventory(bool $value = true)
99
    {
100
        $this->data['inventory'] = $value;
101
102
        return $this;
103
    }
104
105
    public function withElectronicNotice(bool $value = true)
106
    {
107
        $this->data['with-electronic-notice'] = $value;
108
109
        return $this;
110
    }
111
112
    public function withFitting(bool $value = true)
113
    {
114
        $this->data['with-fitting'] = $value;
115
116
        return $this;
117
    }
118
119
    public function withSimpleNotice(bool $value = true)
120
    {
121
        $this->data['with-simple-notice'] = $value;
122
123
        return $this;
124
    }
125
126
    public function withRegisteredNotice(bool $value = true)
127
    {
128
        $this->data['with-order-of-notice'] = $value;
129
130
        return $this;
131
    }
132
133
    public function withSmsNotice(bool $value = true)
134
    {
135
        $this->data['sms-notice-recipient'] = $value;
136
137
        return $this;
138
    }
139
140
    public function toArray(): array
141
    {
142
        if ($this->data['mail-type'] === MailType::ECOM) {
143
            $this->data['delivery-point-index'] = $this->data['index-to'];
144
145
            unset($this->data['index-to']);
146
        }
147
148
        return $this->data;
149
    }
150
151
}
152