Completed
Push — master ( fbe46c...fa1c37 )
by Max
02:21
created

ReservasBankParser::parse()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 1
nop 1
dl 0
loc 17
ccs 9
cts 10
cp 0.9
crap 2.004
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace MidasSoft\DominicanBankParser\Parsers;
4
5
use MidasSoft\DominicanBankParser\Collections\DepositCollection;
6
use MidasSoft\DominicanBankParser\Deposit;
7
use MidasSoft\DominicanBankParser\Files\CSV;
8
use MidasSoft\DominicanBankParser\Files\AbstractFile;
9
use MidasSoft\DominicanBankParser\Traits\InteractsWithArrayTrait;
10
use MidasSoft\DominicanBankParser\Validators\ReservasValidator;
11
12
class ReservasBankParser extends AbstractParser
13
{
14
    use InteractsWithArrayTrait;
15
16
    /**
17
     * Eliminates unnecesary values into
18
     * a Reservas bank file and convert it
19
     * to array.
20
     *
21
     * @param \MidasSoft\DominicanBankParser\Files\CSV $file
22
     *
23
     * @throws \MidasSoft\DominicanBankParser\Exceptions\InvalidArgumentException
24
     * @throws \MidasSoft\DominicanBankParser\Exceptions\EmptyFileException
25
     *
26
     * @return array
27
     */
28 3
    public function parse(AbstractFile $file)
29
    {
30 3
        $collection = new DepositCollection();
31 3
        $fileArray = array_slice($file->toArray(), 1);
32
33
        array_walk($fileArray, function ($line, $key) use (&$collection) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

33
        array_walk($fileArray, function ($line, /** @scrutinizer ignore-unused */ $key) use (&$collection) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34 2
            if (!ReservasValidator::validate($line)) {
35
                return;
36
            }
37
38 2
            $collection->push(new Deposit(trim($line[5]), $line[1], $line[7], $line[2]));
0 ignored issues
show
Bug introduced by
trim($line[5]) of type string is incompatible with the type double expected by parameter $amount of MidasSoft\DominicanBankP...\Deposit::__construct(). ( Ignorable by Annotation )

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

38
            $collection->push(new Deposit(/** @scrutinizer ignore-type */ trim($line[5]), $line[1], $line[7], $line[2]));
Loading history...
39 3
        });
40
41 3
        $this->failIfParsedFileIsEmpty($collection);
42 2
        $this->cache($collection);
43
44 2
        return $collection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $collection returns the type MidasSoft\DominicanBankP...tions\DepositCollection which is incompatible with the documented return type array.
Loading history...
45
    }
46
}
47