File400   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasOtherMotive() 0 11 1
A parseMotiveParts() 0 14 3
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_DEBITS,
35
            Itau::OCCURRENCES_INSTRUCTION_CANCELED,
36
            Itau::OCCURRENCES_PAYER_CLAIMS,
37
            Itau::OCCURRENCES_PROTEST_ORDER_HALTED
38
        );
39
40
        return in_array($data->occurrenceCode, $others);
41
    }
42
43
    /**
44
     * Parse the motive parts from received motive.
45
     *
46
     * @param  \StdClass  $data
47
     * @return array
48
     */
49
    protected function parseMotiveParts(StdClass $data)
50
    {
51
        $motive = str_pad(trim($data->motive), 8, 0, STR_PAD_LEFT);
52
53
        if (in_array($data->occurrenceCode, Itau::OCCURRENCES_ERROR)) {
54
            return str_split($motive, 2);
55
        }
56
57
        if ($this->hasOtherMotive($data)) {
58
            return [$data->otherMotive];
59
        }
60
61
        return [$motive];
62
    }
63
}
64