Passed
Push — master ( 2cdaae...14b6d5 )
by Jhao
02:25
created

OrderItem::withExcise()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Entites;
15
16
use Appwilio\RussianPostSDK\Dispatching\Enum\Country;
17
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable;
18
use Appwilio\RussianPostSDK\Dispatching\Enum\PaymentMode54FZ;
19
use Appwilio\RussianPostSDK\Dispatching\Enum\PaymentSubject54FZ;
20
21
final class OrderItem implements Arrayable
22
{
23
    public const VAT_NO = -1;
24
    public const VAT_0 = 0;
25
    public const VAT_10 = 10;
26
    public const VAT_20 = 20;
27
28
    // TODO: вынести в enum? https://otpravka.pochta.ru/specification#/enums-goods-type
29
    public const TYPE_GOODS = 'GOODS';
30
    public const TYPE_SERVICE = 'SERVICE';
31
32
    /** @var array */
33
    private $data;
34
35
    public static function create(
36
        string $title,
37
        int $quantity,
38
        int $price,
39
        ?string $code = null,
40
        ?string $article = null
41
    ): self {
42
        return new self(...\func_get_args());
43
    }
44
45
    public function __construct(string $description, int $quantity, ?int $price = null, ?string $code = null, ?string $article = null)
46
    {
47
        $this->data['description'] = $description;
48
        $this->data['quantity'] = $quantity;
49
        $this->data['value'] = $price;
50
        $this->data['code'] = $code;
51
        $this->data['item-number'] = $article;
52
    }
53
54
    public function ofType(string $type)
55
    {
56
        $this->data['goods-type'] = $type;
57
58
        return $this;
59
    }
60
61
    public function ofCountry(Country $code)
62
    {
63
        $this->data['country-code'] = $code;
64
65
        return $this;
66
    }
67
68
    public function bySupplier(string $inn, string $name, string $phone)
69
    {
70
        $this->data['supplier-inn'] = $inn;
71
        $this->data['supplier-name'] = $name;
72
        $this->data['supplier-phone'] = $phone;
73
74
        return $this;
75
    }
76
77
    public function paymentMode(PaymentMode54FZ $mode)
78
    {
79
        $this->data['payattr'] = $mode;
80
81
        return $this;
82
    }
83
84
    public function paymentSubject(PaymentSubject54FZ $subject)
85
    {
86
        $this->data['lineattr'] = $subject;
87
88
        return $this;
89
    }
90
91
    public function withCustomsDeclarationNumber(string $number)
92
    {
93
        $this->data['customs-declaration-number'] = $number;
94
95
        return $this;
96
    }
97
98
    public function withVAT(int $vat)
99
    {
100
        $this->data['vat-rate'] = $vat;
101
102
        return $this;
103
    }
104
105
    public function withInshurance(int $value)
106
    {
107
        $this->data['insr-value'] = $value;
108
109
        return $this;
110
    }
111
112
    public function withExcise(int $value)
113
    {
114
        $this->data['excise'] = $value;
115
116
        return $this;
117
    }
118
119
    public function toArray(): array
120
    {
121
        return $this->data;
122
    }
123
}
124