Subscriber::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 1
nop 5
1
<?php
2
3
namespace Cmp\Queues\Infrastructure\AWS\v20121105\DomainEvent;
4
5
use Aws\Sqs\SqsClient;
6
use Cmp\Queues\Domain\Event\JSONDomainEventFactory;
7
use Cmp\Queues\Domain\Event\Subscriber as DomainSubscriber;
8
use Cmp\Queues\Infrastructure\AWS\v20121105\Queue\MessageHandler;
9
use Cmp\Queues\Infrastructure\AWS\v20121105\Queue\QueueReader;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\NullLogger;
12
13
class Subscriber extends DomainSubscriber
14
{
15
    /**
16
     * @param string                 $region
17
     * @param string                 $queueUrl
18
     * @param LoggerInterface        $logger
19
     * @param JSONDomainEventFactory $factory
20
     * @param int                    $messagesToRead
21
     */
22
    public function __construct(
23
        $region,
24
        $queueUrl,
25
        LoggerInterface $logger = null,
26
        JSONDomainEventFactory $factory = null,
27
        $messagesToRead = 10
28
    ) {
29
        $queueReader = new QueueReader(
30
            SqsClient::factory(['region' => $region, 'version' => '2012-11-05']),
0 ignored issues
show
Deprecated Code introduced by
The method Aws\AwsClient::factory() has been deprecated.

This method has been deprecated.

Loading history...
31
            $queueUrl,
32
            $messagesToRead,
33
            new MessageHandler($factory ?: new JSONDomainEventFactory()),
34
            $logger ?: new NullLogger()
35
        );
36
        parent::__construct($queueReader, $logger);
0 ignored issues
show
Bug introduced by
It seems like $logger defined by parameter $logger on line 25 can be null; however, Cmp\Queues\Domain\Event\Subscriber::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
37
    }
38
}
39