Passed
Pull Request — master (#11)
by Oleksandr
04:55
created

AssetApiAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 65
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A all() 0 8 1
A listPerPage() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Asset;
9
10
use Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface;
11
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\ApiAdapterInterface;
12
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\AkeneoResourceCursorInterface;
13
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\AkeneoResourcePageInterface;
14
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\WrapperFactoryInterface;
15
16
class AssetApiAdapter implements ApiAdapterInterface
17
{
18
    /**
19
     * @var \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface
20
     */
21
    protected $akeneoPimClient;
22
23
    /**
24
     * @var \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\WrapperFactoryInterface
25
     */
26
    protected $wrapperFactory;
27
28
    /**
29
     * @param \Akeneo\PimEnterprise\ApiClient\AkeneoPimEnterpriseClientInterface $akeneoPimClient
30
     * @param \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\WrapperFactoryInterface $wrapperFactory
31
     */
32
    public function __construct(AkeneoPimEnterpriseClientInterface $akeneoPimClient, WrapperFactoryInterface $wrapperFactory)
33
    {
34
        $this->akeneoPimClient = $akeneoPimClient;
35
        $this->wrapperFactory = $wrapperFactory;
36
    }
37
38
    /**
39
     * @param string $code
40
     *
41
     * @return array
42
     */
43
    public function get($code): array
44
    {
45
        return $this->akeneoPimClient
46
            ->getAssetApi()
47
            ->get($code);
48
    }
49
50
    /**
51
     * @param int $limit
52
     * @param bool $withCount
53
     * @param array $queryParameters
54
     *
55
     * @return \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\AkeneoResourcePageInterface
56
     */
57
    public function listPerPage($limit = 10, $withCount = false, array $queryParameters = []): AkeneoResourcePageInterface
58
    {
59
        $page = $this->akeneoPimClient
60
            ->getAssetApi()
61
            ->listPerPage($limit, $withCount, $queryParameters);
62
63
        return $this->wrapperFactory
64
            ->createAkeneoPage($page);
65
    }
66
67
    /**
68
     * @param int $pageSize
69
     * @param array $queryParameters
70
     *
71
     * @return \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\AkeneoResourceCursorInterface
72
     */
73
    public function all($pageSize = 10, array $queryParameters = []): AkeneoResourceCursorInterface
74
    {
75
        $resourceCursor = $this->akeneoPimClient
76
            ->getAssetApi()
77
            ->all($pageSize, $queryParameters);
78
79
        return $this->wrapperFactory
80
            ->createAkeneoResourceCursor($resourceCursor);
81
    }
82
}
83