ServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 19 2
1
<?php
2
3
namespace Eole\Sandstone\Push\Bridge\ZMQ;
4
5
use ZMQ;
6
use ZMQContext;
7
use Pimple\ServiceProviderInterface;
8
use Pimple\Container;
9
use Eole\Sandstone\Push\Debug\TraceablePushServer;
10
11
class ServiceProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * {@InheritDoc}
15
     */
16
    public function register(Container $app)
17
    {
18
        $app['sandstone.push'] = function () use ($app) {
19
            $pushServerHost = $app['sandstone.push.server']['host'];
20
            $pushServerPort = $app['sandstone.push.server']['port'];
21
22
            $context = new ZMQContext();
23
            $socket = $context->getSocket(ZMQ::SOCKET_PUSH);
24
            $socket->connect("tcp://$pushServerHost:$pushServerPort");
25
26
            $pushServer = new ZMQPushServer($socket);
0 ignored issues
show
Bug introduced by
It seems like $socket defined by $context->getSocket(\ZMQ::SOCKET_PUSH) on line 23 can be null; however, Eole\Sandstone\Push\Brid...shServer::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
27
28
            if ($app['debug']) {
29
                $pushServer = new TraceablePushServer($pushServer);
30
            }
31
32
            return $pushServer;
33
        };
34
    }
35
}
36