Completed
Push — master ( b96a07...d3cdb3 )
by Hannes
03:31
created

English   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 18.64 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 11
loc 59
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 2
A translate() 0 8 2
A formateDate() 0 4 1
A formatCurrency() 0 4 1
A formatCurrencySymbol() 0 4 1
A formatPercentage() 0 4 1
A formatUnits() 0 4 1

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 byrokrat\paperinvoice\I18n;
4
5
use byrokrat\paperinvoice\I18nInterface;
6
use byrokrat\amount\Amount;
7
8
/**
9
 * English internationalization
10
 *
11
 * @author Hannes Forsgård <[email protected]>
12
 */
13
class English implements I18nInterface
14
{
15
    public static $translations = array(
16
        'Amount'         => '#',
17
        'Unit cost'      => 'Price',
18
        'Total VAT'      => 'Total moms',
19
        'Tax registered' => '',
20
        'Identification' => 'Corporate id.',
21
        'VAT rate'       => 'VAT'
22
    );
23
24
    private $currencyFormatter;
25
26 View Code Duplication
    public function __construct(\NumberFormatter $currencyFormatter = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
27
    {
28
        if (!$currencyFormatter) {
29
            $currencyFormatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
30
            $currencyFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, '');
31
            $currencyFormatter->setSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL, '');
32
            $currencyFormatter->setTextAttribute(\NumberFormatter::NEGATIVE_PREFIX, "-");
33
        }
34
35
        $this->currencyFormatter = $currencyFormatter;
36
    }
37
38
    public function translate($string)
39
    {
40
        if (array_key_exists($string, self::$translations)) {
41
            return self::$translations[$string];
42
        }
43
44
        return $string;
45
    }
46
47
    public function formateDate(\DateTimeInterface $datetime)
48
    {
49
        return $datetime->format('d/m/Y');
50
    }
51
52
    public function formatCurrency(Amount $amount)
53
    {
54
        return $this->currencyFormatter->format($amount->getFloat());
55
    }
56
57
    public function formatCurrencySymbol(Amount $amount, $currency)
58
    {
59
        return $this->currencyFormatter->formatCurrency($amount->getFloat(), $currency);
60
    }
61
62
    public function formatPercentage($amount)
63
    {
64
        return $amount;
65
    }
66
67
    public function formatUnits(Amount $units)
68
    {
69
        return $units;
70
    }
71
}
72