Completed
Push — master ( 31766b...0b1c96 )
by
unknown
21s queued 13s
created

AkeneoPimSdkFactory::getHttpClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\Sdk;
9
10
use Akeneo\Pim\ApiClient\AkeneoPimClientBuilder;
0 ignored issues
show
Bug introduced by
The type Akeneo\Pim\ApiClient\AkeneoPimClientBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
0 ignored issues
show
Bug introduced by
The type Akeneo\Pim\ApiClient\AkeneoPimClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Akeneo\Pim\ApiClient\Client\ClientInterface as AkeneoClientInterface;
0 ignored issues
show
Bug introduced by
The type Akeneo\Pim\ApiClient\Client\ClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Psr\Http\Client\ClientInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Client\ClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use SprykerEco\Service\AkeneoPim\AkeneoPimConfig;
15
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient\AkeneoHttpClient;
16
use SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient\Client;
17
18
class AkeneoPimSdkFactory implements AkeneoPimSdkFactoryInterface
19
{
20
    /**
21
     * @param \SprykerEco\Service\AkeneoPim\AkeneoPimConfig $config
22
     *
23
     * @return \Akeneo\Pim\ApiClient\AkeneoPimClientInterface
24
     */
25
    public function createAkeneoPimClient(AkeneoPimConfig $config): AkeneoPimClientInterface
26
    {
27
        $clientBuilder = new AkeneoPimClientBuilder($config->getHost());
28
        $clientBuilder->setHttpClient($this->getHttpClient());
29
30
        return $clientBuilder->buildAuthenticatedByPassword(
31
            $config->getClientId(),
32
            $config->getClientSecret(),
33
            $config->getUsername(),
34
            $config->getPassword(),
35
        );
36
    }
37
38
    /**
39
     * @return \Psr\Http\Client\ClientInterface
40
     */
41
    public function createHttpClient(): ClientInterface
42
    {
43
        return new Client();
44
    }
45
46
    /**
47
     * @return \Akeneo\Pim\ApiClient\Client\ClientInterface
48
     */
49
    public function createAkeneoHttpClient(): AkeneoClientInterface
50
    {
51
        return new AkeneoHttpClient();
52
    }
53
54
    /**
55
     * @return \Akeneo\Pim\ApiClient\Client\ClientInterface|\Psr\Http\Client\ClientInterface
56
     */
57
    public function getHttpClient()
58
    {
59
        if (interface_exists('\Akeneo\Pim\ApiClient\Client\ClientInterface')) {
60
            return $this->createAkeneoHttpClient();
61
        }
62
63
        return $this->createHttpClient();
64
    }
65
}
66