Completed
Branch feature/scrutinizer-run-tests (072b5a)
by Juliette
10:12
created

NewGroupUseDeclarationsSniffTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 12.94 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 6
c 4
b 1
f 1
lcom 1
cbo 1
dl 11
loc 85
rs 10

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
 * New use group declaration sniff tests
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New use group declaration sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class NewGroupUseDeclarationsSniffTest extends BaseSniffTest
17
{
18
19
    const TEST_FILE = 'sniff-examples/new_group_use_declarations.php';
20
21
    protected function setUp()
22
    {
23
        if (version_compare(PHP_CodeSniffer::VERSION, '2.3.4', '<')) {
24
            $this->markTestSkipped();
25
        }
26
        else {
27
            parent::setUp();
28
        }
29
    }
30
31
    /**
32
     * testGroupUseDeclaration
33
     *
34
     * @requires PHP 5.3
35
     *
36
     * @dataProvider dataGroupUseDeclaration
37
     *
38
     * @param int $line The line number.
39
     *
40
     * @return void
41
     */
42
    public function testGroupUseDeclaration($line)
43
    {
44
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
45
        $this->assertError($file, $line, 'Group use declarations are not allowed in PHP 5.6 or earlier');
46
47
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
48
        $this->assertNoViolation($file, $line);
49
    }
50
51
    /**
52
     * Data provider.
53
     *
54
     * @see testGroupUseDeclaration()
55
     *
56
     * @return array
57
     */
58
    public function dataGroupUseDeclaration()
59
    {
60
        return array(
61
            array(13),
62
            array(14),
63
        );
64
    }
65
66
67
    /**
68
     * testValidUseDeclaration
69
     *
70
     * @dataProvider dataValidUseDeclaration
71
     *
72
     * @param int $line The line number.
73
     *
74
     * @return void
75
     */
76
    public function testValidUseDeclaration($line)
77
    {
78
        $file = $this->sniffFile(self::TEST_FILE);
79
        $this->assertNoViolation($file, $line);
80
    }
81
82
    /**
83
     * Data provider.
84
     *
85
     * @see testValidUseDeclaration()
86
     *
87
     * @return array
88
     */
89
    public function dataValidUseDeclaration()
90
    {
91
        return array(
92
            array(4),
93
            array(5),
94
            array(6),
95
            array(8),
96
            array(9),
97
            array(10),
98
        );
99
    }
100
}
101