ForHumansTest   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 113
Duplicated Lines 8.85 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetTranslator() 0 6 1
A testSetTranslator() 10 10 1
A testGetLocale() 0 5 1
A testSetLocale() 0 7 1
A testYear() 0 5 1
A testYearToString() 0 5 1
A testYears() 0 5 1
A testYearsAndMonth() 0 5 1
A testAll() 0 6 1
A testYearsAndMonthInFrench() 0 5 1
A testYearsAndMonthInGerman() 0 6 1
A testYearsAndMonthInBulgarian() 0 6 1
A testYearsAndMonthInCatalan() 0 6 1
A testYearsAndMonthInCzech() 0 6 1
A testYearsAndMonthInGreek() 0 6 1
A testYearsAndMonthsInDanish() 0 6 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\Interval;
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\Interval;
15
use HMLB\Date\Tests\AbstractTestCase;
16
use Symfony\Component\Translation\Loader\ArrayLoader;
17
use Symfony\Component\Translation\Translator;
18
19
class ForHumansTest extends AbstractTestCase
20
{
21
    public function testGetTranslator()
22
    {
23
        $t = Interval::getTranslator();
24
        $this->assertNotNull($t);
25
        $this->assertSame('en', $t->getLocale());
26
    }
27
28 View Code Duplication
    public function testSetTranslator()
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...
29
    {
30
        $t = new Translator('fr');
31
        $t->addLoader('array', new ArrayLoader());
32
        Interval::setTranslator($t);
33
34
        $t = Interval::getTranslator();
35
        $this->assertNotNull($t);
36
        $this->assertSame('fr', $t->getLocale());
37
    }
38
39
    public function testGetLocale()
40
    {
41
        Interval::setLocale('en');
42
        $this->assertSame('en', Interval::getLocale());
43
    }
44
45
    public function testSetLocale()
46
    {
47
        Interval::setLocale('en');
48
        $this->assertSame('en', Interval::getLocale());
49
        Interval::setLocale('fr');
50
        $this->assertSame('fr', Interval::getLocale());
51
    }
52
53
    public function testYear()
54
    {
55
        Interval::setLocale('en');
56
        $this->assertSame('1 year', Interval::year()->forHumans());
57
    }
58
59
    public function testYearToString()
60
    {
61
        Interval::setLocale('en');
62
        $this->assertSame('1 year:abc', Interval::year().':abc');
63
    }
64
65
    public function testYears()
66
    {
67
        Interval::setLocale('en');
68
        $this->assertSame('2 years', Interval::years(2)->forHumans());
69
    }
70
71
    public function testYearsAndMonth()
72
    {
73
        Interval::setLocale('en');
74
        $this->assertSame('2 years 1 month', Interval::create(2, 1)->forHumans());
75
    }
76
77
    public function testAll()
78
    {
79
        Interval::setLocale('en');
80
        $ci = Interval::create(11, 1, 2, 5, 22, 33, 55)->forHumans();
81
        $this->assertSame('11 years 1 month 2 weeks 5 days 22 hours 33 minutes 55 seconds', $ci);
82
    }
83
84
    public function testYearsAndMonthInFrench()
85
    {
86
        Interval::setLocale('fr');
87
        $this->assertSame('2 ans 1 mois', Interval::create(2, 1)->forHumans());
88
    }
89
90
    public function testYearsAndMonthInGerman()
91
    {
92
        Interval::setLocale('de');
93
        $this->assertSame('1 Jahr 1 Monat', Interval::create(1, 1)->forHumans());
94
        $this->assertSame('2 Jahre 1 Monat', Interval::create(2, 1)->forHumans());
95
    }
96
97
    public function testYearsAndMonthInBulgarian()
98
    {
99
        Interval::setLocale('bg');
100
        $this->assertSame('1 година 1 месец', Interval::create(1, 1)->forHumans());
101
        $this->assertSame('2 години 1 месец', Interval::create(2, 1)->forHumans());
102
    }
103
104
    public function testYearsAndMonthInCatalan()
105
    {
106
        Interval::setLocale('ca');
107
        $this->assertSame('1 any 1 mes', Interval::create(1, 1)->forHumans());
108
        $this->assertSame('2 anys 1 mes', Interval::create(2, 1)->forHumans());
109
    }
110
111
    public function testYearsAndMonthInCzech()
112
    {
113
        Interval::setLocale('cs');
114
        $this->assertSame('1 rok 1 měsíc', Interval::create(1, 1)->forHumans());
115
        $this->assertSame('2 roky 1 měsíc', Interval::create(2, 1)->forHumans());
116
    }
117
118
    public function testYearsAndMonthInGreek()
119
    {
120
        Interval::setLocale('el');
121
        $this->assertSame('1 χρόνος 1 μήνας', Interval::create(1, 1)->forHumans());
122
        $this->assertSame('2 χρόνια 1 μήνας', Interval::create(2, 1)->forHumans());
123
    }
124
125
    public function testYearsAndMonthsInDanish()
126
    {
127
        Interval::setLocale('da');
128
        $this->assertSame('1 år 1 måned', Interval::create(1, 1)->forHumans());
129
        $this->assertSame('2 år 1 måned', Interval::create(2, 1)->forHumans());
130
    }
131
}
132