irishdan /
NotificationBundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 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 | } |
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.