Passed
Push — bugfix/supesc-331-adjusted-the... ( a6d65b...656fd3 )
by Ihor
04:07
created

AkeneoPimSdkDirector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createAkeneoPimClient() 0 16 1
A __construct() 0 6 1
1
<?php
2
3
namespace AkeneoPim\Dependencies\External\Api\Adapter\Sdk;
4
5
use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
6
use SprykerEco\Service\AkeneoPim\AkeneoPimConfig;
7
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Sdk\AkeneoPimSdkDirectorInterface;
8
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Sdk\AkeneoPimSdkFactoryInterface;
9
use Symfony\Component\HttpFoundation\Session\SessionInterface;
10
11
class AkeneoPimSdkDirector implements AkeneoPimSdkDirectorInterface
12
{
13
    /**
14
     * @var \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Sdk\AkeneoPimSdkFactoryInterface
15
     */
16
    protected $akeneoPimSdkFactory;
17
18
    /**
19
     * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
20
     */
21
    private SessionInterface $session;
22
23
    public function __construct(
24
        AkeneoPimSdkFactoryInterface $akeneoPimSdkFactory,
25
        SessionInterface $session
26
    ) {
27
        $this->akeneoPimSdkFactory = $akeneoPimSdkFactory;
28
        $this->session = $session;
29
    }
30
31
    /**
32
     * @param \SprykerEco\Service\AkeneoPim\AkeneoPimConfig $config
33
     *
34
     * @return \Akeneo\Pim\ApiClient\AkeneoPimClientInterface
35
     */
36
    public function createAkeneoPimClient(AkeneoPimConfig $config): AkeneoPimClientInterface
37
    {
38
        $akeneoPimClientBuilder = $this->akeneoPimSdkFactory->createAkeneoPimClientBuilder($config->getHost());
39
40
        $akeneoPimClientBuilder->setHttpClient(
41
            $this->akeneoPimSdkFactory->createHttpClient()
42
        );
43
44
        $akeneoPimClient = $akeneoPimClientBuilder->buildAuthenticatedByPassword(
45
            $config->getClientId(),
46
            $config->getClientSecret(),
47
            $config->getUsername(),
48
            $config->getPassword()
49
        );
50
51
        return $akeneoPimClient;
52
    }
53
}
54