Skip to content

Commit 2e02cb9

Browse files
committed
AC-2219: Removed autofixing suggestion for mb_check_encoding
1 parent 480fa81 commit 2e02cb9

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FunctionsDeprecatedWithoutArgumentSniff implements Sniff
3636
* @var array
3737
*/
3838
private const DEPRECATED_FUNCTIONS_AND_FIXES = [
39-
'mb_check_encoding' => 'STDIN',
39+
'mb_check_encoding' => false,
4040
'get_class' => '$this',
4141
'get_parent_class' => '$this'
4242
];
@@ -65,17 +65,27 @@ public function process(File $phpcsFile, $stackPtr): void
6565

6666
$functionName = $phpcsFile->getTokensAsString($phpcsFile->findPrevious(T_STRING, $stackPtr), 1);
6767

68-
if (in_array($functionName, array_keys(self::DEPRECATED_FUNCTIONS_AND_FIXES))) {
69-
if ($phpcsFile->addFixableWarning(
68+
if (!isset(self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName])) {
69+
return;
70+
}
71+
72+
if (self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName] === false) {
73+
$phpcsFile->addWarning(
74+
sprintf(self::WARNING_MESSAGE, $functionName),
75+
$stackPtr,
76+
self::WARNING_CODE
77+
);
78+
}
79+
80+
if ($phpcsFile->addFixableWarning(
7081
sprintf(self::WARNING_MESSAGE, $functionName),
7182
$stackPtr,
7283
self::WARNING_CODE
7384
) === true) {
74-
$content = self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName];
75-
$phpcsFile->fixer->beginChangeset();
76-
$phpcsFile->fixer->addContentBefore($phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr), $content);
77-
$phpcsFile->fixer->endChangeset();
78-
}
85+
$content = self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName];
86+
$phpcsFile->fixer->beginChangeset();
87+
$phpcsFile->fixer->addContentBefore($phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr), $content);
88+
$phpcsFile->fixer->endChangeset();
7989
}
8090
}
8191
}

Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.inc.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FunctionsDeprecatedWithoutArgument
2020
public function testDeprecatedMethod(): array
2121
{
2222
return [
23-
mb_check_encoding(STDIN), // Calling without argument is deprecated.
23+
mb_check_encoding(), // Calling without argument is deprecated.
2424
mb_check_encoding('test-argument'),
2525
get_class($this), // Calling without argument is deprecated.
2626
get_class(new FunctionsDeprecatedWithoutArgument()),

0 commit comments

Comments
 (0)