Code Duplication    Length = 47-47 lines in 2 locations

src/KavenegarChannel.php 1 location

@@ 11-57 (lines=47) @@
8
use Illuminate\Notifications\Notification;
9
use NotificationChannels\Kavenegar\Exceptions\InvalidConfiguration;
10
11
class KavenegarChannel
12
{
13
    private static $API_ENDPOINT = 'https://api.kavenegar.com/v1/%s/sms/send.json';
14
15
    /** @var Client */
16
    protected $client;
17
18
    /**
19
     * @param Client $client
20
     */
21
    public function __construct(Client $client)
22
    {
23
        $this->client = $client;
24
    }
25
26
    /**
27
     * Send the given notification.
28
     *
29
     * @param mixed $notifiable
30
     * @param \Illuminate\Notifications\Notification $notification
31
     *
32
     * @throws \NotificationChannels\Kavenegar\Exceptions\InvalidConfiguration
33
     * @throws \NotificationChannels\Kavenegar\Exceptions\CouldNotSendNotification
34
     */
35
    public function send($notifiable, Notification $notification)
36
    {
37
        if (! $routing = collect($notifiable->routeNotificationFor('Kavenegar'))) {
38
            return;
39
        }
40
41
        $key = config('services.kavenegar.api_key');
42
43
        if (is_null($key)) {
44
            throw InvalidConfiguration::configurationNotSet();
45
        }
46
47
        $kavenegarParameters = $notification->toKavenegar($notifiable)->toArray();
48
49
        $response = $this->client->post(sprintf(self::$API_ENDPOINT, $key), [
50
            'form_params' => Arr::set($kavenegarParameters, 'receptor', $routing->get('mobile_number')),
51
        ]);
52
53
        if ($response->getStatusCode() !== 200) {
54
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
55
        }
56
    }
57
}
58

src/KavenegarVerifyChannel.php 1 location

@@ 11-57 (lines=47) @@
8
use Illuminate\Notifications\Notification;
9
use NotificationChannels\Kavenegar\Exceptions\InvalidConfiguration;
10
11
class KavenegarVerifyChannel
12
{
13
    private static $API_ENDPOINT = 'https://api.kavenegar.com/v1/%s/verify/lookup.json';
14
15
    /** @var Client */
16
    protected $client;
17
18
    /**
19
     * @param Client $client
20
     */
21
    public function __construct(Client $client)
22
    {
23
        $this->client = $client;
24
    }
25
26
    /**
27
     * Send the given notification.
28
     *
29
     * @param mixed $notifiable
30
     * @param \Illuminate\Notifications\Notification $notification
31
     *
32
     * @throws \NotificationChannels\Kavenegar\Exceptions\InvalidConfiguration
33
     * @throws \NotificationChannels\Kavenegar\Exceptions\CouldNotSendNotification
34
     */
35
    public function send($notifiable, Notification $notification)
36
    {
37
        if (! $routing = collect($notifiable->routeNotificationFor('Kavenegar'))) {
38
            return;
39
        }
40
41
        $key = config('services.kavenegar.api_key');
42
43
        if (is_null($key)) {
44
            throw InvalidConfiguration::configurationNotSet();
45
        }
46
47
        $kavenegarParameters = $notification->toKavenegar($notifiable)->toArray();
48
49
        $response = $this->client->post(sprintf(self::$API_ENDPOINT, $key), [
50
            'form_params' => Arr::set($kavenegarParameters, 'receptor', $routing->get('mobile_number')),
51
        ]);
52
53
        if ($response->getStatusCode() !== 200) {
54
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
55
        }
56
    }
57
}
58