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

RemovedHashAlgorithmsSniffTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 15.73 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 14
loc 89
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
 * Removed hash algorithms sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Removed hash algorithms sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class RemovedHashAlgorithmsSniffTest extends BaseSniffTest
17
{
18
    /**
19
     * Sniffed file
20
     *
21
     * @var PHP_CodeSniffer_File
22
     */
23
    protected $_sniffFile;
24
25
    /**
26
     * setUp
27
     *
28
     * @return void
29
     */
30
    public function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->_sniffFile = $this->sniffFile('sniff-examples/removed_hash_algorithms.php');
35
    }
36
37
    /**
38
     * testRemovedHashAlgorithms
39
     *
40
     * @dataProvider dataRemovedHashAlgorithms
41
     *
42
     * @param int $line Line number on which an error should occur.
43
     *
44
     * @return void
45
     */
46
    public function testRemovedHashAlgorithms($line)
47
    {
48
        $this->assertError($this->_sniffFile, $line, 'The Salsa10 and Salsa20 hash algorithms have been removed since PHP 5.4');
49
    }
50
51
    /**
52
     * dataRemovedHashAlgorithms
53
     *
54
     * @see testRemovedHashAlgorithms()
55
     *
56
     * @return array
57
     */
58
    public function dataRemovedHashAlgorithms()
59
    {
60
        return array(
61
            array(4),
62
            array(5),
63
            array(6),
64
            array(7),
65
            array(9),
66
            array(11),
67
            array(13),
68
            array(15),
69
            array(16),
70
        );
71
    }
72
73
74
    /**
75
     * testOkHashAlgorithm
76
     *
77
     * @return void
78
     */
79
    public function testOkHashAlgorithm()
80
    {
81
        $this->assertNoViolation($this->_sniffFile, 3);
82
    }
83
84
    /**
85
     * testIgnoreSecondParameter
86
     *
87
     * @return void
88
     */
89
    public function testIgnoreSecondParameter()
90
    {
91
        $this->assertNoViolation($this->_sniffFile, 17);
92
    }
93
94
    /**
95
     * testIgnoreNonFunctionCall
96
     *
97
     * @return void
98
     */
99
    public function testIgnoreNonFunctionCall()
100
    {
101
        $this->assertNoViolation($this->_sniffFile, 18);
102
    }
103
104
}
105