Completed
Pull Request — master (#3)
by Alessandro
04:40
created

Factory::createPublisher()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
ccs 10
cts 11
cp 0.9091
rs 8.8571
c 1
b 0
f 0
cc 3
eloc 15
nc 4
nop 8
crap 3.0067

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 1
    public function createPublisher($protocol, $host, $port, $path, $key, $secret, $hostname, $ignoreSsl)
25
    {
26 1
        $config = array();
27
28 1
        $config['base_url'] = sprintf(
29 1
            '%s://%s:%s%s',
30
            $protocol,
31
            $host,
32
            $port,
33
            $path
34
        );
35
36 1
        $config['defaults']['headers']['Content-Type'] = 'application/json';
37
38 1
        if (null !== $hostname) {
39
            $config['defaults']['headers']['Host'] = $hostname;
40
        }
41
42 1
        if ($ignoreSsl) {
43 1
            $config['defaults']['verify'] = false;
44
        }
45
46 1
        $guzzleClient = new GuzzleClient($config);
47
48 1
        return new Publisher($guzzleClient, $key, $secret);
49
    }
50
}
51