Completed
Push — master ( 747969...868971 )
by Vincent
02:05
created

Request::sendSMS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * BongaTech SMS Client Library for PHP.
4
 *
5
 * @copyright Copyright (c) 2017
6
 * @author   Vincent Mosoti <[email protected]>
7
 * @license https://github.com/VMosoti/bongatech-sms/blob/master/LICENSE
8
 */
9
10
namespace VMosoti\BongaTech;
11
12
use Unirest\Request as UniRequest;
13
use Unirest\Request\Body;
14
15
class Request
16
{
17
    /**
18
     * the request url.
19
     *
20
     * @var string
21
     */
22
    public $endpoint;
23
    /**
24
     * request headers.
25
     *
26
     * @var array
27
     */
28
    public $headers;
29
30
    /**
31
     * request body.
32
     *
33
     * @var array
34
     */
35
    public $body;
36
37
    /**
38
     * the response is in form of a string.
39
     *
40
     * @var array
41
     */
42
    public $response;
43
44
    /**
45
     * Request constructor.
46
     *
47
     * @param  $endpoint
48
     * @param array $body
49
     */
50
    public function __construct($endpoint, array $body = null)
51
    {
52
        $this->endpoint = $endpoint;
53
        $this->body = $body;
0 ignored issues
show
Documentation Bug introduced by
It seems like $body can be null. However, the property $body is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
54
        $this->headers = $headers = [
0 ignored issues
show
Unused Code introduced by
$headers is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
            'Accept' => 'application/json'
56
        ];
57
    }
58
59
    public function sendSMS()
60
    {
61
        return UniRequest::post($this->endpoint, $this->headers, Body::Json($this->body));
62
    }
63
64
    public function getBalance()
65
    {
66
        return UniRequest::get($this->endpoint);
67
    }
68
}
69