CalculationRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Requests;
6
7
use Appwilio\RussianPostSDK\Core\Arrayable;
8
use Appwilio\RussianPostSDK\Dispatching\Enum\MailType;
9
use Appwilio\RussianPostSDK\Dispatching\Enum\MailCategory;
10
use Appwilio\RussianPostSDK\Dispatching\Enum\MailEntryType;
11
use Appwilio\RussianPostSDK\Dispatching\Entities\CommonOrder;
12
13
final class CalculationRequest implements Arrayable
14
{
15
    use CommonOrder;
16
17 1
    public static function create(string $to, int $weight): self
18
    {
19 1
        return new self(...\func_get_args());
20
    }
21
22 1
    public function __construct(string $to, int $weight)
23
    {
24 1
        $this->data = [
25 1
            'index-to' => $to,
26 1
            'mass'     => $weight,
27
        ];
28 1
    }
29
30
    public function ofEntriesType(MailEntryType $entriesType)
31
    {
32
        $this->data['entries-type'] = $entriesType;
33
34
        return $this;
35
    }
36
37
    public function ofMailCategory(MailCategory $mailCategory)
38
    {
39
        $this->data['mail-category'] = $mailCategory;
40
41
        return $this;
42
    }
43
44 1
    public function ofMailType(MailType $mailType)
45
    {
46 1
        $this->data['mail-type'] = $mailType;
47
48 1
        return $this;
49
    }
50
51
    public function withDeclaredValue(int $value)
52
    {
53
        $this->data['declared-value'] = $value;
54
55
        return $this;
56
    }
57
58 1
    public function withContentChecking(bool $value = true)
59
    {
60 1
        $this->data['contents-checking'] = $value;
61
62 1
        return $this;
63
    }
64
65 1
    public function withFitting(bool $value = true)
66
    {
67 1
        $this->data['with-fitting'] = $value;
68
69 1
        return $this;
70
    }
71
72 1
    public function toArray(): array
73
    {
74 1
        if ($this->data['mail-type']->equals(MailType::ECOM())) {
75 1
            $this->data['delivery-point-index'] = $this->data['index-to'];
76
77 1
            unset($this->data['index-to']);
78
        }
79
80 1
        return $this->data;
81
    }
82
}
83