ASTalking   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A to() 0 9 3
A message() 0 6 1
A send() 0 9 1
1
<?php
2
3
namespace Ngeno7\ASTalking;
4
5
use AfricasTalking\SDK\AfricasTalking;
6
7
class ASTalking
8
{
9
    // Build your next great package.
10
11
    protected $sms;
12
13
    protected $pNumbers = '';
14
15
    protected $msg = '';
16
17
    public function __construct($username, $key)
18
    {
19
        $AT = new AfricasTalking($username, $key);
20
        
21
        $this->sms = $AT->sms();
22
    }
23
24
    public function to(array $pNumbers): ASTalking 
25
    {
26
        $numbers = array_filter(array_map(function($pNumber) { return trim($pNumber); }, $pNumbers),
27
         function($pNumber) { return strlen($pNumber) == 12 || strlen($pNumber) == 13 ? true : false; });
28
29
        $this->pNumbers = implode(',', $numbers);
30
 
31
         return $this;
32
    }
33
34
    public function message(string $message): ASTalking
35
    {
36
        $this->msg = $message;
37
38
        return $this;
39
    }
40
41
    public function send()
42
    {
43
        $this->sms->send([
44
            'to' => $this->pNumbers,
45
            'message' => $this->msg,
46
            'from' => config('astalking.sender_id'),
47
            'enqueue' => config('astalking.enqueue')
48
        ]);
49
    }
50
}
51