Completed
Push — develop ( 47d726...7b90bb )
by Adrien
17:12
created

StringTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 69
Duplicated Lines 23.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 69
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testGetIsIconvEnabled() 0 5 1
A testGetDecimalSeparator() 8 8 2
A testSetDecimalSeparator() 0 8 1
A testGetThousandsSeparator() 8 8 2
A testSetThousandsSeparator() 0 8 1
A testGetCurrencyCode() 0 7 3
A testSetCurrencyCode() 0 8 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 PhpOffice\PhpSpreadsheetTests\Shared;
4
5
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
6
7
class StringTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function setUp()
10
    {
11
        parent::setUp();
12
13
        // Reset Currency Code
14
        StringHelper::setCurrencyCode(null);
15
    }
16
17
    public function testGetIsIconvEnabled()
18
    {
19
        $result = StringHelper::getIsIconvEnabled();
20
        $this->assertTrue($result);
21
    }
22
23 View Code Duplication
    public function testGetDecimalSeparator()
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...
24
    {
25
        $localeconv = localeconv();
26
27
        $expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ',';
28
        $result = StringHelper::getDecimalSeparator();
29
        $this->assertEquals($expectedResult, $result);
30
    }
31
32
    public function testSetDecimalSeparator()
33
    {
34
        $expectedResult = ',';
35
        StringHelper::setDecimalSeparator($expectedResult);
36
37
        $result = StringHelper::getDecimalSeparator();
38
        $this->assertEquals($expectedResult, $result);
39
    }
40
41 View Code Duplication
    public function testGetThousandsSeparator()
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...
42
    {
43
        $localeconv = localeconv();
44
45
        $expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ',';
46
        $result = StringHelper::getThousandsSeparator();
47
        $this->assertEquals($expectedResult, $result);
48
    }
49
50
    public function testSetThousandsSeparator()
51
    {
52
        $expectedResult = ' ';
53
        StringHelper::setThousandsSeparator($expectedResult);
54
55
        $result = StringHelper::getThousandsSeparator();
56
        $this->assertEquals($expectedResult, $result);
57
    }
58
59
    public function testGetCurrencyCode()
60
    {
61
        $localeconv = localeconv();
62
        $expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$'));
63
        $result = StringHelper::getCurrencyCode();
64
        $this->assertEquals($expectedResult, $result);
65
    }
66
67
    public function testSetCurrencyCode()
68
    {
69
        $expectedResult = '£';
70
        StringHelper::setCurrencyCode($expectedResult);
71
72
        $result = StringHelper::getCurrencyCode();
73
        $this->assertEquals($expectedResult, $result);
74
    }
75
}
76