Returning::wasProtested()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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