Completed
Push — master ( bc4620...2ff3a6 )
by Alessandro
13s queued 12s
created

Factory::createPublisher()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3.0021

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 15
cts 16
cp 0.9375
rs 9.488
c 0
b 0
f 0
cc 3
nc 4
nop 8
crap 3.0021

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 string $protocol
15
     * @param string $host
16
     * @param int $port
17
     * @param string $path
18
     * @param string $key
19
     * @param string $secret
20
     * @param bool|string $hostname
21
     * @param bool $ignoreSsl
22
     * @return Publisher
23
     */
24 3
    public function createPublisher($protocol, $host, $port, $path, $key, $secret, $hostname, $ignoreSsl)
25
    {
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) {
40
            $config['headers']['Host'] = $hostname;
41
        }
42
43 3
        if ($ignoreSsl) {
44 3
            $config['verify'] = false;
45
        }
46
47 3
        $guzzleClient = new GuzzleClient($config);
48
49 3
        return new Publisher($guzzleClient, $key, $secret);
50
    }
51
}
52