Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 18
c 5
b 1
f 0
dl 0
loc 43
ccs 15
cts 16
cp 0.9375
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A createPublisher() 0 38 4
1
<?php
2
3
namespace Facile\CrossbarHTTPPublisherBundle\Publisher;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
7
/**
8
 * Class Factory
9
 * @package Facile\CrossbarHTTPPublisherBundle\Publisher
10
 */
11
class Factory
12
{
13
    /**
14
     * @param bool|string $hostname
15
     */
16
    public function createPublisher(
17
        string $protocol,
18
        string $host,
19
        int $port,
20
        string $path,
21
        ?string $key,
22
        ?string $secret,
23
        $hostname,
24 3
        bool $ignoreSsl = false
25
    ): Publisher {
26 3
        $config = [];
27
28 3
        $config['base_url'] = sprintf(
29 3
            '%s://%s:%s%s',
30 3
            $protocol,
31 3
            $host,
32 3
            $port,
33 3
            $path
34
        );
35 3
        $config['base_uri'] = $config['base_url']; // Guzzle 6 compat
36
37 3
        $config['headers']['Content-Type'] = 'application/json';
38
39 3
        if (null !== $hostname) {
0 ignored issues
show
introduced by
The condition null !== $hostname is always true.
Loading history...
40
            $config['headers']['Host'] = $hostname;
41
        }
42
43 3
        if ($ignoreSsl) {
44 3
            $config['verify'] = false;
45
        }
46
47 3
        if (defined('GuzzleHttp\ClientInterface::VERSION')) {
48
            @trigger_error('Guzzle versions before 7 are deprecated.', E_USER_DEPRECATED);
49 3
        }
50
51
        $guzzleClient = new GuzzleClient($config);
52
53
        return new Publisher($guzzleClient, $key, $secret);
54
    }
55
}
56