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

Swedish   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 14.1 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 11
loc 78
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
 * Swedish internationalization
10
 *
11
 * @author Hannes Forsgård <[email protected]>
12
 */
13
class Swedish implements I18nInterface
14
{
15
    public static $translations = array(
16
        'INVOICE'        => 'FAKTURA',
17
        'Page '          => 'Sida ',
18
        ' of '             => ' av ',
19
        'Invoice date'   => 'Fakturadatum',
20
        'Invoice number' => 'Fakturanummer',
21
        'Reference'      => 'OCR-nummer',
22
        'Payment term'   => 'Betalningsvillkor',
23
        ' days'          => ' dagar',
24
        'Expiry date'    => 'Förfallodag',
25
        'VAT rate'       => 'Momssats',
26
        'Amount'         => 'Antal',
27
        'Unit cost'      => 'Á pris',
28
        'Total'          => 'Summa',
29
        'Basis'          => 'Underlag',
30
        'Total ex. VAT'  => 'Summa ex. moms',
31
        'Total VAT'      => 'Total moms',
32
        'Deduction'      => 'Erlagd förskottsbetalning',
33
        'Tax registered' => 'Godkänd för F-skatt.',
34
        'To pay'         => 'Att betala',
35
        'Address'        => 'Svarsadress',
36
        'Identification' => 'Organisationsnr',
37
        'VAT number'     => 'Momsreg.nr.',
38
        'Phone'          => 'Telefon',
39
        'E-mail'         => 'E-post',
40
        'Continues on next page..' => 'Sammanställningen fortsätter på nästa sida..'
41
    );
42
43
    private $currencyFormatter;
44
45 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...
46
    {
47
        if (!$currencyFormatter) {
48
            $currencyFormatter = new \NumberFormatter('sv', \NumberFormatter::CURRENCY);
49
            $currencyFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, '');
50
            $currencyFormatter->setSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL, '');
51
            $currencyFormatter->setTextAttribute(\NumberFormatter::NEGATIVE_PREFIX, "-");
52
        }
53
54
        $this->currencyFormatter = $currencyFormatter;
55
    }
56
57
    public function translate($string)
58
    {
59
        if (array_key_exists($string, self::$translations)) {
60
            return self::$translations[$string];
61
        }
62
63
        return $string;
64
    }
65
66
    public function formateDate(\DateTimeInterface $datetime)
67
    {
68
        return $datetime->format('Y-m-d');
69
    }
70
71
    public function formatCurrency(Amount $amount)
72
    {
73
        return $this->currencyFormatter->format($amount->getFloat());
74
    }
75
76
    public function formatCurrencySymbol(Amount $amount, $currency)
77
    {
78
        return $this->currencyFormatter->formatCurrency($amount->getFloat(), $currency);
79
    }
80
81
    public function formatPercentage($amount)
82
    {
83
        return $amount;
84
    }
85
86
    public function formatUnits($units)
87
    {
88
        return $units;
89
    }
90
}
91