PositiveAmount   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 2
A requiresDefaultAccount() 0 3 1
A requiresTransactionCurrency() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * PositiveAmount.php
5
 * Copyright (c) 2020 [email protected]
6
 *
7
 * This file is part of the Firefly III CSV importer
8
 * (https://github.com/firefly-iii/csv-importer).
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
22
 */
23
24
namespace App\Services\Import\Task;
25
26
use App\Services\CSV\Converter\Amount;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, App\Services\Import\Task\Amount. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
27
28
/**
29
 * Class PositiveAmount
30
 */
31
class PositiveAmount extends AbstractTask
32
{
33
34
    /**
35
     * Make sure amount is always positive when submitting.
36
     *
37
     * @inheritDoc
38
     */
39
    public function process(array $group): array
40
    {
41
        foreach ($group['transactions'] as $index => $transaction) {
42
            $group['transactions'][$index]['amount'] = Amount::positive($group['transactions'][$index]['amount']);
43
        }
44
45
        return $group;
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function requiresDefaultAccount(): bool
52
    {
53
        return false;
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function requiresTransactionCurrency(): bool
60
    {
61
        return false;
62
    }
63
}
64