GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Request   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 22 7
A account() 0 4 2
1
<?php
2
3
namespace Goodoneuz\PayUz\Http\Classes\Payme;
4
5
class Request
6
{
7
    /** @var array decoded request payload */
8
    public $payload;
9
10
    /** @var int id of the request */
11
    public $id;
12
13
    /** @var string method name, such as <em>CreateTransaction</em> */
14
    public $method;
15
16
    /** @var array request parameters, such as <em>amount</em>, <em>account</em> */
17
    public $params;
18
19
    /** @var int amount value in coins */
20
    public $amount;
21
22
    public $response;
23
    /**
24
     * Request constructor.
25
     * Parses request payload and populates properties with values.
26
     */
27
    public function __construct($response)
28
    {
29
        $this->response = $response;
30
        $request_body  = file_get_contents('php://input');
31
32
        if(env('APP_ENV') == 'testing')
33
            $request_body = request()->all()['request'];
34
    
35
        $this->payload = json_decode($request_body, true);
36
        if (!$this->payload) {
37
            $this->response->error(Response::ERROR_INVALID_JSON_RPC_OBJECT,'Invalid JSON-RPC object.');
38
        }
39
40
        // populate request object with data
41
        $this->id     = isset($this->payload['id']) ? 1 * $this->payload['id'] : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($this->payload['id...s->payload['id'] : null can also be of type double. However, the property $id is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
42
        $this->method = isset($this->payload['method']) ? trim($this->payload['method']) : null;
43
        $this->params = isset($this->payload['params']) ? $this->payload['params'] : [];
44
        $this->amount = isset($this->payload['params']['amount']) ? 1 * $this->payload['params']['amount'] : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($this->payload['pa...rams']['amount'] : null can also be of type double. However, the property $amount is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
45
46
        // add request id into params too
47
        $this->params['request_id'] = $this->id;
48
    }
49
50
    public function account($param)
51
    {
52
        return isset($this->params['account'], $this->params['account'][$param]) ? $this->params['account'][$param] : null;
53
    }
54
55
}
56