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

PHPCompatibility / PHPCompatibility / 18855743835

27 Oct 2025 08:59PM UTC coverage: 98.424%. Remained the same
18855743835

push

github

web-flow
Merge pull request #1958 from PHPCompatibility/php-8.5/newfunctionparam-openssl-functions

PHP 8.5 | NewFunctionParameters: detect use of new openssl_*() params

9369 of 9519 relevant lines covered (98.42%)

37.36 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
        'openssl_pkey_derive' => [
188
            3 => [
189
                'name' => 'key_length',
190
                '8.5'  => false,
191
            ],
192
        ],
193
        'pg_connect' => [
194
            // These were already deprecated before, but version in which deprecation took place is unclear.
195
            3 => [
196
                'name' => 'options',
197
                '8.0'  => true,
198
            ],
199
            4 => [
200
                'name' => 'tty',
201
                '8.0'  => true,
202
            ],
203
            5 => [
204
                'name' => 'dbname',
205
                '8.0'  => true,
206
            ],
207
        ],
208
        'session_set_save_handler' => [
209
            3 => [
210
                'name'        => 'read',
211
                '8.4'         => false,
212
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
213
            ],
214
            4 => [
215
                'name'        => 'write',
216
                '8.4'         => false,
217
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
218
            ],
219
            5 => [
220
                'name'        => 'destroy',
221
                '8.4'         => false,
222
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
223
            ],
224
            6 => [
225
                'name'        => 'gc',
226
                '8.4'         => false,
227
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
228
            ],
229
            7 => [
230
                'name'        => 'create_sid',
231
                '8.4'         => false,
232
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
233
            ],
234
            8 => [
235
                'name'        => 'validate_sid',
236
                '8.4'         => false,
237
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
238
            ],
239
            9 => [
240
                'name'        => 'update_timestamp',
241
                '8.4'         => false,
242
                'alternative' => 'a SessionHandlerInterface implementation for the callbacks instead',
243
            ],
244
        ],
245
    ];
246

247
    /**
248
     * Should the sniff bow out early for specific PHP versions ?
249
     *
250
     * @since 10.0.0
251
     *
252
     * @return bool
253
     */
254
    protected function bowOutEarly()
72✔
255
    {
256
        return false;
72✔
257
    }
258

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

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

278
            if ($targetParam !== false && $targetParam['clean'] !== '') {
72✔
279
                if (isset($parameterDetails['callback']) && \method_exists($this, $parameterDetails['callback'])) {
72✔
280
                    if ($this->{$parameterDetails['callback']}($phpcsFile, $targetParam) === false) {
×
281
                        continue;
×
282
                    }
283
                }
284

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

287
                $itemInfo = [
36✔
288
                    'name'   => $functionName,
72✔
289
                    'nameLc' => $functionLc,
72✔
290
                    'offset' => $offset,
72✔
291
                ];
54✔
292
                $this->handleFeature($phpcsFile, $firstNonEmpty, $itemInfo);
72✔
293
            }
18✔
294
        }
18✔
295
    }
36✔
296

297

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

317
        if (empty($versionInfo['removed']) === false
72✔
318
            && ScannedCode::shouldRunOnOrAbove($versionInfo['removed']) === true
72✔
319
        ) {
18✔
320
            $isError = true;
72✔
321
        } elseif (empty($versionInfo['deprecated']) === false
72✔
322
            && ScannedCode::shouldRunOnOrAbove($versionInfo['deprecated']) === true
72✔
323
        ) {
18✔
324
            $isError = false;
72✔
325

326
            // Reset the 'removed' info as it is not relevant for the current notice.
327
            $versionInfo['removed'] = '';
72✔
328
        }
18✔
329

330
        if (isset($isError) === false) {
72✔
331
            return;
56✔
332
        }
333

334
        $this->addMessage($phpcsFile, $stackPtr, $isError, $itemInfo, $itemArray, $versionInfo);
72✔
335
    }
36✔
336

337

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

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

362
        $data = $msgInfo['data'];
72✔
363
        \array_unshift($data, $itemArray['name']);
72✔
364

365
        MessageHelper::addMessage($phpcsFile, $msgInfo['message'], $stackPtr, $isError, $msgInfo['errorcode'], $data);
72✔
366
    }
36✔
367
}
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