Passed
Push — main ( 314caa...efe81e )
by Aleksandr
08:32
created

CreateBasketRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 74
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setAutoSend() 0 4 1
A removeAutoSend() 0 4 1
A addOrder() 0 4 1
A getAutoSend() 0 3 1
A getOrders() 0 3 1
A forgetOrders() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DalliSDK\Requests;
6
7
use DalliSDK\Models\Order;
8
use DalliSDK\Responses\CreateBasketResponse;
9
use JMS\Serializer\Annotation as JMS;
10
11
/**
12
 * Запрос на добавление заявки в корзину
13
 *
14
 * @see https://api.dalli-service.com/v1/doc/createbasket
15
 * @JMS\XmlRoot("basketcreate")
16
 */
17
class CreateBasketRequest extends AbstractRequest implements RequestInterface
18
{
19
    public const RESPONSE_CLASS = CreateBasketResponse::class;
20
21
    /**
22
     * Можно указать "T", тогда заказ сразу отправится в забор, минуя корзину.
23
     * Идентично добавлению заказа в корзину,
24
     * а затем его отправки через метод sendbasket (необязательный атрибут)
25
     *
26
     * @JMS\XmlAttribute()
27
     * @JMS\Type("string")
28
     * @JMS\SerializedName("autosend")
29
     */
30
    private ?string $autoSend = null;
31
32
    /**
33
     * @JMS\Type("array<DalliSDK\Models\Order>")
34
     * @JMS\XmlList(inline = true, entry = "order")
35
     * @var Order[]
36
     */
37
    private array $orders = [];
38
39
    /**
40
     * @return Order[]
41
     */
42 2
    public function getOrders(): array
43
    {
44 2
        return $this->orders;
45
    }
46
47
    /**
48
     * @param Order $order
49
     *
50
     * @return CreateBasketRequest
51
     */
52 2
    public function addOrder(Order $order): CreateBasketRequest
53
    {
54 2
        $this->orders[] = $order;
55 2
        return $this;
56
    }
57
58
    /**
59
     * @return CreateBasketRequest
60
     */
61 2
    public function forgetOrders(): CreateBasketRequest
62
    {
63 2
        $this->orders = [];
64 2
        return $this;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70 2
    public function getAutoSend(): bool
71
    {
72 2
        return $this->autoSend === 'T';
73
    }
74
75
    /**
76
     * @return CreateBasketRequest
77
     */
78 1
    public function setAutoSend(): CreateBasketRequest
79
    {
80 1
        $this->autoSend = "T";
81 1
        return $this;
82
    }
83
84
    /**
85
     * @return CreateBasketRequest
86
     */
87 1
    public function removeAutoSend(): CreateBasketRequest
88
    {
89 1
        $this->autoSend = null;
90 1
        return $this;
91
    }
92
}
93