Passed
Push — master ( 18cedb...696cbf )
by Melech
04:01
created

VonageSms   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Sms;
15
16
use Exception;
17
use Psr\Http\Client\ClientExceptionInterface;
18
use Valkyrja\Sms\Contract\Sms as Contract;
19
use Valkyrja\Sms\Data\Contract\Message;
20
use Vonage\Client as Vonage;
21
use Vonage\SMS\Message\SMS;
22
23
/**
24
 * Class VonageSms.
25
 *
26
 * @author Melech Mizrachi
27
 */
28
class VonageSms implements Contract
29
{
30
    /**
31
     * VonageSms constructor.
32
     */
33
    public function __construct(
34
        protected Vonage $vonage
35
    ) {
36
    }
37
38
    /**
39
     * @inheritDoc
40
     *
41
     * @throws Exception
42
     * @throws ClientExceptionInterface
43
     */
44
    public function send(Message $message): void
45
    {
46
        $this->vonage->sms()->send(
47
            new SMS(
48
                to: $message->getTo(),
49
                from: $message->getFrom(),
50
                message: $message->getText(),
51
                type: $message->isUnicode() ? 'unicode' : 'text',
52
            )
53
        );
54
    }
55
}
56