1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kasifi\PdfParserBundle\Processor; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class BfbProcessor. |
9
|
|
|
*/ |
10
|
|
|
class BfbProcessor extends Processor implements ProcessorInterface |
11
|
|
|
{ |
12
|
|
|
protected $configuration = [ |
13
|
|
|
'id' => 'bfb', |
14
|
|
|
'name' => 'B For Bank - Compte courant particulier', |
15
|
|
|
'startConditions' => ['/Libellé de l\'opération/'], |
16
|
|
|
'endConditions' => ['/BforBank vous informe/', '/Nous vous rappelons qu\'en cas de différend/'], |
17
|
|
|
'rowMergeColumnTokens' => [1], |
18
|
|
|
'rowSkipConditions' => ['Votre ancien solde', '063584840313690801pli', 'Votre nouveau solde'], |
19
|
|
|
'rowsToSkip' => [0, 1], |
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[1]; |
32
|
|
|
$date = new \DateTime(); |
33
|
|
|
$date->setDate(substr($dateRaw, 6, 4), substr($dateRaw, 3, 2), substr($dateRaw, 0, 2)); |
34
|
|
|
$date->setTime(12, 0, 0); |
35
|
|
|
|
36
|
|
|
// Value |
37
|
|
|
if (strlen($item[3])) { |
38
|
|
|
$value = abs((float) str_replace(',', '.', str_replace(' ', '', $item[3]))); |
39
|
|
|
$debit = true; |
40
|
|
View Code Duplication |
} else { |
|
|
|
|
41
|
|
|
$value = (float) str_replace(',', '.', str_replace(' ', '', $item[4])); |
42
|
|
|
$debit = false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return [ |
46
|
|
|
'date' => $date, |
47
|
|
|
'label' => $item[2], |
48
|
|
|
'value' => $value, |
49
|
|
|
'debit' => $debit, |
50
|
|
|
]; |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
return $data; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
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.