Completed
Push — master ( ac28ba...d1c608 )
by Adriano
05:00
created

GetByFiltrosResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: a.moreira
5
 * Date: 28/10/2016
6
 * Time: 09:09
7
 */
8
9
namespace Integracao\ControlPay\Contracts\Pedido;
10
11
use Integracao\ControlPay\Helpers\SerializerHelper;
12
use Integracao\ControlPay\Model\Pedido;
13
14
/**
15
 * Class GetByFiltrosResponse
16
 * @package Integracao\ControlPay\Contracts\Pedido
17
 */
18
class GetByFiltrosResponse
19
{
20
    /**
21
     * @var \DateTime
22
     */
23
    private $data;
24
25
    /**
26
     * @var array
27
     */
28
    private $pedidos;
29
30
    /**
31
     * InserirResponse constructor.
32
     */
33
    public function __construct()
34
    {
35
    }
36
37
    /**
38
     * @return \DateTime
39
     */
40
    public function getData()
41
    {
42
        return $this->data;
43
    }
44
45
    /**
46
     * @param \DateTime $data
47
     * @return InserirResponse
48
     */
49
    public function setData($data)
50
    {
51
        $this->data = \DateTime::createFromFormat('d/m/Y H:i:s.u', $data);
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFor...'d/m/Y H:i:s.u', $data) can also be of type false. However, the property $data is declared as type object<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...
52
        return $this;
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getPedidos()
59
    {
60
        return $this->pedidos;
61
    }
62
63
    /**
64
     * @param $pedidos
65
     * @return $this
66
     */
67
    public function setPedidos($pedidos)
68
    {
69
        foreach ($pedidos as $pedido)
70
            $this->pedidos[] = SerializerHelper::denormalize($pedido, Pedido::class);
71
72
        return $this;
73
    }
74
}