PopularBankParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 17 2
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\Validators\PopularValidator;
9
10
class PopularBankParser extends AbstractParser
11
{
12
    /**
13
     * Eliminates unnecesary values into
14
     * a Popular bank file and convert it
15
     * to array.
16
     *
17
     * @param \MidasSoft\DominicanBankParser\Files\CSV $file
18
     *
19
     * @throws \MidasSoft\DominicanBankParser\Exceptions\InvalidArgumentException
20
     * @throws \MidasSoft\DominicanBankParser\Exceptions\EmptyFileException
21
     *
22
     * @return \MidasSoft\DominicanBankParser\Collections\DepositCollection
23
     */
24 3
    public function parse(AbstractFile $file)
25
    {
26 3
        $collection = new DepositCollection();
27 3
        $fileArray = array_slice($file->toArray(), 5);
28
29
        array_walk($fileArray, function ($line) use (&$collection) {
30 2
            if (!PopularValidator::validate($line)) {
31 2
                return;
32
            }
33
34 2
            $collection->push(new Deposit($line[2], $line[0], $line[5], $line[1]));
35 3
        });
36
37 3
        $this->failIfParsedFileIsEmpty($collection);
38 2
        $this->cache($collection);
39
40 2
        return $collection;
41
    }
42
}
43