Completed
Push — master ( a32632...c637b7 )
by Juliette
9s
created

DeprecatedIniDirectivesSniff::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 39
Code Lines 23

Duplication

Lines 39
Ratio 100 %

Importance

Changes 0
Metric Value
dl 39
loc 39
rs 8.439
c 0
b 0
f 0
cc 5
eloc 23
nc 5
nop 2
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff.
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_DeprecatedIniDirectivesSniff.
15
 *
16
 * Discourages the use of deprecated INI directives through ini_set() or ini_get().
17
 *
18
 * @category  PHP
19
 * @package   PHPCompatibility
20
 * @author    Wim Godden <[email protected]>
21
 * @copyright 2012 Cu.be Solutions bvba
22
 */
23
class PHPCompatibility_Sniffs_PHP_DeprecatedIniDirectivesSniff extends PHPCompatibility_AbstractRemovedFeatureSniff
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...
24
{
25
    /**
26
     * A list of deprecated INI directives.
27
     *
28
     * The array lists : version number with false (deprecated) and true (removed).
29
     * If's sufficient to list the first version where the ini directive was deprecated/removed.
30
     *
31
     * @var array(string)
32
     */
33
    protected $deprecatedIniDirectives = array(
34
        'fbsql.batchSize' => array(
35
            '5.1' => true,
36
            'alternative' => 'fbsql.batchsize',
37
        ),
38
39
        'ifx.allow_persistent' => array(
40
            '5.2.1' => true
41
        ),
42
        'ifx.blobinfile' => array(
43
            '5.2.1' => true
44
        ),
45
        'ifx.byteasvarchar' => array(
46
            '5.2.1' => true
47
        ),
48
        'ifx.charasvarchar' => array(
49
            '5.2.1' => true
50
        ),
51
        'ifx.default_host' => array(
52
            '5.2.1' => true
53
        ),
54
        'ifx.default_password' => array(
55
            '5.2.1' => true
56
        ),
57
        'ifx.default_user' => array(
58
            '5.2.1' => true
59
        ),
60
        'ifx.max_links' => array(
61
            '5.2.1' => true
62
        ),
63
        'ifx.max_persistent' => array(
64
            '5.2.1' => true
65
        ),
66
        'ifx.nullformat' => array(
67
            '5.2.1' => true
68
        ),
69
        'ifx.textasvarchar' => array(
70
            '5.2.1' => true
71
        ),
72
73
        'zend.ze1_compatibility_mode' => array(
74
            '5.3' => true,
75
        ),
76
77
        'allow_call_time_pass_reference' => array(
78
            '5.3' => false,
79
            '5.4' => true
80
        ),
81
        'define_syslog_variables' => array(
82
            '5.3' => false,
83
            '5.4' => true
84
        ),
85
        'detect_unicode' => array(
86
            '5.4'         => true,
87
            'alternative' => 'zend.detect_unicode',
88
        ),
89
        'highlight.bg' => array(
90
            '5.3' => false,
91
            '5.4' => true
92
        ),
93
        'magic_quotes_gpc' => array(
94
            '5.3' => false,
95
            '5.4' => true
96
        ),
97
        'magic_quotes_runtime' => array(
98
            '5.3' => false,
99
            '5.4' => true
100
        ),
101
        'magic_quotes_sybase' => array(
102
            '5.3' => false,
103
            '5.4' => true
104
        ),
105
        'mbstring.script_encoding' => array(
106
            '5.4'         => true,
107
            'alternative' => 'zend.script_encoding',
108
        ),
109
        'register_globals' => array(
110
            '5.3' => false,
111
            '5.4' => true
112
        ),
113
        'register_long_arrays' => array(
114
            '5.3' => false,
115
            '5.4' => true
116
        ),
117
        'safe_mode' => array(
118
            '5.3' => false,
119
            '5.4' => true
120
        ),
121
        'safe_mode_allowed_env_vars' => array(
122
            '5.3' => false,
123
            '5.4' => true
124
        ),
125
        'safe_mode_exec_dir' => array(
126
            '5.3' => false,
127
            '5.4' => true
128
        ),
129
        'safe_mode_gid' => array(
130
            '5.3' => false,
131
            '5.4' => true
132
        ),
133
        'safe_mode_include_dir' => array(
134
            '5.3' => false,
135
            '5.4' => true
136
        ),
137
        'safe_mode_protected_env_vars' => array(
138
            '5.3' => false,
139
            '5.4' => true
140
        ),
141
        'session.bug_compat_42' => array(
142
            '5.3' => false,
143
            '5.4' => true
144
        ),
145
        'session.bug_compat_warn' => array(
146
            '5.3' => false,
147
            '5.4' => true
148
        ),
149
        'y2k_compliance' => array(
150
            '5.3' => false,
151
            '5.4' => true
152
        ),
153
154
        'always_populate_raw_post_data' => array(
155
            '5.6' => false,
156
            '7.0' => true
157
        ),
158
        'iconv.input_encoding' => array(
159
            '5.6' => false
160
        ),
161
        'iconv.output_encoding' => array(
162
            '5.6' => false
163
        ),
164
        'iconv.internal_encoding' => array(
165
            '5.6' => false
166
        ),
167
        'mbstring.http_input' => array(
168
            '5.6' => false
169
        ),
170
        'mbstring.http_output' => array(
171
            '5.6' => false
172
        ),
173
        'mbstring.internal_encoding' => array(
174
            '5.6' => false
175
        ),
176
177
        'asp_tags' => array(
178
            '7.0' => true
179
        ),
180
        'xsl.security_prefs' => array(
181
            '7.0' => true
182
        ),
183
184
        'mcrypt.algorithms_dir' => array(
185
            '7.1' => false
186
        ),
187
        'mcrypt.modes_dir' => array(
188
            '7.1' => false
189
        ),
190
        'session.entropy_file' => array(
191
            '7.1' => true
192
        ),
193
        'session.entropy_length' => array(
194
            '7.1' => true
195
        ),
196
        'session.hash_function' => array(
197
            '7.1' => true
198
        ),
199
        'session.hash_bits_per_character' => array(
200
            '7.1' => true
201
        ),
202
    );
203
204
    /**
205
     * Returns an array of tokens this test wants to listen for.
206
     *
207
     * @return array
208
     */
209
    public function register()
210
    {
211
        return array(T_STRING);
212
213
    }//end register()
214
215
    /**
216
     * Processes this test, when one of its tokens is encountered.
217
     *
218
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
219
     * @param int                  $stackPtr  The position of the current token in the
220
     *                                        stack passed in $tokens.
221
     *
222
     * @return void
223
     */
224 View Code Duplication
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
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...
225
    {
226
        $tokens = $phpcsFile->getTokens();
227
228
        $ignore = array(
229
                   T_DOUBLE_COLON,
230
                   T_OBJECT_OPERATOR,
231
                   T_FUNCTION,
232
                   T_CONST,
233
                  );
234
235
        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
236
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
237
            // Not a call to a PHP function.
238
            return;
239
        }
240
241
        $functionLc = strtolower($tokens[$stackPtr]['content']);
242
        if (isset($this->iniFunctions[$functionLc]) === false) {
243
            return;
244
        }
245
246
        $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]);
247
        if ($iniToken === false) {
248
            return;
249
        }
250
251
        $filteredToken = $this->stripQuotes($iniToken['raw']);
252
        if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) {
253
            return;
254
        }
255
256
        $itemInfo = array(
257
            'name'       => $filteredToken,
258
            'functionLc' => $functionLc,
259
        );
260
        $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo);
261
262
    }//end process()
263
264
265
    /**
266
     * Get the relevant sub-array for a specific item from a multi-dimensional array.
267
     *
268
     * @param array $itemInfo Base information about the item.
269
     *
270
     * @return array Version and other information about the item.
271
     */
272
    public function getItemArray(array $itemInfo)
273
    {
274
        return $this->deprecatedIniDirectives[$itemInfo['name']];
275
    }
276
277
278
    /**
279
     * Retrieve the relevant detail (version) information for use in an error message.
280
     *
281
     * @param array $itemArray Version and other information about the item.
282
     * @param array $itemInfo  Base information about the item.
283
     *
284
     * @return array
285
     */
286
    public function getErrorInfo(array $itemArray, array $itemInfo)
287
    {
288
        $errorInfo = parent::getErrorInfo($itemArray, $itemInfo);
289
290
        // Lower error level to warning if the function used was ini_get.
291 View Code Duplication
        if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
292
            $errorInfo['error'] = false;
293
        }
294
295
        return $errorInfo;
296
    }
297
298
299
    /**
300
     * Get the error message template for this sniff.
301
     *
302
     * @return string
303
     */
304
    protected function getErrorMsgTemplate()
305
    {
306
        return "INI directive '%s' is ";
307
    }
308
309
310
    /**
311
     * Get the error message template for suggesting an alternative for a specific sniff.
312
     *
313
     * @return string
314
     */
315
    protected function getAlternativeOptionTemplate()
316
    {
317
        return str_replace("%s", "'%s'", parent::getAlternativeOptionTemplate());
318
    }
319
320
321
}//end class
322