LocalizationTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 9.35 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 10
loc 107
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetTranslator() 0 6 1
A providerLocales() 0 54 1
A testSetLocale() 0 5 1
A testSetTranslator() 10 10 1
A testSetLocaleWithKnownLocale() 0 4 1
A testSetLocaleWithUnknownLocale() 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 HMLB\Date\Tests\Date;
4
5
/*
6
 * This file is part of the Date package.
7
 *
8
 * (c) Hugues Maignol <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
use HMLB\Date\Date;
15
use HMLB\Date\Tests\AbstractTestCase;
16
use Symfony\Component\Translation\Loader\ArrayLoader;
17
use Symfony\Component\Translation\Translator;
18
19
class LocalizationTest extends AbstractTestCase
20
{
21
    public function testGetTranslator()
22
    {
23
        $t = Date::getTranslator();
24
        $this->assertNotNull($t);
25
        $this->assertSame('en', $t->getLocale());
26
    }
27
28
    /**
29
     * @see testSetLocale
30
     * @see testSetTranslator
31
     *
32
     * @return array
33
     */
34
    public function providerLocales()
35
    {
36
        return [
37
            ['af'],
38
            ['ar'],
39
            ['az'],
40
            ['bg'],
41
            ['bn'],
42
            ['ca'],
43
            ['cs'],
44
            ['da'],
45
            ['de'],
46
            ['el'],
47
            ['en'],
48
            ['eo'],
49
            ['es'],
50
            ['et'],
51
            ['eu'],
52
            ['fa'],
53
            ['fi'],
54
            ['fo'],
55
            ['fr'],
56
            ['he'],
57
            ['hr'],
58
            ['hu'],
59
            ['id'],
60
            ['it'],
61
            ['ja'],
62
            ['ko'],
63
            ['lt'],
64
            ['lv'],
65
            ['ms'],
66
            ['nl'],
67
            ['no'],
68
            ['pl'],
69
            ['pt'],
70
            ['pt_BR'],
71
            ['pt-BR'],
72
            ['ro'],
73
            ['ru'],
74
            ['sk'],
75
            ['sl'],
76
            ['sq'],
77
            ['sr'],
78
            ['sv'],
79
            ['th'],
80
            ['tr'],
81
            ['uk'],
82
            ['uz'],
83
            ['vi'],
84
            ['zh'],
85
            ['zh-TW'],
86
        ];
87
    }
88
89
    /**
90
     * @dataProvider providerLocales
91
     *
92
     * @param string $locale
93
     */
94
    public function testSetLocale($locale)
95
    {
96
        $this->assertTrue(Date::setLocale($locale));
97
        $this->assertSame($locale, Date::getLocale());
98
    }
99
100
    /**
101
     * @dataProvider providerLocales
102
     *
103
     * @param string $locale
104
     */
105 View Code Duplication
    public function testSetTranslator($locale)
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...
106
    {
107
        $t = new Translator($locale);
108
        $t->addLoader('array', new ArrayLoader());
109
        Date::setTranslator($t);
110
111
        $t = Date::getTranslator();
112
        $this->assertNotNull($t);
113
        $this->assertSame($locale, $t->getLocale());
114
    }
115
116
    public function testSetLocaleWithKnownLocale()
117
    {
118
        $this->assertTrue(Date::setLocale('fr'));
119
    }
120
121
    public function testSetLocaleWithUnknownLocale()
122
    {
123
        $this->assertFalse(Date::setLocale('zz'));
124
    }
125
}
126