Test Failed
Push — master ( e928d3...36a43d )
by
unknown
02:42 queued 16s
created

FortySixElksSMS   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 8
eloc 28
c 8
b 0
f 0
dl 0
loc 96
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A whenDelivered() 0 5 1
A flash() 0 5 1
A dry() 0 5 1
A prepareParams() 0 5 1
A __construct() 0 5 1
A dontLog() 0 5 1
A send() 0 23 2
1
<?php
2
3
namespace NotificationChannels\FortySixElks;
4
5
use NotificationChannels\FortySixElks\Exceptions\CouldNotSendNotification;
6
7
class FortySixElksSMS extends FortySixElksMedia implements FortySixElksMediaInterface
8
{
9
    const ENDPOINT = 'https://api.46elks.com/a1/SMS';
10
11
    protected array $form_params;
12
13
    /**
14
     * FortySixElksSMS constructor.
15
     */
16
    public function __construct()
17
    {
18
        $this->form_params = [];
19
20
        return parent::__construct();
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::__construct() targeting NotificationChannels\For...lksMedia::__construct() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
    }
22
23
    /**
24
     * @return $this
25
     */
26
    public function send()
27
    {
28
        try {
29
            $response = $this->client->request('POST', self::ENDPOINT, [
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
30
                'form_params' => array_merge(
31
                    $this->form_params,
32
                    [
33
                        'from'    => $this->from,
34
                        'to'      => $this->phone_number,
35
                        'message' => $this->getContent(),
36
                    ]
37
                ),
38
            ]);
39
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
40
            $response = $e->getResponse();
41
42
            throw CouldNotSendNotification::serviceRespondedWithAnError(
43
                $response->getBody()->getContents(),
44
                $response->getStatusCode()
45
            );
46
        }
47
48
        return $this;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function prepareParams(string $key, mixed $value): FortySixElksSMS
55
    {
56
        $this->form_params[$key] = $value;
57
58
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type NotificationChannels\FortySixElks\FortySixElksSMS which is incompatible with the documented return type array.
Loading history...
59
    }
60
61
    /**
62
     * @return void
63
     */
64
    public function flash(string $value = 'yes'): FortySixElksSMS
65
    {
66
        self::prepareParams(key: 'flash', value: $value);
0 ignored issues
show
Bug Best Practice introduced by
The method NotificationChannels\For...lksSMS::prepareParams() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        self::/** @scrutinizer ignore-call */ 
67
              prepareParams(key: 'flash', value: $value);
Loading history...
67
68
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type NotificationChannels\FortySixElks\FortySixElksSMS which is incompatible with the documented return type void.
Loading history...
69
    }
70
71
    /**
72
     * @param string $value
73
     *
74
     * @return FortySixElksSMS
75
     */
76
    public function dry(string $value = 'yes'): FortySixElksSMS
77
    {
78
        self::prepareParams(key: 'dryrun', value: $value);
0 ignored issues
show
Bug Best Practice introduced by
The method NotificationChannels\For...lksSMS::prepareParams() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        self::/** @scrutinizer ignore-call */ 
79
              prepareParams(key: 'dryrun', value: $value);
Loading history...
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param string $url
85
     *
86
     * @return FortySixElksSMS
87
     */
88
    public function whenDelivered(string $url): FortySixElksSMS
89
    {
90
        self::prepareParams(key: 'whendelivered', value: $url);
0 ignored issues
show
Bug Best Practice introduced by
The method NotificationChannels\For...lksSMS::prepareParams() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        self::/** @scrutinizer ignore-call */ 
91
              prepareParams(key: 'whendelivered', value: $url);
Loading history...
91
92
        return $this;
93
    }
94
95
    /**
96
     * @return FortySixElksSMS
97
     */
98
    public function dontLog(): FortySixElksSMS
99
    {
100
        self::prepareParams(key: 'dontlog', value: 'message');
0 ignored issues
show
Bug Best Practice introduced by
The method NotificationChannels\For...lksSMS::prepareParams() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
        self::/** @scrutinizer ignore-call */ 
101
              prepareParams(key: 'dontlog', value: 'message');
Loading history...
101
102
        return $this;
103
    }
104
}
105