Footer::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
namespace MrPrompt\Celesc\Shipment\Partial;
3
4
use MrPrompt\ShipmentCommon\Base\Sequence;
5
use MrPrompt\ShipmentCommon\Type\Alphanumeric;
6
use MrPrompt\ShipmentCommon\Type\Numeric;
7
8
/**
9
 * File footer
10
 *
11
 * @author Thiago Paes <[email protected]>
12
 */
13
class Footer
14
{
15
    /**
16
     * Type of register
17
     *
18
     * @var string
19
     */
20
    const TYPE = 9;
21
22
    /**
23
     * Sequence number
24
     *
25
     * @var Sequence
26
     */
27
    private $sequence;
28
29
    /**
30
     * Total of new charges
31
     *
32
     * @var int
33
     */
34
    private $total;
35
36
    /**
37
     * Sum of new charges
38
     *
39
     * @var int
40
     */
41
    private $sum;
42
43
    /**
44
     * @param int $totalCharges
45
     * @param int $sumCharges
46
     * @param Sequence $sequence
47
     */
48 1
    public function __construct($totalCharges = 0, $sumCharges = 0, Sequence $sequence)
49
    {
50 1
        $this->total    = $totalCharges;
51 1
        $this->sum      = $sumCharges;
52 1
        $this->sequence = $sequence;
53 1
    }
54
55
    /**
56
     * Render footer line
57
     *
58
     * @return string
59
     */
60 1
    public function render()
61
    {
62
        // register code
63 1
        $result = self::TYPE;
64
65
        // sum of charges values
66 1
        $result .= str_pad(str_replace('.',  '', $this->sum), 11, Numeric::FILL, Numeric::ALIGN);
67
68
        // whitespace
69 1
        $result .= str_pad(' ', 132, Alphanumeric::FILL, Alphanumeric::ALIGN);
70
71
        // sequence line
72 1
        $result .= str_pad($this->sequence->getValue(), 6, Numeric::FILL, Numeric::ALIGN);
73
74
        // resulting...
75 1
        return $result;
76
    }
77
}
78