Completed
Push — master ( c1ef80...f9ae48 )
by Naylon Kessler de
02:39
created

Returning::getMotives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace SmartCNAB\Services\Returning;
4
5
use StdClass;
6
7
use SmartCNAB\Support\Bank;
8
use SmartCNAB\Support\Picture;
9
use SmartCNAB\Support\File\Returning as SupportReturning;
10
11
/**
12
 * Base service class for all returning service classes.
13
 * This class contains all shared logic around returning parsing rules.
14
 */
15
class Returning extends SupportReturning
16
{
17
    /**
18
     * Instance of bank support class.
19
     *
20
     * @var \SmartCNAB\Contracts\Support\BankSupportInterface
21
     */
22
    protected $supportBank;
23
24
    /**
25
     * Initialize and return a new instance.
26
     *
27
     * @param  string  $path  path of returning file
28
     * @param  \SmartCNAB\Support\Picture  $picture
29
     */
30
    public function __construct($path, Picture $picture)
31
    {
32
        parent::__construct($path, $picture);
33
34
        $this->supportBank = Bank::ofNumber($this->header()->bankCode);
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getMessage(array $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...
41
    {
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function getMotives(array $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...
48
    {
49
    }
50
51
    /**
52
     * @return boolean
53
     */
54
    public function wasAnError(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...
55
    {
56
    }
57
58
    /**
59
     * Check and return if received data has entry confirmed status.
60
     *
61
     * @param  \StdClass  $data
62
     * @return boolean
63
     */
64
    public function wasEntryConfirmed(StdClass $data)
65
    {
66
        $bank = $this->supportBank;
67
68
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_ENTRY);
69
    }
70
71
    /**
72
     * Check and return if received data has discharged status.
73
     *
74
     * @param  \StdClass  $data
75
     * @return boolean
76
     */
77
    public function wasDischarged(StdClass $data)
78
    {
79
        $bank = $this->supportBank;
80
81
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_DISCHARGED);
82
    }
83
84
    /**
85
     * Check and return if received data has paid status.
86
     *
87
     * @param  \StdClass  $data
88
     * @return boolean
89
     */
90
    public function wasPaid(StdClass $data)
91
    {
92
        $bank = $this->supportBank;
93
94
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_PAID);
95
    }
96
97
    /**
98
     * Check and return if received data has protested status.
99
     *
100
     * @param  \StdClass  $data
101
     * @return boolean
102
     */
103
    public function wasProtested(StdClass $data)
104
    {
105
        $bank = $this->supportBank;
106
107
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_PROTESTED);
108
    }
109
110
    /**
111
     * Specialized mapper method for one line parsing.
112
     *
113
     * @param  string  $detail
114
     * @return \StdClass
115
     */
116
    protected function detailMapper($detail)
117
    {
118
        $parsed = parent::detailMapper($detail);
119
        $parsed = $this->parseStatusAttributes($parsed);
120
121
        return $parsed;
122
    }
123
124
    /**
125
     * @return mixed
126
     */
127
    protected function getCustomGetter($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name 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...
128
    {
129
    }
130
131
    /**
132
     * @return array
133
     */
134
    protected function parseCustomGetters()
135
    {
136
    }
137
138
    /**
139
     * Parsed and set the status attributes on received detail data.
140
     *
141
     * @param  \StdClass  $detail
142
     * @return \StdClass
143
     */
144
    protected function parseStatusAttributes(StdClass $detail)
145
    {
146
        $detail->wasAnError = $this->wasAnError($detail);
147
        $detail->wasDischarged = $this->wasDischarged($detail);
148
        $detail->wasEntryConfirmed = $this->wasEntryConfirmed($detail);
149
        $detail->wasPaid = $this->wasPaid($detail);
150
        $detail->wasProtested = $this->wasProtested($detail);
151
152
        return $detail;
153
    }
154
}
155