ReservasBankParser::parse()   A
last analyzed

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\AbstractFile;
8
use MidasSoft\DominicanBankParser\Traits\InteractsWithArrayTrait;
9
use MidasSoft\DominicanBankParser\Validators\ReservasValidator;
10
11
class ReservasBankParser extends AbstractParser
12
{
13
    use InteractsWithArrayTrait;
14
15
    /**
16
     * Eliminates unnecesary values into
17
     * a Reservas bank file and convert it
18
     * to array.
19
     *
20
     * @param \MidasSoft\DominicanBankParser\Files\CSV $file
21
     *
22
     * @throws \MidasSoft\DominicanBankParser\Exceptions\InvalidArgumentException
23
     * @throws \MidasSoft\DominicanBankParser\Exceptions\EmptyFileException
24
     *
25
     * @return \MidasSoft\DominicanBankParser\Collections\DepositCollection
26
     */
27 3
    public function parse(AbstractFile $file)
28
    {
29 3
        $collection = new DepositCollection();
30 3
        $fileArray = array_slice($file->toArray(), 1);
31
32
        array_walk($fileArray, function ($line) use (&$collection) {
33 2
            if (!ReservasValidator::validate($line)) {
34
                return;
35
            }
36
37 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

37
            $collection->push(new Deposit(/** @scrutinizer ignore-type */ trim($line[5]), $line[1], $line[7], $line[2]));
Loading history...
38 3
        });
39
40 3
        $this->failIfParsedFileIsEmpty($collection);
41 2
        $this->cache($collection);
42
43 2
        return $collection;
44
    }
45
}
46