Passed
Push — master ( 645444...70cdd5 )
by
unknown
05:22 queued 10s
created

FortySixElksMedia::to()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace NotificationChannels\FortySixElks;
4
5
use GuzzleHttp\Client;
6
use NotificationChannels\FortySixElks\Exceptions\MissingConfigNotification;
7
8
class FortySixElksMedia
9
{
10
    /**
11
     * @var string
12
     */
13
    const ENDPOINT = null;
14
    /**
15
     * @var array
16
     */
17
    protected $payload = [
18
        'lines'   => [],
19
        'subject' => '',
20
    ];
21
22
    /**
23
     * @var int
24
     */
25
    protected $phone_number;
26
    /**
27
     * @var string
28
     */
29
    protected $from;
30
31
    /**
32
     * @var string
33
     */
34
    protected $username;
35
    /**
36
     * @var string
37
     */
38
    protected $password;
39
40
    /**
41
     * FortySixElksMedia constructor.
42
     */
43
    public function __construct()
44
    {
45
        $this->username = config('services.46elks.username');
46
        $this->password = config('services.46elks.password');
47
        if (!$this->username || !$this->password) {
48
            throw MissingConfigNotification::missingConfig();
49
        }
50
51
        $this->client = new Client(
0 ignored issues
show
Bug Best Practice introduced by
The property client does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
            [
53
                'headers' => [
54
                    'Content-Type' => 'application/x-www-urlencoded',
55
                ],
56
                'auth'    => [
57
                    $this->username,
58
                    $this->password,
59
                ],
60
            ]
61
        );
62
    }
63
64
    /**
65
     * @param $line
66
     *
67
     * @return $this
68
     */
69
    public function line($line)
70
    {
71
        $this->payload['lines'][] = $line;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @param $subject
78
     *
79
     * @return $this
80
     */
81
    public function subject($subject)
82
    {
83
        $this->payload['subject'] = $subject;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @param $phone_number
90
     *
91
     * @return $this
92
     */
93
    public function to($phoneNumber)
94
    {
95
        $this->phone_number = $phoneNumber;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @param $string
102
     *
103
     * @return $this
104
     */
105
    public function from($string)
106
    {
107
        $this->from = $string;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getContent()
116
    {
117
        return implode(PHP_EOL, $this->payload['lines']);
118
    }
119
120
    /**
121
     * @return mixed
122
     */
123
    public function getSubject()
124
    {
125
        return $this->payload['subject'];
126
    }
127
}
128