Test Failed
Pull Request — master (#20)
by
unknown
08:08
created

FortySixElksSMS::prepareParams()   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 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
        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
            ]);
38
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
39
            $response = $e->getResponse();
40
41
            throw CouldNotSendNotification::serviceRespondedWithAnError(
42
                $response->getBody()->getContents(),
43
                $response->getStatusCode()
44
            );
45
        }
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function prepareParams(string $key, mixed $value): FortySixElksSMS
54
    {
55
        $this->form_params[$key] = $value;
56
57
        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...
58
    }
59
60
    /**
61
     * @return void
62
     */
63
    public function flash(string $value = 'yes'): FortySixElksSMS
64
    {
65
        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

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

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

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

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