• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCompatibility / PHPCompatibility / 18854982515

27 Oct 2025 08:28PM UTC coverage: 98.401%. Remained the same
18854982515

push

github

web-flow
Merge pull request #1947 from PHPCompatibility/php-8.5/newfunctionparam-grapheme-locale

PHP 8.5 | NewFunctionParameters: detect use of grapheme_*() $locale (RFC)

9231 of 9381 relevant lines covered (98.4%)

37.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.56
/PHPCompatibility/Sniffs/FunctionUse/RemovedFunctionParametersSniff.php
1
<?php
2
/**
3
 * PHPCompatibility, an external standard for PHP_CodeSniffer.
4
 *
5
 * @package   PHPCompatibility
6
 * @copyright 2012-2020 PHPCompatibility Contributors
7
 * @license   https://opensource.org/licenses/LGPL-3.0 LGPL3
8
 * @link      https://github.com/PHPCompatibility/PHPCompatibility
9
 */
10

11
namespace PHPCompatibility\Sniffs\FunctionUse;
12

13
use PHPCompatibility\AbstractFunctionCallParameterSniff;
14
use PHPCompatibility\Helpers\ComplexVersionDeprecatedRemovedFeatureTrait;
15
use PHPCompatibility\Helpers\ScannedCode;
16
use PHP_CodeSniffer\Files\File;
17
use PHP_CodeSniffer\Util\Tokens;
18
use PHPCSUtils\Utils\MessageHelper;
19
use PHPCSUtils\Utils\PassedParameters;
20

21
/**
22
 * Detect use of deprecated/removed function parameters in calls to native PHP functions.
23
 *
24
 * PHP version All
25
 *
26
 * @link https://www.php.net/manual/en/doc.changelog.php
27
 *
28
 * @since 7.0.0
29
 * @since 7.1.0  Now extends the `AbstractRemovedFeatureSniff` instead of the base `Sniff` class.
30
 * @since 10.0.0 - Now extends the base `AbstractFunctionCallParameterSniff` class
31
 *                 and uses the `ComplexVersionNewFeatureTrait`.
32
 *               - This class is now `final`.
33
 */
34
final class RemovedFunctionParametersSniff extends AbstractFunctionCallParameterSniff
35
{
36
    use ComplexVersionDeprecatedRemovedFeatureTrait;
37

38
    /**
39
     * A list of removed function parameters, which were present in older versions.
40
     *
41
     * The array lists : version number with false (deprecated) and true (removed).
42
     * The index is the 1-based parameter position of the parameter in the parameter list.
43
     * If's sufficient to list the first version where the function parameter was deprecated/removed.
44
     *
45
     * The optional `callback` key can be used to pass a method name which should be called for an
46
     * additional check. The method will be passed the parameter info and should return true
47
     * if the notice should be thrown or false otherwise.
48
     *
49
     * @since 7.0.0
50
     * @since 7.0.2  Visibility changed from `public` to `protected`.
51
     * @since 9.3.0  Optional `callback` key.
52
     * @since 10.0.0 - The parameter offsets were changed from 0-based to 1-based.
53
     *               - The property was renamed from `$removedFunctionParameters` to `$targetFunctions`.
54
     *
55
     * @var array<string, array<int, array<string, bool|string>>>
56
     */
57
    protected $targetFunctions = [
58
        'curl_version' => [
59
            1 => [
60
                'name' => 'age',
61
                '7.4'  => false,
62
                '8.0'  => true,
63
            ],
64
        ],
65
        'define' => [
66
            3 => [
67
                'name' => 'case_insensitive',
68
                '7.3'  => false,
69
                '8.0'  => true,
70
            ],
71
        ],
72
        /*
73
         * Closely related to the `PHPCompatibility.ParameterValues.RemovedGetDefinedFunctionsExcludeDisabledFalse` sniff.
74
         * That sniff detects the change in PHP 8.0, this sniff detect the follow-up step of deprecating the parameter
75
         * completely in PHP 8.5.
76
         */
77
        'get_defined_functions' => [
78
            1 => [
79
                'name' => 'exclude_disabled',
80
                '8.5'  => false,
81
            ],
82
        ],
83
        'gmmktime' => [
84
            7 => [
85
                'name' => 'isDST',
86
                '5.1'  => false,
87
                '7.0'  => true,
88
            ],
89
        ],
90
        /*
91
         * For the below three functions, it's actually the 3rd parameter which has been deprecated.
92
         * However with positional arguments, this can only be detected by checking for the "old last" argument.
93
         * Note: this function explicitly does NOT support named parameters for the function
94
         * signature without this parameter, but that's not the concern of this sniff.
95
         */
96
        'imagefilledpolygon' => [
97
            4 => [
98
                'name' => 'num_points',
99
                '8.1'  => false,
100
            ],
101
        ],
102
        'imageopenpolygon' => [
103
            4 => [
104
                'name' => 'num_points',
105
                '8.1'  => false,
106
            ],
107
        ],
108
        'imagepolygon' => [
109
            4 => [
110
                'name' => 'num_points',
111
                '8.1'  => false,
112
            ],
113
        ],
114
        'imagerotate' => [
115
            4 => [
116
                'name' => 'ignore_transparent',
117
                '8.3'  => true,
118
            ],
119
        ],
120
        'imap_headerinfo' => [
121
            5 => [
122
                'name' => 'defaulthost',
123
                '8.0'  => true,
124
            ],
125
        ],
126
        'ldap_exop' => [
127
            5 => [
128
                'name'        => 'response_data',
129
                '8.4'         => false,
130
                'alternative' => 'the PHP 8.3+ ldap_exop_sync() function',
131
            ],
132
            6 => [
133
                'name'        => 'response_oid',
134
                '8.4'         => false,
135
                'alternative' => 'the PHP 8.3+ ldap_exop_sync() function',
136
            ],
137
        ],
138
        'ldap_first_attribute' => [
139
            3 => [
140
                'name'  => 'ber_identifier',
141
                '5.2.4' => true,
142
            ],
143
        ],
144
        'ldap_next_attribute' => [
145
            3 => [
146
                'name'  => 'ber_identifier',
147
                '5.2.4' => true,
148
            ],
149
        ],
150
        'mb_decode_numericentity' => [
151
            4 => [
152
                'name' => 'is_hex',
153
                '8.0'  => true,
154
            ],
155
        ],
156
        'mktime' => [
157
            7 => [
158
                'name' => 'isDST',
159
                '5.1'  => false,
160
                '7.0'  => true,
161
            ],
162
        ],
163
        'mysqli_get_client_info' => [
164
            1 => [
165
                'name' => 'mysql',
166
                '8.1'  => false,
167
            ],
168
        ],
169
        'mysqli_store_result' => [
170
            2 => [
171
                'name' => 'mode',
172
                '8.4'  => false,
173
            ],
174
        ],
175
        'odbc_do' => [
176
            3 => [
177
                'name' => 'flags',
178
                '8.0'  => true,
179
            ],
180
        ],
181
        'odbc_exec' => [
182
            3 => [
183
                'name' => 'flags',
184
                '8.0'  => true,
185
            ],
186
        ],
187
        'pg_connect' => [
188
            // These were already deprecated before, but version in which deprecation took place is unclear.
189
            3 => [
190
                'name' => 'options',
191
                '8.0'  => true,
192
            ],
193
            4 => [
194
                'name' => 'tty',
195
                '8.0'  => true,
196
            ],
197
            5 => [
198
                'name' => 'dbname',
199
                '8.0'  => true,
200
            ],
201
        ],
202
        'session_set_save_handler' => [
203
            3 => [
204
                'name'        => 'read',
205
                '8.4'         => false,
206
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
207
            ],
208
            4 => [
209
                'name'        => 'write',
210
                '8.4'         => false,
211
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
212
            ],
213
            5 => [
214
                'name'        => 'destroy',
215
                '8.4'         => false,
216
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
217
            ],
218
            6 => [
219
                'name'        => 'gc',
220
                '8.4'         => false,
221
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
222
            ],
223
            7 => [
224
                'name'        => 'create_sid',
225
                '8.4'         => false,
226
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
227
            ],
228
            8 => [
229
                'name'        => 'validate_sid',
230
                '8.4'         => false,
231
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
232
            ],
233
            9 => [
234
                'name'        => 'update_timestamp',
235
                '8.4'         => false,
236
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
237
            ],
238
        ],
239
    ];
240

241
    /**
242
     * Should the sniff bow out early for specific PHP versions ?
243
     *
244
     * @since 10.0.0
245
     *
246
     * @return bool
247
     */
248
    protected function bowOutEarly()
72✔
249
    {
250
        return false;
72✔
251
    }
252

253
    /**
254
     * Process the parameters of a matched function.
255
     *
256
     * @since 10.0.0
257
     *
258
     * @param \PHP_CodeSniffer\Files\File $phpcsFile    The file being scanned.
259
     * @param int                         $stackPtr     The position of the current token in the stack.
260
     * @param string                      $functionName The token content (function name) which was matched.
261
     * @param array                       $parameters   Array with information about the parameters.
262
     *
263
     * @return void
264
     */
265
    public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
72✔
266
    {
267
        $functionLc = \strtolower($functionName);
72✔
268

269
        foreach ($this->targetFunctions[$functionLc] as $offset => $parameterDetails) {
72✔
270
            $targetParam = PassedParameters::getParameterFromStack($parameters, $offset, $parameterDetails['name']);
72✔
271

272
            if ($targetParam !== false && $targetParam['clean'] !== '') {
72✔
273
                if (isset($parameterDetails['callback']) && \method_exists($this, $parameterDetails['callback'])) {
72✔
274
                    if ($this->{$parameterDetails['callback']}($phpcsFile, $targetParam) === false) {
×
275
                        continue;
×
276
                    }
277
                }
278

279
                $firstNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $targetParam['start'], ($targetParam['end'] + 1), true);
72✔
280

281
                $itemInfo = [
36✔
282
                    'name'   => $functionName,
72✔
283
                    'nameLc' => $functionLc,
72✔
284
                    'offset' => $offset,
72✔
285
                ];
54✔
286
                $this->handleFeature($phpcsFile, $firstNonEmpty, $itemInfo);
72✔
287
            }
18✔
288
        }
18✔
289
    }
36✔
290

291

292
    /**
293
     * Handle the retrieval of relevant information and - if necessary - throwing of an
294
     * error/warning for a matched item.
295
     *
296
     * @since 10.0.0
297
     *
298
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
299
     * @param int                         $stackPtr  The position of the relevant token in
300
     *                                               the stack.
301
     * @param array                       $itemInfo  Base information about the item.
302
     *
303
     * @return void
304
     */
305
    protected function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo)
72✔
306
    {
307
        $itemArray   = $this->targetFunctions[$itemInfo['nameLc']][$itemInfo['offset']];
72✔
308
        $versionInfo = $this->getVersionInfo($itemArray);
72✔
309
        $isError     = null;
72✔
310

311
        if (empty($versionInfo['removed']) === false
72✔
312
            && ScannedCode::shouldRunOnOrAbove($versionInfo['removed']) === true
72✔
313
        ) {
18✔
314
            $isError = true;
72✔
315
        } elseif (empty($versionInfo['deprecated']) === false
72✔
316
            && ScannedCode::shouldRunOnOrAbove($versionInfo['deprecated']) === true
72✔
317
        ) {
18✔
318
            $isError = false;
72✔
319

320
            // Reset the 'removed' info as it is not relevant for the current notice.
321
            $versionInfo['removed'] = '';
72✔
322
        }
18✔
323

324
        if (isset($isError) === false) {
72✔
325
            return;
56✔
326
        }
327

328
        $this->addMessage($phpcsFile, $stackPtr, $isError, $itemInfo, $itemArray, $versionInfo);
72✔
329
    }
36✔
330

331

332
    /**
333
     * Generates the error or warning for this item.
334
     *
335
     * @since 10.0.0
336
     *
337
     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
338
     * @param int                         $stackPtr    The position of the relevant token in
339
     *                                                 the stack.
340
     * @param bool                        $isError     Whether this should be an error or a warning.
341
     * @param array                       $itemInfo    Base information about the item.
342
     * @param array                       $itemArray   The sub-array with all the details about
343
     *                                                 this item.
344
     * @param string[]                    $versionInfo Array with detail (version) information
345
     *                                                 relevant to the item.
346
     *
347
     * @return void
348
     */
349
    protected function addMessage(File $phpcsFile, $stackPtr, $isError, array $itemInfo, array $itemArray, array $versionInfo)
72✔
350
    {
351
        // Overrule the default message template.
352
        $this->msgTemplate = 'The "%s" parameter for function %s() is ';
72✔
353

354
        $msgInfo = $this->getMessageInfo($itemInfo['name'], $itemInfo['nameLc'] . '_' . $itemArray['name'], $versionInfo);
72✔
355

356
        $data = $msgInfo['data'];
72✔
357
        \array_unshift($data, $itemArray['name']);
72✔
358

359
        MessageHelper::addMessage($phpcsFile, $msgInfo['message'], $stackPtr, $isError, $msgInfo['errorcode'], $data);
72✔
360
    }
36✔
361
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc