Completed
Branch master (0b2361)
by Lucas
03:53 queued 01:52
created

LclProcessor::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 21
rs 9.3142
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace Kasifi\PdfParserBundle\Processor;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
7
/**
8
 * Class LclProcessor.
9
 */
10
class LclProcessor extends Processor implements ProcessorInterface
11
{
12
    protected $configuration = [
13
        'id' => 'lcl',
14
        'name' => 'LCL - Compte courant particulier',
15
        'startConditions' => ['/ DATE\s+LIBELLE\s+/'],
16
        'endConditions' => ['/Page \d \/ \d/', '/LCL vous informe/'],
17
        'rowMergeColumnTokens' => [0],
18
        'rowSkipConditions' => ['ANCIEN SOLDE', 'TOTAUX', 'SOLDE EN EUROS', 'SOLDE INTERMEDIAIRE A'],
19
        'rowsToSkip' => [0],
20
    ];
21
22
    /**
23
     * @param ArrayCollection $data
24
     *
25
     * @return ArrayCollection
26
     */
27
    public function format(ArrayCollection $data)
28
    {
29
        $data = $data->map(function ($item) {
30
            // Date
31
            $dateRaw = $item[2];
32
            $date = new \DateTime();
33
            $date->setDate(2000 + (int) substr($dateRaw, 6, 2), (int) substr($dateRaw, 3, 2), (int) substr($dateRaw, 0, 2));
34
            $date->setTime(12, 0, 0);
35
            // Transaction
36
            $transaction = $this->frenchTransactionFormatter($item[3], $item[4]);
37
38
            return [
39
                'date'  => $date,
40
                'label' => $item[1],
41
                'value' => $transaction['value'],
42
                'debit' => $transaction['debit'],
43
            ];
44
        });
45
46
        return $data;
47
    }
48
}
49