Completed
Push — master ( 38a4e8...c04e1d )
by Vladimir
11s
created

Transaction::hasInvoice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay\Paymarket\Resources;
6
7
class Transaction extends AbstractResource
8
{
9
    /** @var int */
10
    public $id;
11
12
    /** @var int */
13
    public $merchantId;
14
15
    /** @var int */
16
    public $serviceId;
17
18
    /** @var string */
19
    public $externalId;
20
21
    /** @var string */
22
    public $uuid;
23
24
    /** @var int|float */
25
    public $amount;
26
27
    /** @var array */
28
    public $parameters;
29
30
    /** @var array|null */
31
    public $invoice;
32
33
    /** @var array|null */
34
    public $transfer;
35
36
    /** @var int */ // todo change to bool?
37
    public $status;
38
39
    /** @var string */
40
    public $statusLabel;
41
42
    /** @var string */
43
    public $createdAt;
44
45
    /** @var string */
46
    public $updatedAt;
47
48
    public function __construct(array $attributes)
49
    {
50
        parent::__construct($attributes);
51
52
        $this->invoice = $attributes['invoice'] ? new Invoice($attributes['invoice']) : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $attributes['invoice'] ?...utes['invoice']) : null can also be of type object<AcquiroPay\Paymarket\Resources\Invoice>. However, the property $invoice is declared as type array|null. 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...
53
        $this->transfer = $attributes['transfer'] ? new Transfer($attributes['transfer']) : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $attributes['transfer'] ...tes['transfer']) : null can also be of type object<AcquiroPay\Paymarket\Resources\Transfer>. However, the property $transfer is declared as type array|null. 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...
54
55
        // todo class for TransactionParameters or leave array
56
    }
57
58
    public function hasInvoice(): bool
59
    {
60
        return (bool) $this->invoice;
61
    }
62
63
    public function hasTransfer(): bool
64
    {
65
        return (bool) $this->transfer;
66
    }
67
}
68