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
![]() |
|||
38 | 3 | }); |
|
39 | |||
40 | 3 | $this->failIfParsedFileIsEmpty($collection); |
|
41 | 2 | $this->cache($collection); |
|
42 | |||
43 | 2 | return $collection; |
|
44 | } |
||
45 | } |
||
46 |