Completed
Push — master ( e5a838...3ab9c7 )
by Naylon Kessler de
02:53
created

File400::hasOtherMotive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
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
        $map = $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
        $parts = $this->parseMotiveParts($data);
32
33
        $mapper = function ($motive) use ($map) {
34
            return empty($map[$motive]) ? null : $map[$motive];
35
        };
36
37
        return array_filter(array_map($mapper, $parts));
38
    }
39
40
    /**
41
     * Check if received data as other motive set.
42
     *
43
     * @param  \StdClass  $data
44
     * @return boolean
45
     */
46
    protected function hasOtherMotive(StdClass $data)
47
    {
48
        $others = array_merge(
49
            Itau::OCCURRENCES_INSTRUCTION_CANCELED,
50
            Itau::OCCURRENCES_PAYER_CLAIMS,
51
            Itau::OCCURRENCES_PROTEST_ORDER_HALTED
52
        );
53
54
        return in_array($data->occurrenceCode, $others);
55
    }
56
57
    /**
58
     * Parse the motive parts from received motive.
59
     *
60
     * @param  \StdClass  $data
61
     * @return array
62
     */
63
    protected function parseMotiveParts(StdClass $data)
64
    {
65
        $motive = $data->motive;
66
67
        if (in_array($data->occurrenceCode, Itau::OCCURRENCES_ERROR)) {
68
            return str_split($motive, 2);
69
        }
70
71
        if ($this->hasOtherMotive($data)) {
72
            return [$data->otherMotive];
73
        }
74
75
        return [$motive];
76
    }
77
}
78