Completed
Pull Request — master (#1)
by Adam
06:20 queued 03:33
created

Event   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 36.73 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 1
cbo 2
dl 18
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A acknowledge() 9 9 1
A reject() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Equip\Queue;
4
5
use Exception;
6
use League\Event\EmitterInterface;
7
8
class Event
9
{
10
    const QUEUE_ACKNOWLEDGE = 'queue.acknowledge';
11
    const QUEUE_REJECT = 'queue.reject';
12
13
    /**
14
     * @var EmitterInterface
15
     */
16
    private $emitter;
17
18
    /**
19
     * @param EmitterInterface $emitter
20
     */
21
    public function __construct(EmitterInterface $emitter)
22
    {
23
        $this->emitter = $emitter;
24
    }
25
26
    /**
27
     * Emits message acknowledgement events
28
     *
29
     * @param Message $message
30
     */
31 View Code Duplication
    public function acknowledge(Message $message)
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        array_map(function ($name) use ($message) {
34
            $this->emitter->emit($name, $message);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $message.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
35
        }, [
36
            static::QUEUE_ACKNOWLEDGE,
37
            sprintf('%s.%s', static::QUEUE_ACKNOWLEDGE, $message->handler())
38
        ]);
39
    }
40
41
    /**
42
     * Emits message rejection events
43
     *
44
     * @param Message $message
45
     * @param Exception $exception
46
     */
47 View Code Duplication
    public function reject(Message $message, Exception $exception)
0 ignored issues
show
Duplication introduced by
This method 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...
48
    {
49
        array_map(function ($name) use ($message, $exception) {
50
            $this->emitter->emit($name, $message, $exception);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $message.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
51
        }, [
52
            static::QUEUE_REJECT,
53
            sprintf('%s.%s', static::QUEUE_REJECT, $message->handler())
54
        ]);
55
    }
56
}
57