Completed
Push — master ( 5a0e22...3dcaa1 )
by Thomas Mauro
02:54
created

ConnectionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 76
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptionsClass() 0 4 1
A __invoke() 0 7 1
A createService() 0 4 1
B createConnection() 0 26 1
1
<?php
2
3
namespace PamiModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use InvalidArgumentException;
7
use PAMI\Client\Impl\ClientImpl;
8
use PamiModule\Options\Connection as ConnectionOptions;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
/**
12
 * Class ConnectionFactory.
13
 */
14
class ConnectionFactory extends AbstractFactory
15
{
16
    /**
17
     * Get the class name of the options associated with this factory.
18
     *
19
     * @return string
20
     */
21 3
    public function getOptionsClass()
22
    {
23 3
        return \PamiModule\Options\Connection::class;
24
    }
25
26
    /**
27
     * @param ContainerInterface $container
28
     * @param string             $requestedName
29
     * @param array|null         $options
30
     *
31
     * @throws \RuntimeException
32
     * @throws \InvalidArgumentException
33
     *
34
     * @return ClientImpl
35
     */
36 3
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38
        /* @var $options ConnectionOptions */
39 3
        $options = $this->getOptions($container, 'connection');
40
41 3
        return $this->createConnection($options);
42
    }
43
44
    /**
45
     * Create service.
46
     *
47
     * @param ServiceLocatorInterface $serviceLocator
48
     *
49
     * @return ClientImpl
50
     */
51 1
    public function createService(ServiceLocatorInterface $serviceLocator)
52
    {
53 1
        return $this($serviceLocator, ClientImpl::class);
54
    }
55
56
    /**
57
     * @param ConnectionOptions $options
58
     *
59
     * @throws InvalidArgumentException
60
     *
61
     * @return ClientImpl
62
     */
63 3
    protected function createConnection(ConnectionOptions $options)
64
    {
65
        $clientOptions = [
66 3
            'host' => $options->getHost(),
67 3
            'port' => $options->getPort(),
68 3
            'username' => $options->getUsername(),
69 3
            'secret' => $options->getSecret(),
70 3
            'connect_timeout' => $options->getConnectTimeout(),
71 3
            'read_timeout' => $options->getReadTimeout(),
72 3
            'scheme' => $options->getScheme(),
73 3
        ];
74
75
        // Disable loggin for version <2.0
76 3
        $clientOptions['log4php.properties'] = [
77
            'rootLogger' => [
78 3
                'appenders' => ['default'],
79 3
            ],
80
            'appenders' => [
81
                'default' => [
82 3
                    'class' => 'LoggerAppenderNull',
83 3
                ],
84 3
            ],
85
        ];
86
87 3
        return new ClientImpl($clientOptions);
0 ignored issues
show
Documentation introduced by
$clientOptions is of type array<string,string|inte...\\\\\\\"}>\\\"}>\"}>"}>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
88
    }
89
}
90