Completed
Pull Request — master (#291)
by Juliette
02:26
created

RemovedHashAlgorithmsSniff::getErrorMsgTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 * @copyright 2012 Cu.be Solutions bvba
11
 */
12
13
/**
14
 * PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff.
15
 *
16
 * Discourages the use of deprecated and removed hash algorithms.
17
 *
18
 * PHP version 5.4
19
 *
20
 * @category  PHP
21
 * @package   PHPCompatibility
22
 * @author    Wim Godden <[email protected]>
23
 * @copyright 2012 Cu.be Solutions bvba
24
 */
25
class PHPCompatibility_Sniffs_PHP_RemovedHashAlgorithmsSniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
    extends PHPCompatibility_AbstractRemovedFeatureSniff
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
27
{
28
29
    /**
30
     * A list of removed hash algorithms, which were present in older versions.
31
     *
32
     * The array lists : version number with false (deprecated) and true (removed).
33
     * If's sufficient to list the first version where the hash algorithm was deprecated/removed.
34
     *
35
     * @var array(string => array(string => bool))
36
     */
37
    protected $removedAlgorithms = array(
38
        'salsa10' => array(
39
            '5.4' => true,
40
        ),
41
        'salsa20' => array(
42
            '5.4' => true,
43
        ),
44
    );
45
46
    /**
47
     * Returns an array of tokens this test wants to listen for.
48
     *
49
     * @return array
50
     */
51
    public function register()
52
    {
53
        return array(T_STRING);
54
55
    }//end register()
56
57
58
    /**
59
     * Processes this test, when one of its tokens is encountered.
60
     *
61
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
62
     * @param int                  $stackPtr  The position of the current token in the
63
     *                                        stack passed in $tokens.
64
     *
65
     * @return void
66
     */
67
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
68
    {
69
        $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr);
70
        if (empty($algo) || is_string($algo) === false) {
71
            return;
72
        }
73
74
        // Bow out if not one of the algorithms we're targetting.
75
        if (isset($this->removedAlgorithms[$algo]) === false) {
76
            return;
77
        }
78
79
        $itemInfo = array(
80
            'name' => $algo,
81
        );
82
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
83
84
    }//end process()
85
86
87
    /**
88
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
89
     *
90
     * @param array $itemInfo Base information about the item.
91
     *
92
     * @return array Version and other information about the item.
93
     */
94
    public function getItemArray(array $itemInfo)
95
    {
96
        return $this->removedAlgorithms[$itemInfo['name']];
97
    }
98
99
100
    /**
101
     * Get the error message template for this sniff.
102
     *
103
     * @return string
104
     */
105
    protected function getErrorMsgTemplate()
106
    {
107
        return 'The %s hash algorithm is ';
108
    }
109
110
111
}//end class
112