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

Returning::header()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
     * Fetch and return the message received on header data.
39
     *
40
     * @param  \StdClass  $data
41
     * @return array
42
     */
43
    public function getMessage(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...
44
    {
45
        return [];
46
    }
47
48
    /**
49
     * Fetch and return motives descriptions from received detail data.
50
     *
51
     * @param  \StdClass  $data
52
     * @return array
53
     */
54
    public function getMotives(StdClass $data)
55
    {
56
        $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...
57
58
        return empty($motives[$motive]) ? [] : [$motives[$motive]];
0 ignored issues
show
Bug introduced by
The variable $motive does not exist. Did you mean $motives?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
59
    }
60
61
    /**
62
     * Returns the file header.
63
     *
64
     * @return \StdClass
65
     */
66
    public function header()
67
    {
68
        $data = parent::header();
69
        $data->message = $this->getMessage($data);
70
71
        return $data;
72
    }
73
74
    /**
75
     * Check and return if received data has some error status.
76
     *
77
     * @param  \StdClass  $data
78
     * @return boolean
79
     */
80
    public function wasAnError(StdClass $data)
81
    {
82
        $bank = $this->supportBank;
83
84
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_ERROR);
85
    }
86
87
    /**
88
     * Check and return if received data has entry confirmed status.
89
     *
90
     * @param  \StdClass  $data
91
     * @return boolean
92
     */
93
    public function wasEntryConfirmed(StdClass $data)
94
    {
95
        $bank = $this->supportBank;
96
97
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_ENTRY);
98
    }
99
100
    /**
101
     * Check and return if received data has discharged status.
102
     *
103
     * @param  \StdClass  $data
104
     * @return boolean
105
     */
106
    public function wasDischarged(StdClass $data)
107
    {
108
        $bank = $this->supportBank;
109
110
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_DISCHARGED);
111
    }
112
113
    /**
114
     * Check and return if received data has paid status.
115
     *
116
     * @param  \StdClass  $data
117
     * @return boolean
118
     */
119
    public function wasPaid(StdClass $data)
120
    {
121
        $bank = $this->supportBank;
122
123
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_PAID);
124
    }
125
126
    /**
127
     * Check and return if received data has protested status.
128
     *
129
     * @param  \StdClass  $data
130
     * @return boolean
131
     */
132
    public function wasProtested(StdClass $data)
133
    {
134
        $bank = $this->supportBank;
135
136
        return in_array($data->occurrenceCode, $bank::OCCURRENCES_PROTESTED);
137
    }
138
139
    /**
140
     * Specialized mapper method for one line parsing.
141
     *
142
     * @param  string  $detail
143
     * @return \StdClass
144
     */
145
    protected function detailMapper($detail)
146
    {
147
        $parsed = parent::detailMapper($detail);
148
        $parsed = $this->parseStatusAttributes($parsed);
149
150
        return $parsed;
151
    }
152
153
    /**
154
     * @return mixed
155
     */
156
    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...
157
    {
158
    }
159
160
    /**
161
     * @return array
162
     */
163
    protected function parseCustomGetters()
164
    {
165
    }
166
167
    /**
168
     * Parsed and set the status attributes on received detail data.
169
     *
170
     * @param  \StdClass  $detail
171
     * @return \StdClass
172
     */
173
    protected function parseStatusAttributes(StdClass $detail)
174
    {
175
        $detail->motives = $this->getMotives($detail);
176
        $detail->wasAnError = $this->wasAnError($detail);
177
        $detail->wasDischarged = $this->wasDischarged($detail);
178
        $detail->wasEntryConfirmed = $this->wasEntryConfirmed($detail);
179
        $detail->wasPaid = $this->wasPaid($detail);
180
        $detail->wasProtested = $this->wasProtested($detail);
181
182
        return $detail;
183
    }
184
}
185