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

BHDBankParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 33
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\CSV;
8
use MidasSoft\DominicanBankParser\Files\AbstractFile;
9
use MidasSoft\DominicanBankParser\Traits\InteractsWithArrayTrait;
10
use MidasSoft\DominicanBankParser\Validators\BHDValidator;
11
12
class BHDBankParser extends AbstractParser
13
{
14
    use InteractsWithArrayTrait;
15
16
    /**
17
     * Eliminates unnecesary values into
18
     * a BHD 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(), 3);
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 (!BHDValidator::validate($line)) {
35 2
                return;
36
            }
37
38 2
            $collection->push(new Deposit($line[6], $line[0], $line[4], $line[4]));
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