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

VonageSms::send()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 1
nop 1
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