GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GuzzleClientFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 17
cts 17
cp 1
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 1
crap 2
1
<?php
2
3
namespace WebservicesNl\Protocol\Soap\Helper;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\MessageFormatter;
8
use GuzzleHttp\Middleware;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\LoggerInterface;
11
use WebservicesNl\Platform\PlatformConfigInterface;
12
13
/**
14
 * HttpClientFactory.
15
 *
16
 * Helper class the Webservices connector generator with instantiating a PSR-7 curl client.
17
 */
18
class GuzzleClientFactory
19
{
20
    use LoggerAwareTrait;
21
22
    /**
23
     * @var PlatformConfigInterface
24
     */
25
    private $platform;
26
27
    /**
28
     * HttpClientFactory constructor.
29
     *
30
     * @param PlatformConfigInterface $platform
31
     */
32 7
    public function __construct(PlatformConfigInterface $platform)
33
    {
34 7
        $this->platform = $platform;
35 7
    }
36
37
    /**
38
     * Create a static instance (LSB) of HttpClientFactory.
39
     *
40
     * @param PlatformConfigInterface $platform
41
     *
42
     * @return GuzzleClientFactory
43
     */
44 7
    public static function build(PlatformConfigInterface $platform)
45
    {
46 7
        return new static($platform);
47
    }
48
49
    /**
50
     * Create and configure a http curl client.
51
     *
52
     * @param array $settings additional settings
53
     *
54
     * @return Client
55
     */
56 7
    public function create(array $settings = [])
57
    {
58 7
        $stack = null;
59 7
        $settings += $this->platform->toArray();
60
61 7
        if ($this->getLogger() instanceof LoggerInterface) {
62 3
            $stack = HandlerStack::create();
63 3
            $stack->push(Middleware::log($this->getLogger(), new MessageFormatter('{request} - {response}')));
64 3
        }
65
66 7
        return new Client(
67
            [
68 7
                'base_url'           => (string)$settings['url'],
69 7
                'handler'            => $stack,
70 7
                'exceptions'         => false,
71 7
                'timeout'            => (float)$settings['responseTimeout'],
72 7
                'connection_timeout' => (float)$settings['connectionTimeout'],
73
                'headers' => [
74 7
                    'User-Agent' => $settings['userAgent']
75 7
                ]
76 7
            ]
77 7
        );
78
    }
79
80
    /**
81
     * Returns this LoggerInterface.
82
     *
83
     * @return LoggerInterface
84
     */
85 7
    public function getLogger()
86
    {
87 7
        return $this->logger;
88
    }
89
}
90