Completed
Pull Request — master (#1)
by Laurent
04:28
created

ProductsService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getByBarcode() 0 7 1
1
<?php
2
3
4
namespace Dolibarr\Client\Service;
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Dolibarr\Client\Domain\Common\Barcode;
8
use Dolibarr\Client\Domain\Product\Product;
9
use Dolibarr\Client\Domain\Resource\ApiResource;
10
use Dolibarr\Client\Exception\ApiException;
11
use Dolibarr\Client\HttpClient\HttpClientInterface;
12
use JMS\Serializer\SerializerInterface;
13
14
/**
15
 * @package Dolibarr\Client\Service
16
 */
17
final class ProductsService extends AbstractService
18
{
19
20
    /**
21
     * @param HttpClientInterface $httpClient
22
     * @param SerializerInterface $serializerInterface
23
     */
24
    public function __construct(HttpClientInterface $httpClient, SerializerInterface $serializerInterface)
25
    {
26
        parent::__construct($httpClient, $serializerInterface, new ApiResource('products'));
27
    }
28
29
    /**
30
     * @param Barcode $barcode
31
     *
32
     * @return ArrayCollection|Product[]
33
     *
34
     * @throws ApiException
35
     */
36
    public function getByBarcode(Barcode $barcode)
37
    {
38
        $resources = $this->getList(['query' => [
39
            'sqlfilters' => 'barcode='.$barcode->barcode()
40
        ]]);
41
42
        return $this->deserializeCollection($resources, Product::class);
43
    }
44
}
45