Issues (24)

src/Requests/SendToDeliveryBasketRequest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DalliSDK\Requests;
6
7
use DalliSDK\Responses\SendToDeliveryResponse;
8
use JMS\Serializer\Annotation as JMS;
9
10
/**
11
 * Запрос на добавление заказов из корзины в акт
12
 *
13
 * @see https://api.dalli-service.com/v1/doc/sendbasket
14
 * @JMS\XmlRoot("sendbasket")
15
 */
16
class SendToDeliveryBasketRequest extends AbstractRequest implements RequestInterface
17
{
18
    public const RESPONSE_CLASS = SendToDeliveryResponse::class;
19
20
    /**
21
     * Контейнер, который содержит штрих-коды заказов.
22
     * По-умолчанию все переданные заказы за сегодня (не обязательный элемент)
23
     *
24
     * @JMS\XmlList(inline = true, entry = "barcode")
25
     */
26
    private ?array $barcodes = null;
27
28
    /**
29
     * @return array|null
30
     */
31 2
    public function getBarcodes(): ?array
32
    {
33 2
        return $this->barcodes;
34
    }
35
36
    /**
37
     * @param array|null $barcodes
38
     *
39
     * @return SendToDeliveryBasketRequest
40
     */
41 1
    public function setBarcodes(?array $barcodes): SendToDeliveryBasketRequest
42
    {
43 1
        $this->barcodes = $barcodes;
44 1
        return $this;
45
    }
46
47
    /**
48
     * @param string $barcode
49
     *
50
     * @return $this
51
     */
52 2
    public function addBarcode(string $barcode): SendToDeliveryBasketRequest
53
    {
54 2
        if ($this->barcodes === null) {
55 2
            $this->barcodes = [];
56
        }
57 2
        if (in_array($barcode, $this->barcodes)) {
0 ignored issues
show
It seems like $this->barcodes can also be of type null; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        if (in_array($barcode, /** @scrutinizer ignore-type */ $this->barcodes)) {
Loading history...
58 1
            throw new \InvalidArgumentException("Barcode: $barcode already exists.");
59
        }
60 2
        $this->barcodes[] = $barcode;
61 2
        return $this;
62
    }
63
}
64