Completed
Push — develop ( ec7312...1cf119 )
by Adrien
27:33
created

StringHelperTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 93
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 30
loc 93
rs 10
c 1
b 0
f 0
wmc 15
lcom 1
cbo 2

11 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
A testControlCharacterPHP2OOXML() 7 7 1
A testControlCharacterOOXML2PHP() 7 7 1
A testSYLKtoUTF8() 0 7 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
use PHPUnit_Framework_TestCase;
7
8
class StringHelperTest extends PHPUnit_Framework_TestCase
9
{
10
    public function setUp()
11
    {
12
        parent::setUp();
13
14
        // Reset Currency Code
15
        StringHelper::setCurrencyCode(null);
16
    }
17
18
    public function testGetIsIconvEnabled()
19
    {
20
        $result = StringHelper::getIsIconvEnabled();
21
        $this->assertTrue($result);
22
    }
23
24 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...
25
    {
26
        $localeconv = localeconv();
27
28
        $expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ',';
29
        $result = StringHelper::getDecimalSeparator();
30
        $this->assertEquals($expectedResult, $result);
31
    }
32
33
    public function testSetDecimalSeparator()
34
    {
35
        $expectedResult = ',';
36
        StringHelper::setDecimalSeparator($expectedResult);
37
38
        $result = StringHelper::getDecimalSeparator();
39
        $this->assertEquals($expectedResult, $result);
40
    }
41
42 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...
43
    {
44
        $localeconv = localeconv();
45
46
        $expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ',';
47
        $result = StringHelper::getThousandsSeparator();
48
        $this->assertEquals($expectedResult, $result);
49
    }
50
51
    public function testSetThousandsSeparator()
52
    {
53
        $expectedResult = ' ';
54
        StringHelper::setThousandsSeparator($expectedResult);
55
56
        $result = StringHelper::getThousandsSeparator();
57
        $this->assertEquals($expectedResult, $result);
58
    }
59
60
    public function testGetCurrencyCode()
61
    {
62
        $localeconv = localeconv();
63
        $expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$'));
64
        $result = StringHelper::getCurrencyCode();
65
        $this->assertEquals($expectedResult, $result);
66
    }
67
68
    public function testSetCurrencyCode()
69
    {
70
        $expectedResult = '£';
71
        StringHelper::setCurrencyCode($expectedResult);
72
73
        $result = StringHelper::getCurrencyCode();
74
        $this->assertEquals($expectedResult, $result);
75
    }
76
77 View Code Duplication
    public function testControlCharacterPHP2OOXML()
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...
78
    {
79
        $expectedResult = 'foo_x000B_bar';
80
        $result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar');
81
82
        $this->assertEquals($expectedResult, $result);
83
    }
84
85 View Code Duplication
    public function testControlCharacterOOXML2PHP()
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...
86
    {
87
        $expectedResult = 'foo' . chr(11) . 'bar';
88
        $result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar');
89
90
        $this->assertEquals($expectedResult, $result);
91
    }
92
93
    public function testSYLKtoUTF8()
94
    {
95
        $expectedResult = 'foo' . chr(11) . 'bar';
96
        $result = StringHelper::SYLKtoUTF8("foo\x1B ;bar");
97
98
        $this->assertEquals($expectedResult, $result);
99
    }
100
}
101