Passed
Push — master ( 6c42be...776013 )
by Igor
02:03
created

ListPaymentsRequest::getRequired()   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
 * This class represents List Payments RequestInterface Entity
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  RequestEntity
8
 * @package   Payever\Payments
9
 * @author    payever GmbH <[email protected]>
10
 * @copyright 2017-2018 payever GmbH
11
 * @license   MIT <https://opensource.org/licenses/MIT>
12
 * @link      https://getpayever.com/shopsystem/
13
 */
14
15
namespace Payever\ExternalIntegration\Payments\Http\RequestEntity;
16
17
use Payever\ExternalIntegration\Core\Http\RequestEntity;
18
use Payever\ExternalIntegration\Payments\Enum\Status;
19
20
/**
21
 * This class represents List Payments RequestInterface Entity
22
 *
23
 * PHP version 5.4
24
 *
25
 * @category  RequestEntity
26
 * @package   Payever\Payments
27
 * @author    payever GmbH <[email protected]>
28
 * @copyright 2017-2018 payever GmbH
29
 * @license   MIT <https://opensource.org/licenses/MIT>
30
 * @link      https://getpayever.com/shopsystem/
31
 *
32
 * @method string     getAccessToken()
33
 * @method string     getPaymentMethod()
34
 * @method \DateTime  getDate()
35
 * @method string     getCurrency()
36
 * @method string     getState()
37
 * @method int|string getLimit()
38
 * @method self       setAccessToken(string $token)
39
 * @method self       setPaymentMethod(string $method)
40
 * @method self       setCurrency(string $currency)
41
 * @method self       setState(string $state)
42
 * @method self       setLimit(int|string $limit)
43
 */
44
class ListPaymentsRequest extends RequestEntity
45
{
46
    /** @var string $accessToken */
47
    protected $accessToken;
48
49
    /** @var string $paymentMethod */
50
    protected $paymentMethod;
51
52
    /** @var \DateTime $date */
53
    protected $date;
54
55
    /** @var string $currency */
56
    protected $currency;
57
58
    /** @var string $state */
59
    protected $state;
60
61
    /** @var int|string $limit */
62
    protected $limit;
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function isValid()
68
    {
69
        return parent::isValid() &&
70
            (!$this->date || $this->date instanceof \DateTime) &&
71
            (!$this->state || in_array($this->state, Status::enum())) &&
72
            (!$this->limit || is_integer($this->limit))
73
        ;
74
    }
75
76
    /**
77
     * Sets Date
78
     *
79
     * @param string $date
80
     */
81
    public function setDate($date)
82
    {
83
        $this->date = date_create($date);
0 ignored issues
show
Documentation Bug introduced by
It seems like date_create($date) can also be of type false. However, the property $date is declared as type DateTime. 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...
84
    }
85
}
86