Subscriber::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 1
nop 10

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 Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\DomainEvent;
4
5
use Cmp\Queues\Domain\Event\JSONDomainEventFactory;
6
use Cmp\Queues\Domain\Event\Subscriber as DomainSubscriber;
7
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\BindConfig;
8
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\ConsumeConfig;
9
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\ExchangeConfig;
10
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\Config\QueueConfig;
11
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\MessageHandler;
12
use Cmp\Queues\Infrastructure\AmqpLib\v26\RabbitMQ\Queue\QueueReader;
13
use PhpAmqpLib\Connection\AMQPLazyConnection;
14
use Psr\Log\LoggerInterface;
15
16 View Code Duplication
class Subscriber extends DomainSubscriber
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @param string                 $host
20
     * @param int                    $port
21
     * @param string                 $user
22
     * @param string                 $password
23
     * @param string                 $vHost
24
     * @param string                 $exchangeName
25
     * @param string                 $queueName
26
     * @param BindConfig             $bindConfig
27
     * @param LoggerInterface        $logger
28
     * @param JSONDomainEventFactory $factory
29
     */
30
    public function __construct(
31
        $host,
32
        $port,
33
        $user,
34
        $password,
35
        $vHost,
36
        $exchangeName,
37
        $queueName,
38
        BindConfig $bindConfig,
39
        LoggerInterface $logger,
40
        JSONDomainEventFactory $factory = null
41
    ) {
42
        $queueReader = new QueueReader(
43
            new AMQPLazyConnection($host, $port, $user, $password, $vHost),
44
            new QueueConfig($queueName, false, true, false, false),
45
            new ExchangeConfig($exchangeName, 'topic', false, true, false),
46
            $bindConfig,
47
            new ConsumeConfig(false, false, false, false),
48
            new MessageHandler($factory ?: new JSONDomainEventFactory()),
49
            $logger
50
        );
51
        parent::__construct($queueReader, $logger);
52
    }
53
}
54