Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73d4423

Browse filesBrowse files
authored
Merge pull request #163 from magento-commerce/develop
Develop to master v19
2 parents 1e62380 + 235640e commit 73d4423
Copy full SHA for 73d4423
Expand file treeCollapse file tree

6 files changed

+73
-21
lines changed

‎Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php
+29-8Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ class FunctionsDeprecatedWithoutArgumentSniff implements Sniff
3131
private const WARNING_CODE = 'FunctionsDeprecatedWithoutArgument';
3232

3333
/**
34-
* Deprecated functions without argument.
34+
* Deprecated functions without argument https://wiki.php.net/rfc/deprecations_php_8_1
3535
*
3636
* @var array
3737
*/
38-
private const FUNCTIONS_LIST = [
39-
'mb_check_encoding',
40-
'get_class',
41-
'get_parent_class',
42-
'get_called_class'
38+
private const DEPRECATED_FUNCTIONS_AND_FIXES = [
39+
'mb_check_encoding' => false,
40+
'get_class' => '$this',
41+
'get_parent_class' => '$this'
4342
];
4443

4544
/**
@@ -66,8 +65,30 @@ public function process(File $phpcsFile, $stackPtr): void
6665

6766
$functionName = $phpcsFile->getTokensAsString($phpcsFile->findPrevious(T_STRING, $stackPtr), 1);
6867

69-
if (in_array($functionName, self::FUNCTIONS_LIST)) {
70-
$phpcsFile->addWarning(sprintf(self::WARNING_MESSAGE, $functionName), $stackPtr, self::WARNING_CODE);
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+
return;
79+
}
80+
81+
$fix = $phpcsFile->addFixableWarning(
82+
sprintf(self::WARNING_MESSAGE, $functionName),
83+
$stackPtr,
84+
self::WARNING_CODE
85+
);
86+
87+
if ($fix === true) {
88+
$content = self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName];
89+
$phpcsFile->fixer->beginChangeset();
90+
$phpcsFile->fixer->addContentBefore($phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr), $content);
91+
$phpcsFile->fixer->endChangeset();
7192
}
7293
}
7394
}

‎Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.inc

Copy file name to clipboardExpand all lines: Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.inc
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ class FunctionsDeprecatedWithoutArgument
2121
{
2222
return [
2323
mb_check_encoding(), // Calling without argument is deprecated.
24-
mb_check_encoding('test-argument', null),
24+
mb_check_encoding('test-argument'),
2525
get_class(), // Calling without argument is deprecated.
2626
get_class(new FunctionsDeprecatedWithoutArgument()),
2727
get_parent_class(), // Calling without argument is deprecated.
28-
get_parent_class('test-argument'),
29-
get_called_class(), // Calling without argument is deprecated.
30-
get_called_class('test-argument')
28+
get_parent_class(new FunctionsDeprecatedWithoutArgument())
3129
];
3230
}
3331
}
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Tests\Functions;
9+
10+
/**
11+
* Class to test validate PHP functions usage of which without passing arguments.
12+
*/
13+
class FunctionsDeprecatedWithoutArgument
14+
{
15+
/**
16+
* Test deprecation function.
17+
*
18+
* @return array
19+
*/
20+
public function testDeprecatedMethod(): array
21+
{
22+
return [
23+
mb_check_encoding(), // Calling without argument is deprecated.
24+
mb_check_encoding('test-argument'),
25+
get_class($this), // Calling without argument is deprecated.
26+
get_class(new FunctionsDeprecatedWithoutArgument()),
27+
get_parent_class($this), // Calling without argument is deprecated.
28+
get_parent_class(new FunctionsDeprecatedWithoutArgument())
29+
];
30+
}
31+
}

‎Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.php

Copy file name to clipboardExpand all lines: Magento2/Tests/Functions/FunctionsDeprecatedWithoutArgumentUnitTest.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function getWarningList(): array
3030
return [
3131
23 => 1,
3232
25 => 1,
33-
27 => 1,
34-
29 => 1
33+
27 => 1
3534
];
3635
}
3736
}

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"AFL-3.0"
77
],
88
"type": "phpcodesniffer-standard",
9-
"version": "18",
9+
"version": "19",
1010
"require": {
1111
"php": ">=7.3",
1212
"webonyx/graphql-php": "^14.9",

‎composer.lock

Copy file name to clipboardExpand all lines: composer.lock
+9-6Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.