Test Failed
Pull Request — master (#21)
by
unknown
05:32
created

FortySixElksSMS   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 8
eloc 27
c 6
b 0
f 0
dl 0
loc 94
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A whenDelivered() 0 5 1
A send() 0 23 2
A flash() 0 5 1
A dry() 0 5 1
A prepareParams() 0 5 1
A dontLog() 0 5 1
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
        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...
19
    }
20
21
    /**
22
     * @return $this
23
     */
24
    public function send()
25
    {
26
        try {
27
            $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...
28
                'form_params' => array_merge(
29
                    $this->form_params,
30
                    [
31
                        'from'          => $this->from,
32
                        'to'            => $this->phone_number,
33
                        'message'       => $this->getContent(),
34
                    ]
35
                ),
36
            ]);
37
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
38
            $response = $e->getResponse();
39
40
            throw CouldNotSendNotification::serviceRespondedWithAnError(
41
                $response->getBody()->getContents(),
42
                $response->getStatusCode()
43
            );
44
        }
45
46
        return $this;
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function prepareParams(string $key, mixed $value): FortySixElksSMS
53
    {
54
        $this->form_params[$key] = $value;
55
56
        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...
57
    }
58
59
    /**
60
     * @return void
61
     */
62
    public function flash(string $value = 'yes'): FortySixElksSMS
63
    {
64
        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

64
        self::/** @scrutinizer ignore-call */ 
65
              prepareParams(key: 'flash', value: $value);
Loading history...
65
66
        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...
67
    }
68
69
    /**
70
     * @param string $value
71
     *
72
     * @return FortySixElksSMS
73
     */
74
    public function dry(string $value = 'yes'): FortySixElksSMS
75
    {
76
        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

76
        self::/** @scrutinizer ignore-call */ 
77
              prepareParams(key: 'dryrun', value: $value);
Loading history...
77
78
        return $this;
79
    }
80
81
    /**
82
     * @param string $url
83
     *
84
     * @return FortySixElksSMS
85
     */
86
    public function whenDelivered(string $url): FortySixElksSMS
87
    {
88
        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

88
        self::/** @scrutinizer ignore-call */ 
89
              prepareParams(key: 'whendelivered', value: $url);
Loading history...
89
90
        return $this;
91
    }
92
93
    /**
94
     * @return FortySixElksSMS
95
     */
96
    public function dontLog(): FortySixElksSMS
97
    {
98
        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

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