Completed
Push — master ( e75455...e5a838 )
by Naylon Kessler de
07:35
created

File400::parseMotiveParts()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace SmartCNAB\Services\Returning\Banks\Itau;
4
5
use StdClass;
6
7
use SmartCNAB\Services\Returning\Returning;
8
use SmartCNAB\Support\Bank\Itau;
9
10
/**
11
 * Class for Itau return CNAB 400 layout.
12
 */
13
class File400 extends Returning
14
{
15
    /**
16
     * File schema file.
17
     *
18
     * @var string
19
     */
20
    protected $schemaFile = '/schemas/400.json';
21
22
    /**
23
     * Fetch and return motives descriptions from received detail data.
24
     *
25
     * @param  \StdClass  $data
26
     * @return array
27
     */
28
    public function getMotives(StdClass $data)
29
    {
30
        $motives = $this->supportBank->motives($data->occurrenceCode);
0 ignored issues
show
Unused Code introduced by
The call to BankSupportInterface::motives() has too many arguments starting with $data->occurrenceCode.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
31
        $motive = $this->parseMotiveParts($data);
32
33
        $motive = array_map(function ($motive) use ($motives) {
34
            return empty($motives[$motive]) ? null : $motives[$motive];
35
        }, $motive);
36
37
        return array_filter($motive);
38
    }
39
40
    /**
41
     * Parse the motive parts from received motive.
42
     *
43
     * @param  \StdClass  $data
44
     * @return array
45
     */
46
    protected function parseMotiveParts(StdClass $data)
47
    {
48
        $motive = $data->motive;
49
50
        if (in_array($data->occurrenceCode, Itau::OCCURRENCES_ERROR)) {
51
            return str_split($motive, 2);
52
        }
53
54
        if (in_array($data->occurrenceCode, Itau::OCCURRENCES_INSTRUCTION_CANCELED)) {
55
            return [$data->canceledInstruction];
56
        }
57
58
        return [$motive];
59
    }
60
}
61