Completed
Push — master ( 37d52e...ca4941 )
by Jhao
11:04
created

OrderItem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 21
c 1
b 0
f 0
dl 0
loc 55
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A withInshurance() 0 5 1
A bySupplier() 0 7 1
A create() 0 8 1
A toArray() 0 3 1
A withVAT() 0 5 1
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\Contracts\Arrayable;
17
18
final class OrderItem implements Arrayable
19
{
20
    public const VAT_NO = -1;
21
    public const VAT_0 = 0;
22
    public const VAT_10 = 10;
23
    public const VAT_20 = 20;
24
25
    /** @var array */
26
    private $data;
27
28
    public static function create(
29
        string $title,
30
        int $quantity,
31
        int $price,
32
        ?string $code = null,
33
        ?string $article = null
34
    ): self {
35
        return new self(...\func_get_args());
36
    }
37
38
    public function __construct(string $title, int $quantity, int $price, ?string $code = null, ?string $article = null)
39
    {
40
        $this->data['description'] = $title;
41
        $this->data['quantity'] = $quantity;
42
        $this->data['price'] = $price;
43
        $this->data['code'] = $code;
44
        $this->data['item-number'] = $article;
45
    }
46
47
    public function bySupplier(string $inn, string $name, string $phone)
48
    {
49
        $this->data['supplier-inn'] = $inn;
50
        $this->data['supplier-name'] = $name;
51
        $this->data['supplier-phone'] = $phone;
52
53
        return $this;
54
    }
55
56
    public function withVAT(int $vat)
57
    {
58
        $this->data['vat-rate'] = $vat;
59
60
        return $this;
61
    }
62
63
    public function withInshurance(int $value)
64
    {
65
        $this->data['insr-value'] = $value;
66
67
        return $this;
68
    }
69
70
    public function toArray(): array
71
    {
72
        return $this->data;
73
    }
74
}
75