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 SgProProcessor. |
||
9 | */ |
||
10 | class SgProProcessor extends Processor implements ProcessorInterface |
||
11 | { |
||
12 | protected $configuration = [ |
||
13 | 'id' => 'sg_pro', |
||
14 | 'name' => 'Société Générale - Compte courant professionnel', |
||
15 | 'startConditions' => ['/Date\s+Valeur\s+Nature de l\'opération/'], |
||
16 | 'endConditions' => [ |
||
17 | '/1 Depuis l\'étranger/', '/N° d\'adhérent JAZZ Pro/', '/Société Générale\s+552 120 222 RCS Paris/', |
||
18 | ], |
||
19 | 'rowMergeColumnTokens' => [0], |
||
20 | 'rowSkipConditions' => ['SOLDE PRÉCÉDENT AU', 'TOTAUX DES MOUVEMENTS', 'RA4-01K', 'NOUVEAU SOLDE AU'], |
||
21 | 'rowsToSkip' => [0], |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * @param ArrayCollection $data |
||
26 | * |
||
27 | * @return ArrayCollection |
||
28 | */ |
||
29 | public function format(ArrayCollection $data) |
||
30 | { |
||
31 | $data = $data->map(function ($item) { |
||
32 | // Date |
||
33 | $dateRaw = $item[0]; |
||
34 | $date = new \DateTime(); |
||
35 | $date->setDate((int) substr($dateRaw, 6, 4), (int) substr($dateRaw, 3, 2), (int) substr($dateRaw, 0, 2)); |
||
36 | $date->setTime(12, 0, 0); |
||
37 | |||
38 | // Value Date |
||
39 | $dateRaw = $item[1]; |
||
40 | $valueDate = new \DateTime(); |
||
41 | $valueDate->setDate((int) substr($dateRaw, 6, 4), (int) substr($dateRaw, 3, 2), (int) substr($dateRaw, 0, 2)); |
||
42 | $valueDate->setTime(12, 0, 0); |
||
43 | |||
44 | // Value |
||
45 | $debitRaw = $item[3]; |
||
46 | View Code Duplication | if (strlen($debitRaw)) { |
|
0 ignored issues
–
show
|
|||
47 | $value = abs((float) str_replace(',', '.', str_replace('.', '', $debitRaw))); |
||
48 | $debit = true; |
||
49 | } else { |
||
50 | $creditRaw = $item[4]; |
||
51 | $value = (float) str_replace(',', '.', str_replace('.', '', $creditRaw)); |
||
52 | $debit = false; |
||
53 | } |
||
54 | |||
55 | return [ |
||
56 | 'date' => $date, |
||
57 | 'value_date' => $valueDate, |
||
58 | 'label' => $item[2], |
||
59 | 'value' => $value, |
||
60 | 'debit' => $debit, |
||
61 | ]; |
||
62 | }); |
||
63 | |||
64 | return $data; |
||
65 | } |
||
66 | } |
||
67 |
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.