Issues (10)

src/Service/WarehousesService.php (1 issue)

Labels
Severity
1
<?php
2
namespace Dolibarr\Client\Service;
3
4
use Doctrine\Common\Collections\ArrayCollection;
5
use Dolibarr\Client\Domain\Resource\ApiResource;
6
use Dolibarr\Client\Domain\Resource\ResourceId;
7
use Dolibarr\Client\Domain\Warehouse\Warehouse;
8
use Dolibarr\Client\Domain\Warehouse\WarehouseId;
9
use Dolibarr\Client\Exception\ApiException;
10
use Dolibarr\Client\HttpClient\HttpClientInterface;
11
use JMS\Serializer\SerializerInterface;
12
13
/**
14
 * @author Laurent De Coninck <[email protected]>
15
 */
16
final class WarehousesService extends AbstractService
17
{
18
    /**
19
     * @param HttpClientInterface $httpClient
20
     * @param SerializerInterface $serializerInterface
21
     */
22
    public function __construct(HttpClientInterface $httpClient, SerializerInterface $serializerInterface)
23
    {
24
        parent::__construct($httpClient, $serializerInterface, new ApiResource('warehouses'));
25
    }
26
27
    /**
28
     * @param int $limit
29
     * @param int $page
30
     *
31
     * @return ArrayCollection|Warehouse[]
32
     *
33
     * @throws ApiException
34
     */
35
    public function findAll($limit = 100, $page = 0)
36
    {
37
        $options = [
38
            'query' => [
39
                'limit' => $limit,
40
                'page'  => $page
41
            ]
42
        ];
43
44
        $warehouses = $this->getList($options);
45
46
        return $this->deserializeCollection($warehouses, Warehouse::class);
47
    }
48
49
    /**
50
     * @param WarehouseId $id
51
     *
52
     * @return Warehouse
53
     *
54
     * @throws ApiException
55
     */
56
    public function getById(WarehouseId $id)
57
    {
58
        $response = $this->get($id->getId());
59
60
        return $this->deserialize($response, Warehouse::class);
61
    }
62
63
    /**
64
     * @param WarehouseId $id
65
     *
66
     * @throws ApiException
67
     */
68
    public function remove(WarehouseId $id)
69
    {
70
        $this->delete($id->getId());
71
    }
72
73
    /**
74
     * @param Warehouse $warehouse
75
     *
76
     * @return WarehouseId
77
     *
78
     * @throws ApiException
79
     */
80
    public function create(Warehouse $warehouse)
81
    {
82
        $resourceId = new ResourceId($this->post($this->serialize($warehouse)));
0 ignored issues
show
$this->post($this->serialize($warehouse)) of type string is incompatible with the type integer expected by parameter $id of Dolibarr\Client\Domain\R...sourceId::__construct(). ( Ignorable by Annotation )

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

82
        $resourceId = new ResourceId(/** @scrutinizer ignore-type */ $this->post($this->serialize($warehouse)));
Loading history...
83
84
        return WarehouseId::fromResourceId($resourceId);
85
    }
86
}
87