Skip to content

Commit 7aef678

Browse files
authored
Merge pull request #253 from magento-l3/ACP2E-2635
ACP2E-2635: Replace phpcompatibility/php-compatibility with magento/php-compatibility-fork
2 parents 6cbe6a3 + 2a50cc7 commit 7aef678

File tree

7 files changed

+110
-28
lines changed

7 files changed

+110
-28
lines changed

Diff for: .github/workflows/php.yml

+1-1
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

Diff for: Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php

+23-4
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. '

Diff for: Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc

+53-1
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+
}

Diff for: Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php

+4
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

Diff for: Magento2/ruleset.xml

+1-1
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>

Diff for: composer.json

+5-5
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": {

Diff for: composer.lock

+23-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)