Issues (24)

src/Requests/CancelOrderRequest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DalliSDK\Requests;
6
7
use DalliSDK\Responses\CancelOrderResponse;
8
use JMS\Serializer\Annotation as JMS;
9
10
/**
11
 * Запрос на отмену заявки
12
 *
13
 * @see https://api.dalli-service.com/v1/doc/cancelOrder
14
 * @JMS\XmlRoot("cancelorder")
15
 */
16
class CancelOrderRequest extends AbstractRequest implements RequestInterface
17
{
18
    public const RESPONSE_CLASS = CancelOrderResponse::class;
19
20
    /**
21
     * Контейнер, который содержит штрих-коды заказов.
22
     *
23
     * @JMS\XmlList(inline = true, entry = "barcode")
24
     */
25
    private ?array $barcodes = null;
26
27
    /**
28
     * @return array|null
29
     */
30 2
    public function getBarcodes(): ?array
31
    {
32 2
        return $this->barcodes;
33
    }
34
35
    /**
36
     * @param array|null $barcodes
37
     *
38
     * @return CancelOrderRequest
39
     */
40 1
    public function setBarcodes(?array $barcodes): CancelOrderRequest
41
    {
42 1
        $this->barcodes = $barcodes;
43 1
        return $this;
44
    }
45
46
    /**
47
     * @param string $barcode
48
     *
49
     * @return $this
50
     */
51 2
    public function addBarcode(string $barcode): CancelOrderRequest
52
    {
53 2
        if ($this->barcodes === null) {
54 2
            $this->barcodes = [];
55
        }
56 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

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