BfbProcessor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 8.7 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 2
c 4
b 1
f 1
lcom 0
cbo 1
dl 4
loc 46
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B format() 4 28 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 {
0 ignored issues
show
Duplication introduced by
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...
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