GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 4dea3a...f98011 )
by James
14:12 queued 11s
created

IngDescription::MoveSavingsAccount()   B

Complexity

Conditions 7
Paths 15

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 20
rs 8.8333
cc 7
nc 15
nop 0
1
<?php
2
/**
3
 * IngDescription.php
4
 * Copyright (c) 2019 https://github.com/tomwerf
5
 *
6
 * This file is part of Firefly III (https://github.com/firefly-iii).
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace FireflyIII\Import\Specifics;
24
25
/**
26
 * Class IngDescription.
27
 *
28
 * @deprecated
29
 * @codeCoverageIgnore
30
 *
31
 * Parses the description from CSV files for Ing bank accounts.
32
 *
33
 * With Mutation 'InternetBankieren', 'Overschrijving', 'Verzamelbetaling' and
34
 * 'Incasso' the Name of Opposing account the Opposing IBAN number are in the
35
 * Description. This class will remove them, and add Name in description by
36
 * 'Betaalautomaat' so those are easily recognizable
37
 */
38
class IngDescription implements SpecificInterface
0 ignored issues
show
Deprecated Code introduced by
The interface FireflyIII\Import\Specifics\SpecificInterface has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
class IngDescription implements /** @scrutinizer ignore-deprecated */ SpecificInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
39
{
40
    /** @var array The current row. */
41
    public $row;
42
43
    /**
44
     * Description of the current specific.
45
     *
46
     * @return string
47
     * @codeCoverageIgnore
48
     */
49
    public static function getDescription(): string
50
    {
51
        return 'import.specific_ing_descr';
52
    }
53
54
    /**
55
     * Name of the current specific.
56
     *
57
     * @return string
58
     * @codeCoverageIgnore
59
     */
60
    public static function getName(): string
61
    {
62
        return 'import.specific_ing_name';
63
    }
64
65
    /**
66
     * Run the specific code.
67
     *
68
     * @param array $row
69
     *
70
     * @return array
71
     *
72
     */
73
    public function run(array $row): array
74
    {
75
        $this->row = array_values($row);
76
        array_push($this->row); // New column for "Valutadatum"
0 ignored issues
show
Bug introduced by
The call to array_push() has too few arguments starting with var. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        /** @scrutinizer ignore-call */ 
77
        array_push($this->row); // New column for "Valutadatum"

This check compares calls to functions or methods with their respective definitions. If the call has less 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. Please note the @ignore annotation hint above.

Loading history...
77
        if (count($this->row) >= 8) {                    // check if the array is correct
78
            switch ($this->row[4]) {                     // Get value for the mutation type
79
                case 'GT':                               // InternetBankieren
80
                case 'OV':                               // Overschrijving
81
                case 'VZ':                               // Verzamelbetaling
82
                case 'IC':                               // Incasso
83
                case 'DV':                               // Divers
84
                    $this->removeIBANIngDescription();   // Remove "IBAN:", because it is already at "Tegenrekening"
85
                    $this->removeNameIngDescription();   // Remove "Naam:", because it is already at "Naam/ Omschrijving"
86
                    $this->removeIngDescription();       // Remove "Omschrijving", but not the value from description
87
                    $this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column
88
                    $this->MoveSavingsAccount();         // Move savings account number and name
89
                    break;
90
                case 'BA':                              // Betaalautomaat
91
                    $this->moveValutadatumDescription(); // Move "Valutadatum" from description to new column
92
                    $this->addNameIngDescription();
93
                    break;
94
            }
95
        }
96
97
        return $this->row;
98
    }
99
100
    /**
101
     * Add the Opposing name from cell 1 in the description for Betaalautomaten
102
     * Otherwise the description is only: 'Pasvolgnr:<nr> <date> Transactie:<NR> Term:<nr>'.
103
     */
104
    protected function addNameIngDescription(): void
105
    {
106
        $this->row[8] = $this->row[1] . ' ' . $this->row[8];
107
    }
108
109
    /**
110
     * Move "Valutadatum" from the description to new column.
111
     */
112
    protected function moveValutadatumDescription(): void
113
    {
114
        $matches = [];
115
        if (preg_match('/Valutadatum: ([0-9-]+)/', $this->row[8], $matches)) {
116
            $this->row[9] = date("Ymd", strtotime($matches[1]));
117
            $this->row[8] = preg_replace('/Valutadatum: [0-9-]+/', '', $this->row[8]);
118
        }
119
    }
120
121
    /**
122
     * Remove IBAN number out of the  description
123
     * Default description of Description is: Naam: <OPPOS NAME> Omschrijving: <DESCRIPTION> IBAN: <OPPOS IBAN NR>.
124
     */
125
    protected function removeIBANIngDescription(): void
126
    {
127
        // Try replace the iban number with nothing. The IBAN nr is found in the third column
128
        $this->row[8] = preg_replace('/\sIBAN:\s' . $this->row[3] . '/', '', $this->row[8]);
129
    }
130
131
    /**
132
     * Remove "Omschrijving" (and NOT its value) from the description.
133
     */
134
    protected function removeIngDescription(): void
135
    {
136
        $this->row[8] = preg_replace('/Omschrijving: /', '', $this->row[8]);
137
    }
138
139
    /**
140
     * Remove "Naam" (and its value) from the description.
141
     */
142
    protected function removeNameIngDescription(): void
143
    {
144
        $this->row[8] = preg_replace('/Naam:.*?([a-zA-Z\/]+:)/', '$1', $this->row[8]);
145
    }
146
147
    /**
148
     * Move savings account number to column 1 and name to column 3.
149
     */
150
    private function MoveSavingsAccount(): void
151
    {
152
        $matches = [];
153
154
        if (preg_match('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', $this->row[8], $matches)) { // Search for saving acount at 'Mededelingen' column
155
            $this->row[1] = $this->row[1] . ' ' . $matches[2] . ' ' . $matches[3]; // Current name + Saving acount name + Acount number
156
            if ('' === (string) $this->row[3]) { // if Saving account number does not yet exists
157
                $this->row[3] = $matches[3]; // Copy savings account number
158
            }
159
            $this->row[8] = preg_replace('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', '', $this->row[8]); // Remove the savings account content from description
160
        } elseif (preg_match('/(Naar|Van) (.*rekening) ([A-Za-z0-9]+)/', $this->row[1], $matches)) { // Search for saving acount at 'Naam / Omschrijving' column
161
            $this->row[1] = $matches[2] . ' ' . $matches[3];  // Saving acount name + Acount number
162
            if ('' === (string) $this->row[3]) { // if Saving account number does not yet exists
163
                $this->row[3] = $matches[3]; // Copy savings account number
164
            }
165
        }
166
167
        if ('' !== (string)$this->row[3]) { // if Saving account number exists
168
            if (! preg_match('/[A-Za-z]/', $this->row[3])) { // if Saving account number has no characters 
169
                $this->row[3] = sprintf("%010d", $this->row[3]); // Make the number 10 digits
170
            }
171
        }
172
    }
173
}
174