Completed
Branch master (7c4a20)
by Vincent
15:22 queued 05:09
created

Request::getBalance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 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\Body;
13
use Unirest\Request as UniRequest;
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 $headers
49
     * @param array $body
50
     */
51
    public function __construct($endpoint, array $headers = null, array $body = null)
52
    {
53
        $this->endpoint = $endpoint;
54
        $this->headers = $headers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $headers can be null. However, the property $headers 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...
55
        $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...
56
    }
57
58
    public function send()
59
    {
60
        return UniRequest::post($this->endpoint, null, Body::Json($this->body));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
    }
62
63
    public function getBalance()
64
    {
65
66
        return UniRequest::get($this->endpoint);
67
    }
68
69
70
}
71