Passed
Push — master ( 66e3bc...7594cc )
by Naylon Kessler de
04:03
created

File400::parseMotiveParts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace SmartCNAB\Services\Returning\Banks\Bradesco;
4
5
use SmartCNAB\Services\Returning\MultiPartMotiveTrait;
6
use SmartCNAB\Services\Returning\Returning;
7
use SmartCNAB\Support\Bank\Bradesco;
8
9
/**
10
 * Class for Bradesco return CNAB 400 layout.
11
 */
12
class File400 extends Returning
13
{
14
    use MultiPartMotiveTrait;
15
16
    /**
17
     * File schema file.
18
     *
19
     * @var string
20
     */
21
    protected $schemaFile = '/schemas/400.json';
22
23
    /**
24
     * Find for irregular motives on received motive info.
25
     *
26
     * @param  mixed  $motive
27
     * @return array
28
     */
29
    protected function findIrregularMotive($motive)
30
    {
31
        $filter = function ($irregular) use ($motive) {
32
            return strpos($motive, $irregular) !== false;
33
        };
34
35
        return array_filter(Bradesco::MOTIVES_DEBITS_IRREGULAR, $filter);
36
    }
37
38
    /**
39
     * Parse the motive parts for debits occurrence code.
40
     *
41
     * @param  mixed  $motive
42
     * @param  \StdClass  $data
43
     * @return array
44
     */
45
    protected function parseDebitsMotiveParts($motive, StdClass $data)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        $irregular = $this->findIrregularMotive($motive);
48
49
        foreach ($irregular as $one) {
50
            $motive = str_replace($one, '', $motive);
51
        }
52
53
        $regular = str_split($motive, 2);
54
55
        return array_merge($irregular, $regular);
56
    }
57
58
    /**
59
     * Parse the motive parts from received motive.
60
     *
61
     * @param  \StdClass  $data
62
     * @return array
63
     */
64
    protected function parseMotiveParts(StdClass $data)
65
    {
66
        $motive = str_pad(trim($data->motive), 10, 0, STR_PAD_LEFT);
67
68
        if (in_array($data->occurrenceCode, Bradesco::OCCURRENCES_DEBITS)) {
69
            return $this->parseDebitsMotiveParts($motive, $data);
70
        }
71
72
        return str_split($motive, 2);
73
    }
74
}
75