Header::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace MrPrompt\Centercob\Shipment\Partial;
3
4
use DateTime;
5
use MrPrompt\ShipmentCommon\Type\Numeric;
6
use MrPrompt\ShipmentCommon\Base\Customer;
7
use MrPrompt\ShipmentCommon\Base\Sequence;
8
use MrPrompt\ShipmentCommon\Type\Alphanumeric;
9
10
/**
11
 * File header
12
 *
13
 * @author Thiago Paes <[email protected]>
14
 */
15
class Header
16
{
17
    /**
18
     * Type of register
19
     *
20
     * @const string
21
     */
22
    const TYPE = 'A';
23
24
    /**
25
     * Shippment code
26
     *
27
     * @const int
28
     */
29
    const SHIPPING = 2;
30
31
    /**
32
     * Layout version
33
     *
34
     * @const int
35
     */
36
    const VERSION = '00000013';
37
38
    /**
39
     * Sequencial line
40
     *
41
     * @const int
42
     */
43
    const LINE = 1;
44
45
    /**
46
     * Customer Code
47
     *
48
     * @var Customer
49
     */
50
    private $customer;
51
52
    /**
53
     * File date creation
54
     *
55
     * @var DateTime
56
     */
57
    private $created;
58
59
    /**
60
     * Sequencial number of file
61
     *
62
     * @var Sequence
63
     */
64
    private $sequence;
65
66
    /**
67
     * Constructor
68
     *
69
     * @param Customer $customer
70
     * @param Sequence $sequence
71
     * @param DateTime $created
72
     */
73 7
    public function __construct(Customer $customer, Sequence $sequence, DateTime $created)
74
    {
75 7
        $this->customer = $customer;
76 7
        $this->sequence = $sequence;
77 7
        $this->created  = $created;
78 7
    }
79
80
    /**
81
     * @return Customer
82
     */
83 1
    public function getCustomer()
84
    {
85 1
        return $this->customer;
86
    }
87
88
    /**
89
     * @param Customer $customer
90
     */
91 1
    public function setCustomer(Customer $customer)
92
    {
93 1
        $this->customer = $customer;
94 1
    }
95
96
    /**
97
     * @return DateTime
98
     */
99 1
    public function getCreated()
100
    {
101 1
        return $this->created;
102
    }
103
104
    /**
105
     * @param DateTime $created
106
     */
107 1
    public function setCreated(DateTime $created)
108
    {
109 1
        $this->created = $created;
110 1
    }
111
112
    /**
113
     * @return Sequence
114
     */
115 1
    public function getSequence()
116
    {
117 1
        return $this->sequence;
118
    }
119
120
    /**
121
     * @param Sequence $sequence
122
     */
123 1
    public function setSequence(Sequence $sequence)
124
    {
125 1
        $this->sequence = $sequence;
126 1
    }
127
128
    /**
129
     * Render header file
130
     *
131
     * @return string
132
     */
133 1
    public function render()
134
    {
135
        // register type
136 1
        $line  = self::TYPE;
137
138
        // shipping code
139 1
        $line .= self::SHIPPING;
140
141
        // customer code
142 1
        $line .= str_pad($this->customer->getCode(), 6, Numeric::FILL, Numeric::ALIGN);
143
144
        // date from file
145 1
        $line .= $this->created->format('dmY');
146
147
        // whitespace
148 1
        $line .= str_pad('', 970, Alphanumeric::FILL, Alphanumeric::ALIGN);
149
150
        // layout version
151 1
        $line .= str_pad(self::VERSION, 8, Alphanumeric::FILL, Alphanumeric::ALIGN);
152
153
        // sequence file
154 1
        $line .= str_pad($this->sequence->getValue(), 6, Numeric::FILL, Numeric::ALIGN);
155
156
        // sequence line
157 1
        $line .= str_pad(self::LINE, 6, Numeric::FILL, Numeric::ALIGN);
158
159
        // resulting...
160 1
        return $line;
161
    }
162
}
163