Completed
Push — master ( 95299a...ed19e2 )
by Naylon Kessler de
02:38
created

File400::getMotives()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
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\MultiPartMotiveTrait;
8
use SmartCNAB\Services\Returning\Returning;
9
use SmartCNAB\Support\Bank\Itau;
10
11
/**
12
 * Class for Itau return CNAB 400 layout.
13
 */
14
class File400 extends Returning
15
{
16
    use MultiPartMotiveTrait;
17
18
    /**
19
     * File schema file.
20
     *
21
     * @var string
22
     */
23
    protected $schemaFile = '/schemas/400.json';
24
25
    /**
26
     * Check if received data as other motive set.
27
     *
28
     * @param  \StdClass  $data
29
     * @return boolean
30
     */
31
    protected function hasOtherMotive(StdClass $data)
32
    {
33
        $others = array_merge(
34
            Itau::OCCURRENCES_INSTRUCTION_CANCELED,
35
            Itau::OCCURRENCES_PAYER_CLAIMS,
36
            Itau::OCCURRENCES_PROTEST_ORDER_HALTED
37
        );
38
39
        return in_array($data->occurrenceCode, $others);
40
    }
41
42
    /**
43
     * Parse the motive parts from received motive.
44
     *
45
     * @param  \StdClass  $data
46
     * @return array
47
     */
48
    protected function parseMotiveParts(StdClass $data)
49
    {
50
        $motive = $data->motive;
51
52
        if (in_array($data->occurrenceCode, Itau::OCCURRENCES_ERROR)) {
53
            return str_split($motive, 2);
54
        }
55
56
        if ($this->hasOtherMotive($data)) {
57
            return [$data->otherMotive];
58
        }
59
60
        return [$motive];
61
    }
62
}
63