BoletoConverter::toBarcode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.9666
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Claudsonm\BoletoWinner\Converters;
4
5
use Claudsonm\BoletoWinner\Bill;
6
7
class BoletoConverter implements Converter
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 26
    public function toBarcode(Bill $bill): string
13
    {
14 26
        $writableLine = $bill->getWritableLine();
15
        $barcodeParts = [
16 26
            'bankCode' => substr($writableLine, 0, 3),
17 26
            'currency' => substr($writableLine, 3, 1),
18 26
            'financialInfo' => substr($writableLine, 32),
19 26
            'firstFreeFields' => substr($writableLine, 4, 5),
20 26
            'secondFreeFields' => substr($writableLine, 10, 10),
21 26
            'thirdFreeFields' => substr($writableLine, 21, 10),
22
        ];
23
24 26
        return implode('', $barcodeParts);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 25
    public function toWritableLine(Bill $bill): string
31
    {
32 25
        $barcode = $bill->getBarcode();
33
        $blocks = [
34 25
            substr($barcode, 0, 4).substr($barcode, 19, 5),
35 25
            substr($barcode, 24, 10),
36 25
            substr($barcode, 34, 10),
37
        ];
38
39 25
        foreach ($blocks as &$block) {
40 25
            $block .= module10($block);
41
        }
42 25
        $blocks[] = substr($barcode, 4, 1);
43 25
        $blocks[] = substr($barcode, 5, 14);
44
45 25
        return implode('', $blocks);
46
    }
47
}
48