ThirdPartiesService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getById() 0 5 1
A create() 0 3 1
1
<?php
2
3
4
namespace Dolibarr\Client\Service;
5
6
use Dolibarr\Client\Domain\Resource\ApiResource;
7
use Dolibarr\Client\Domain\Resource\ResourceId;
8
use Dolibarr\Client\Domain\Thirdparty\Thirdparty;
9
use Dolibarr\Client\Domain\Thirdparty\ThirdpartyId;
10
use Dolibarr\Client\Exception\ApiException;
11
use Dolibarr\Client\HttpClient\HttpClientInterface;
12
use JMS\Serializer\SerializerInterface;
13
14
/**
15
 * @author Laurent De Coninck <[email protected]>
16
 */
17
class ThirdPartiesService extends AbstractService
18
{
19
    /**
20
     * @param HttpClientInterface $httpClient
21
     * @param SerializerInterface $serializerInterface
22
     */
23
    public function __construct(HttpClientInterface $httpClient, SerializerInterface $serializerInterface)
24
    {
25
        parent::__construct($httpClient, $serializerInterface, new ApiResource('thirdparties'));
26
    }
27
28
    /**
29
     * @param ThirdpartyId $id
30
     *
31
     * @return Thirdparty
32
     *
33
     * @throws ApiException
34
     */
35
    public function getById(ThirdpartyId $id)
36
    {
37
        $response = parent::get($id->getId());
38
39
        return $this->deserialize($response, Thirdparty::class);
40
    }
41
42
    /**
43
     * @param Thirdparty $thirdparty
44
     *
45
     * @return ResourceId
46
     *
47
     * @throws ApiException
48
     */
49
    public function create(Thirdparty $thirdparty)
50
    {
51
        return new ResourceId($this->post($this->serialize($thirdparty)));
0 ignored issues
show
Bug introduced by
$this->post($this->serialize($thirdparty)) 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

51
        return new ResourceId(/** @scrutinizer ignore-type */ $this->post($this->serialize($thirdparty)));
Loading history...
52
    }
53
}
54