Header::getCustomer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace MrPrompt\Centercob\Received\Partial;
3
4
use DateTime;
5
use MrPrompt\ShipmentCommon\Base\Customer;
6
use MrPrompt\ShipmentCommon\Base\Sequence;
7
8
/**
9
 * File header
10
 *
11
 * @author Thiago Paes <[email protected]>
12
 */
13
class Header
14
{
15
    /**
16
     * Line length
17
     *
18
     * @const int
19
     */
20
    const LENGTH = 1006;
21
22
    /**
23
     * Type of register
24
     *
25
     * @const string
26
     */
27
    const TYPE = 'A';
28
29
    /**
30
     * Shippment code
31
     *
32
     * @const int
33
     */
34
    const SHIPPING = 1;
35
36
    /**
37
     * Layout version
38
     *
39
     * @const int
40
     */
41
    const VERSION = '00000013';
42
43
    /**
44
     * Sequencial line
45
     *
46
     * @const int
47
     */
48
    const LINE = 1;
49
50
    /**
51
     * Customer Code
52
     *
53
     * @var Customer
54
     */
55
    private $customer;
56
57
    /**
58
     * File date creation
59
     *
60
     * @var DateTime
61
     */
62
    private $created;
63
64
    /**
65
     * Sequencial number of file
66
     *
67
     * @var Sequence
68
     */
69
    private $sequence;
70
71
    /**
72
     * @var string
73
     */
74
    private $passed;
75
76
    /**
77
     * Constructor
78
     * @param string $row
79
     */
80 9
    public function __construct($row)
81
    {
82 9
        $customer = new Customer();
83 9
        $customer->setName(substr($row, 5, 20));
84
85 9
        $this->passed   = substr($row, 2, 3);
86 9
        $this->customer = $customer;
87 9
        $this->created  = DateTime::createFromFormat('dmY h:i:s', substr($row, 25, 8) . ' 00:00:00');
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFor..., 25, 8) . ' 00:00:00') can also be of type false. However, the property $created 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...
88 9
        $this->sequence = new Sequence(substr($row, 500, 6));
89 9
    }
90
91
    /**
92
     * @return Customer
93
     */
94 1
    public function getCustomer()
95
    {
96 1
        return $this->customer;
97
    }
98
99
    /**
100
     * @param Customer $customer
101
     */
102 1
    public function setCustomer(Customer $customer)
103
    {
104 1
        $this->customer = $customer;
105 1
    }
106
107
    /**
108
     * @return DateTime
109
     */
110 1
    public function getCreated()
111
    {
112 1
        return $this->created;
113
    }
114
115
    /**
116
     * @param DateTime $created
117
     */
118 1
    public function setCreated(DateTime $created)
119
    {
120 1
        $this->created = $created;
121 1
    }
122
123
    /**
124
     * @return Sequence
125
     */
126 1
    public function getSequence()
127
    {
128 1
        return $this->sequence;
129
    }
130
131
    /**
132
     * @param Sequence $sequence
133
     */
134 1
    public function setSequence(Sequence $sequence)
135
    {
136 1
        $this->sequence = $sequence;
137 1
    }
138
139
    /**
140
     * @return string
141
     */
142 1
    public function getPassed()
143
    {
144 1
        return $this->passed;
145
    }
146
147
    /**
148
     * @param string $passed
149
     */
150 1
    public function setPassed($passed)
151
    {
152 1
        $this->passed = $passed;
153 1
    }
154
}
155