Completed
Branch master (0b2361)
by Lucas
04:00 queued 02:07
created

Processor/LclProcessor.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
            // Value
36
            $debitRaw = $item[3];
37 View Code Duplication
            if (strlen($debitRaw)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
                $value = abs((float) str_replace(',', '.', str_replace(' ', '', $debitRaw)));
39
                $debit = true;
40
            } else {
41
                $creditRaw = $item[4];
42
                $value = (float) str_replace(',', '.', str_replace(' ', '', $creditRaw));
43
                $debit = false;
44
            }
45
46
            return [
47
                'date' => $date,
48
                'label' => $item[1],
49
                'value' => $value,
50
                'debit' => $debit,
51
            ];
52
        });
53
54
        return $data;
55
    }
56
}
57