Skip to content

Commit 6bd92be

Browse files
committedMay 11, 2023
ACP2E-1946: Move PHPCompatibility/PHPCompatibility sniffs into separate namespace
1 parent df39772 commit 6bd92be

File tree

56 files changed

+3077
-9716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3077
-9716
lines changed
 

Diff for: ‎Magento2/Internal/FileProxy.php

+465
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,14 @@
11
<?php
22
/**
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
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
95
*/
106

117
namespace Magento2\Sniffs\PHPCompatibility;
128

13-
use PHP_CodeSniffer\Files\File;
14-
use PHP_CodeSniffer\Util\Tokens;
15-
use PHPCompatibility\AbstractFunctionCallParameterSniff;
16-
use PHPCSUtils\BackCompat\BCTokens;
17-
189
/**
19-
* Detect calls to functions where the expected type of a parameter has been changed from integer to boolean.
20-
*
21-
* Throws an error when a hard-coded numeric value is passed.
22-
*
23-
* PHP version 8.0+
24-
*
25-
* @since 10.0.0
10+
* @inheritdoc
2611
*/
27-
class ChangedIntToBoolParamTypeSniff extends AbstractFunctionCallParameterSniff
12+
class ChangedIntToBoolParamTypeSniff extends \PHPCompatibility\Sniffs\ParameterValues\ChangedIntToBoolParamTypeSniff
2813
{
29-
30-
/**
31-
* Functions to check for.
32-
*
33-
* @since 10.0.0
34-
*
35-
* @var array
36-
*/
37-
protected $targetFunctions = [
38-
'ob_implicit_flush' => [
39-
1 => [
40-
'name' => 'flag',
41-
'since' => '8.0',
42-
],
43-
],
44-
'sem_get' => [
45-
4 => [
46-
'name' => 'auto_release',
47-
'since' => '8.0',
48-
],
49-
],
50-
];
51-
52-
/**
53-
* Do a version check to determine if this sniff needs to run at all.
54-
*
55-
* Checks against the first PHP version listed in the above array.
56-
*
57-
* @since 10.0.0
58-
*
59-
* @return bool
60-
*/
61-
protected function bowOutEarly()
62-
{
63-
return ($this->supportsAbove('8.0') === false);
64-
}
65-
66-
/**
67-
* Process the parameters of a matched function.
68-
*
69-
* @since 10.0.0
70-
*
71-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
72-
* @param int $stackPtr The position of the current token in the stack.
73-
* @param string $functionName The token content (function name) which was matched.
74-
* @param array $parameters Array with information about the parameters.
75-
*
76-
* @return int|void Integer stack pointer to skip forward or void to continue
77-
* normal file processing.
78-
*/
79-
public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
80-
{
81-
static $search;
82-
83-
if (isset($search) === false) {
84-
$search = [
85-
\T_LNUMBER => \T_LNUMBER,
86-
\T_DNUMBER => \T_DNUMBER,
87-
];
88-
$search += BCTokens::arithmeticTokens();
89-
$search += Tokens::$emptyTokens;
90-
}
91-
92-
$functionLC = \strtolower($functionName);
93-
$functionInfo = $this->targetFunctions[$functionLC];
94-
foreach ($functionInfo as $offset => $paramInfo) {
95-
if (isset($parameters[$offset]) === false) {
96-
continue;
97-
}
98-
99-
if ($this->supportsAbove($paramInfo['since']) === false) {
100-
continue;
101-
}
102-
103-
$target = $parameters[$offset];
104-
105-
$hasNonNumeric = $phpcsFile->findNext($search, $target['start'], ($target['end'] + 1), true);
106-
if ($hasNonNumeric !== false) {
107-
// Not a purely numerical value. Ignore.
108-
continue;
109-
}
110-
111-
$error = 'The $%s parameter of %s() expects a boolean value instead of an integer since PHP %s. Found: %s';
112-
$code = $this->stringToErrorCode($functionName . '_' . $paramInfo['name']) . 'NumericFound';
113-
$data = [
114-
$paramInfo['name'],
115-
$functionLC,
116-
$paramInfo['since'],
117-
$target['raw'],
118-
];
119-
120-
$phpcsFile->addError($error, $target['start'], $code, $data);
121-
}
122-
}
12314
}

0 commit comments

Comments
 (0)
Please sign in to comment.