Passed
Pull Request — master (#24)
by Denys
30:05 queued 28:06
created

AbstractHttpClient::sendRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
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\HttpClient;
9
10
use GuzzleHttp\Client as GuzzleHttpClient;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Client 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 GuzzleHttp\ClientInterface;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\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...
12
use GuzzleHttp\HandlerStack;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\HandlerStack 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 GuzzleHttp\Middleware;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Middleware 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 GuzzleHttp\Utils;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Utils 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...
15
use Http\Promise\Promise as HttpPromise;
0 ignored issues
show
Bug introduced by
The type Http\Promise\Promise 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...
16
use Psr\Http\Message\RequestInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\RequestInterface 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...
17
use Psr\Http\Message\ResponseInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface 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...
18
use function GuzzleHttp\choose_handler;
0 ignored issues
show
introduced by
The function GuzzleHttp\choose_handler was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
19
20
abstract class AbstractHttpClient
21
{
22
    /**
23
     * @var \GuzzleHttp\ClientInterface
24
     */
25
    protected $client;
26
27
    public function __construct()
28
    {
29
        $this->client = $this->buildClient();
30
    }
31
32
    /**
33
     * @param \Psr\Http\Message\RequestInterface $request
34
     *
35
     * @return \Psr\Http\Message\ResponseInterface
36
     */
37
    public function sendRequest(RequestInterface $request): ResponseInterface
38
    {
39
        return $this->client->send($request);
40
    }
41
42
    /**
43
     * @param \Psr\Http\Message\RequestInterface $request
44
     *
45
     * @return \Http\Promise\Promise
46
     */
47
    public function sendAsyncRequest(RequestInterface $request): HttpPromise
48
    {
49
        $promise = $this->client->sendAsync($request);
50
51
        return new Promise($promise, $request);
52
    }
53
54
    /**
55
     * @return \GuzzleHttp\ClientInterface
56
     */
57
    protected function buildClient(): ClientInterface
58
    {
59
        $handlerStack = $this->createHandlerStack();
60
        $handlerStack->push(Middleware::prepareBody(), 'prepare_body');
61
62
        return new GuzzleHttpClient(['handler' => $handlerStack]);
63
    }
64
65
    /**
66
     * @return \GuzzleHttp\HandlerStack
67
     */
68
    protected function createHandlerStack(): HandlerStack
69
    {
70
        if (method_exists(Utils::class, 'chooseHandler')) {
71
            return new HandlerStack(Utils::chooseHandler());
72
        }
73
74
        return new HandlerStack(choose_handler());
0 ignored issues
show
Bug introduced by
The function choose_handler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        return new HandlerStack(/** @scrutinizer ignore-call */ choose_handler());
Loading history...
75
    }
76
}
77