Completed
Push — master ( e7a3c7...2372b5 )
by dan
02:03
created

LoggerMessageAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 12
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 12 12 1
A dispatch() 0 10 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 IrishDan\NotificationBundle\Adapter;
4
5
use IrishDan\NotificationBundle\Message\MessageInterface;
6
use IrishDan\NotificationBundle\Notification\NotificationInterface;
7
use Psr\Log\LoggerInterface;
8
9
class LoggerMessageAdapter extends BaseMessageAdapter implements MessageAdapterInterface
10
{
11
    protected $logger;
12
13
    public function __construct(LoggerInterface $logger)
14
    {
15
        $this->logger = $logger;
16
    }
17
18
    /**
19
     * Generates a message object
20
     *
21
     * @param NotificationInterface $notification
22
     * @return \IrishDan\NotificationBundle\Message\Message
23
     */
24 View Code Duplication
    public function format(NotificationInterface $notification)
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...
25
    {
26
        parent::format($notification);
27
28
        $dispatchData = [
29
            'type' => 'info',
30
        ];
31
32
        $messageData = self::createMessagaData($notification->getDataArray());
33
34
        return self::createMessage($dispatchData, $messageData, $this->channelName);
35
    }
36
37
    public function dispatch(MessageInterface $message)
38
    {
39
        // Get the dispatch and message data from the message.
40
        $dispatchData = $message->getDispatchData();
41
        $messageData = $message->getMessageData();
42
43
        $this->logger->{$dispatchData['type']}($messageData['body']);
44
45
        return true;
46
    }
47
}