Code Duplication    Length = 63-67 lines in 3 locations

src/Drivers/Farazsms.php 1 location

@@ 8-74 (lines=67) @@
5
use Tzsk\Sms\Abstracts\Driver;
6
use \SoapClient;
7
8
class Farazsms extends Driver
9
{
10
    /**
11
     * Tsms Settings.
12
     *
13
     * @var null|object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Smsir Client.
19
     *
20
     * @var null|SoapClient
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * @param $settings
28
     * @throws \SoapFault
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client();
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return object
40
     * @throws \GuzzleHttp\Exception\GuzzleException
41
     */
42
    public function send()
43
    {
44
        $response = collect();
45
46
        foreach ($this->recipients as $recipient) {
47
            $result = $this->client->request(
48
                'POST',
49
                $this->settings->url,
50
                $this->payload($recipient)
51
            );
52
            $response->put($recipient, json_decode($result));
53
        }
54
55
        return (count($this->recipients) == 1) ? $response->first() : $response;
56
    }
57
58
    /**
59
     * @param string $recipient
60
     * @param string $token
61
     * @return array
62
     */
63
    protected function payload($recipient)
64
    {
65
        return [
66
            'uname' => $this->settings->username,
67
            'pass' => $this->settings->password,
68
            'from' => $this->settings->from,
69
            'message' => $this->body,
70
            'to' => json_encode([$recipient]),
71
            'op'=>'send'
72
        ];
73
    }
74
}
75

src/Drivers/Linkmobility.php 1 location

@@ 8-70 (lines=63) @@
5
use GuzzleHttp\Client;
6
use Tzsk\Sms\Abstracts\Driver;
7
8
class Linkmobility extends Driver
9
{
10
    /**
11
     * Linkmobility Settings.
12
     *
13
     * @var object|null
14
     */
15
    protected $settings;
16
17
    /**
18
     * Http Client.
19
     *
20
     * @var Client|null
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * SendSmsInterface constructor.
28
     * @param array $settings
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client();
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return mixed
40
     */
41
    public function send()
42
    {
43
        $response = collect();
44
        foreach ($this->recipients as $recipient) {
45
            $response->put(
46
                $recipient,
47
                $this->client->request('POST', $this->settings->url, $this->payload($recipient))
48
            );
49
        }
50
51
        return (count($this->recipients) == 1) ? $response->first() : $response;
52
    }
53
54
    /**
55
     * @param string $recipient
56
     * @return array
57
     */
58
    protected function payload($recipient)
59
    {
60
        return [
61
            'form_params' => [
62
                'USER' => $this->settings->username,
63
                'PW' => $this->settings->password,
64
                'RCV' => $recipient,
65
                'SND' => urlencode($this->settings->sender),
66
                'TXT' => $this->body,
67
            ],
68
        ];
69
    }
70
}
71

src/Drivers/Textlocal.php 1 location

@@ 8-70 (lines=63) @@
5
use GuzzleHttp\Client;
6
use Tzsk\Sms\Abstracts\Driver;
7
8
class Textlocal extends Driver
9
{
10
    /**
11
     * Textlocal Settings.
12
     *
13
     * @var object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Http Client.
19
     *
20
     * @var Client
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * SendSmsInterface constructor.
28
     * @param array $settings
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new Client();
34
    }
35
36
    /**
37
     * Send text message and return response.
38
     *
39
     * @return mixed
40
     */
41
    public function send()
42
    {
43
        $response = collect();
44
        foreach ($this->recipients as $recipient) {
45
            $response->put(
46
                $recipient,
47
                $this->client->request('POST', $this->settings->url, $this->payload($recipient))
48
            );
49
        }
50
51
        return (count($this->recipients) == 1) ? $response->first() : $response;
52
    }
53
54
    /**
55
     * @param string $recipient
56
     * @return array
57
     */
58
    public function payload($recipient)
59
    {
60
        return [
61
            'form_params' => [
62
                'username' => $this->settings->username,
63
                'hash' => $this->settings->hash,
64
                'numbers' => $recipient,
65
                'sender' => urlencode($this->settings->sender),
66
                'message' => $this->body,
67
            ],
68
        ];
69
    }
70
}
71