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 2a50cc7

Browse filesBrowse files
committed
ACP2E-2635: Replace phpcompatibility/php-compatibility with magento/php-compatibility-fork
* Fix fatal error in MethodAnnotationStructureSniff when there is no comment preceding a function or class method
1 parent 6cbe6a3 commit 2a50cc7
Copy full SHA for 2a50cc7

File tree

Expand file treeCollapse file tree

7 files changed

+110
-28
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+110
-28
lines changed

‎.github/workflows/php.yml

Copy file name to clipboardExpand all lines: .github/workflows/php.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ jobs:
8989
run: composer install
9090

9191
- name: Run rector
92-
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/phpcompatibility/php-compatibility/PHPCSAliases.php
92+
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/magento/php-compatibility-fork/PHPCSAliases.php

‎Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
+23-4Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,33 @@ public function register()
5151
public function process(File $phpcsFile, $stackPtr)
5252
{
5353
$tokens = $phpcsFile->getTokens();
54-
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0);
55-
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0);
56-
$prevSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr, $commentEndPtr);
57-
if (!$commentStartPtr || $prevSemicolon) {
54+
$commentEndPtr = $stackPtr;
55+
$tokensToFind = [
56+
\T_SEMICOLON,
57+
\T_OPEN_CURLY_BRACKET,
58+
\T_CLOSE_CURLY_BRACKET,
59+
\T_ATTRIBUTE_END,
60+
\T_DOC_COMMENT_CLOSE_TAG
61+
];
62+
63+
do {
64+
$commentEndPtr = $phpcsFile->findPrevious($tokensToFind, $commentEndPtr - 1);
65+
if ($commentEndPtr !== false
66+
&& $tokens[$commentEndPtr]['code'] === \T_ATTRIBUTE_END
67+
&& isset($tokens[$commentEndPtr]['attribute_opener'])
68+
) {
69+
$commentEndPtr = $tokens[$commentEndPtr]['attribute_opener'];
70+
}
71+
} while ($commentEndPtr !== false && !in_array($tokens[$commentEndPtr]['code'], $tokensToFind, true));
72+
73+
if ($commentEndPtr === false || $tokens[$commentEndPtr]['code'] !== \T_DOC_COMMENT_CLOSE_TAG) {
5874
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
5975
return;
6076
}
6177

78+
$commentStartPtr = $tokens[$commentEndPtr]['comment_opener']
79+
?? $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $commentEndPtr - 1);
80+
6281
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
6382
$phpcsFile->addWarning(
6483
'Motivation behind the added @deprecated tag MUST be explained. '

‎Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc

Copy file name to clipboardExpand all lines: Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc
+53-1Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
function functionWithNoPrecedingDocBlock() {}
33
/**
44
* Class for method structure for annotations test cases
55
*/
@@ -398,3 +398,55 @@ class MethodAnnotationFixture
398398
return false;
399399
}
400400
}
401+
402+
/**
403+
* Class with comment
404+
*/
405+
class ClassWithDocBlock
406+
{
407+
private function methodWithNoDocBlock(): bool
408+
{
409+
return false;
410+
}
411+
412+
#[
413+
/**
414+
* This docBloc is not for the method but for the attribute
415+
*/
416+
\ReturnTypeWillChange
417+
]
418+
public function methodWithDocBlockInsideAttributesDelimiters(string $text): string
419+
{
420+
return $text;
421+
}
422+
423+
#[\ReturnTypeWillChange]
424+
public function methodWithAttributeAndNoDocBlock(string $text): string
425+
{
426+
return $text;
427+
}
428+
429+
/**
430+
* Short description.
431+
*
432+
* @param string $text
433+
* @return string
434+
*/
435+
#[\ReturnTypeWillChange]
436+
public function methodWithAttributeAndValidDocBlock(string $text): string
437+
{
438+
return $text;
439+
}
440+
441+
#[\ReturnTypeWillChange]
442+
/**
443+
* Short description.
444+
*
445+
* @param string $text
446+
* @return string
447+
*/
448+
public function methodWithAttributeAndValidDocBlock2(string $text): string
449+
{
450+
return $text;
451+
}
452+
}

‎Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php

Copy file name to clipboardExpand all lines: Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class MethodAnnotationStructureUnitTest extends AbstractSniffUnitTest
1515
public function getErrorList()
1616
{
1717
return [
18+
2 => 1,
1819
10 => 1,
1920
18 => 1,
2021
30 => 1,
@@ -40,6 +41,9 @@ public function getErrorList()
4041
289 => 1,
4142
298 => 1,
4243
396 => 1,
44+
407 => 1,
45+
418 => 1,
46+
424 => 1,
4347
];
4448
}
4549

‎Magento2/ruleset.xml

Copy file name to clipboardExpand all lines: Magento2/ruleset.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,6 @@
770770
<exclude name="PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound" />
771771
<!-- Following sniffs have an equivalent in PHPCS -->
772772
<exclude name="PHPCompatibility.Syntax.ForbiddenCallTimePassByReference" />
773-
<exclude name="PHPCompatibility.Keywords.ForbiddenNamesAsDeclared" />
773+
<exclude name="PHPCompatibility.Keywords.ForbiddenNames" />
774774
</rule>
775775
</ruleset>

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"AFL-3.0"
77
],
88
"type": "phpcodesniffer-standard",
9-
"version": "32",
9+
"version": "33",
1010
"require": {
1111
"php": "~8.1.0 || ~8.2.0",
1212
"webonyx/graphql-php": "^15.0",
1313
"ext-simplexml": "*",
1414
"ext-dom": "*",
15-
"phpcompatibility/php-compatibility": "^9.3",
1615
"squizlabs/php_codesniffer": "^3.6.1",
1716
"rector/rector": "^0.17.12",
18-
"phpcsstandards/phpcsutils": "^1.0.5"
17+
"phpcsstandards/phpcsutils": "^1.0.5",
18+
"magento/php-compatibility-fork": "^0.1"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.5.10",
@@ -36,8 +36,8 @@
3636
}
3737
},
3838
"scripts": {
39-
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility",
40-
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility"
39+
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility",
40+
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility"
4141
},
4242
"config": {
4343
"allow-plugins": {

‎composer.lock

Copy file name to clipboardExpand all lines: composer.lock
+23-16Lines changed: 23 additions & 16 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.