Completed
Pull Request — master (#9)
by Adam
05:10 queued 02:21
created

Event::shutdown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Equip\Queue;
4
5
use Equip\Command\OptionsInterface;
6
use Exception;
7
use League\Event\EmitterInterface;
8
use Psr\Log\LoggerInterface;
9
10
class Event
11
{
12
    const MESSAGE_ACKNOWLEDGE = 'message.acknowledge';
13
    const MESSAGE_FINISH = 'message.finish';
14
    const MESSAGE_REJECT = 'message.reject';
15
    const QUEUE_SHUTDOWN = 'queue.shutdown';
16
17
    /**
18
     * @var EmitterInterface
19
     */
20
    private $emitter;
21
22
    /**
23
     * @var LoggerInterface
24
     */
25
    protected $logger;
26
27
    /**
28
     * @param EmitterInterface $emitter
29
     * @param LoggerInterface $logger
30
     */
31 4
    public function __construct(EmitterInterface $emitter, LoggerInterface $logger)
32
    {
33 4
        $this->emitter = $emitter;
34 4
        $this->logger = $logger;
35 4
    }
36
37
    /**
38
     * Emits message acknowledgement events
39
     *
40
     * @param string $command
41
     * @param OptionsInterface $options
42
     */
43 1 View Code Duplication
    public function acknowledge($command, OptionsInterface $options)
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...
44
    {
45
        array_map(function ($name) use ($options) {
46 1
            $this->emitter->emit($name, $options);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $options.

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...
47 1
        }, [
48 1
            static::MESSAGE_ACKNOWLEDGE,
49 1
            sprintf('%s.%s', static::MESSAGE_ACKNOWLEDGE, $command)
50
        ]);
51
52 1
        $this->logger->info(sprintf('`%s` job started', $command));
53 1
    }
54
55
    /**
56
     * Emits message finished events
57
     *
58
     * @param string $command
59
     * @param OptionsInterface $options
60
     */
61 1 View Code Duplication
    public function finish($command, OptionsInterface $options)
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...
62
    {
63
        array_map(function ($name) use ($options) {
64 1
           $this->emitter->emit($name, $options) ;
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $options.

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...
65 1
        }, [
66 1
            static::MESSAGE_FINISH,
67 1
            sprintf('%s.%s', static::MESSAGE_FINISH, $command)
68
        ]);
69
70 1
        $this->logger->info(sprintf('`%s` job finished', $command));
71 1
    }
72
73
    /**
74
     * Emits message rejection events
75
     *
76
     * @param string $command
77
     * @param OptionsInterface $options
78
     * @param Exception $exception
79
     */
80 1 View Code Duplication
    public function reject($command, OptionsInterface $options, 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...
81
    {
82
        array_map(function ($name) use ($options, $exception) {
83 1
            $this->emitter->emit($name, $options, $exception);
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with $options.

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...
84 1
        }, [
85 1
            static::MESSAGE_REJECT,
86 1
            sprintf('%s.%s', static::MESSAGE_REJECT, $command)
87
        ]);
88
89 1
        $this->logger->error($exception->getMessage());
90 1
    }
91
92
    /**
93
     * Emits message shutdown events
94
     *
95
     * @param string $command
96
     */
97 View Code Duplication
    public function shutdown($command)
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...
98
    {
99 1
        array_map(function ($name) {
100 1
            $this->emitter->emit($name) ;
101 1
        }, [
102 1
            static::QUEUE_SHUTDOWN,
103 1
            sprintf('%s.%s', static::QUEUE_SHUTDOWN, $command)
104
        ]);
105
106 1
        $this->logger->notice(sprintf('shutting down by request of `%s`', $command));
107 1
    }
108
}
109