MessageBirdClient   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A triggerNotification() 0 13 2

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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Infrastructure\Notification\Client\Sms\MessageBird;
16
17
use Acme\App\Core\Port\Notification\Client\Sms\Exception\SmsNotifierException;
18
use Acme\App\Core\Port\Validation\PhoneNumber\PhoneNumberValidatorInterface;
19
use Acme\App\Infrastructure\Notification\Client\Sms\AbstractClient;
20
use libphonenumber\PhoneNumberUtil;
21
use MessageBird\Client;
22
use MessageBird\Exceptions\MessageBirdException;
23
use MessageBird\Objects\Message;
24
25
/**
26
 * @author Winfred Peereboom
27
 * @author Herberto Graca <[email protected]>
28
 */
29
final class MessageBirdClient extends AbstractClient
30
{
31
    /**
32
     * @var Client
33
     */
34
    private $client;
35
36
    /**
37
     * @var string
38
     */
39
    private $sender;
40
41 View Code Duplication
    public function __construct(
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...
42
        PhoneNumberValidatorInterface $phoneNumberValidator,
43
        PhoneNumberUtil $phoneNumberUtil,
44
        string $countryCode,
45
        Client $client,
46
        string $smsSender,
47
        string $defaultDestination = null
48
    ) {
49
        parent::__construct($phoneNumberValidator, $phoneNumberUtil, $countryCode, $defaultDestination);
50
        $this->client = $client;
51
        $this->sender = $smsSender;
52
    }
53
54
    public function triggerNotification(string $phoneNumber, string $content): void
55
    {
56
        $message = new Message();
57
        $message->originator = $this->sender;
58
        $message->recipients = [$phoneNumber];
59
        $message->body = $content;
60
61
        try {
62
            $this->client->messages->create($message);
63
        } catch (MessageBirdException $e) {
64
            throw new SmsNotifierException($e->getMessage(), 0, $e);
65
        }
66
    }
67
}
68