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

Sign up
Appearance settings

Commit d142dbb

Browse files
committed
Merge remote-tracking branch 'origin/develop' into AC-9670
2 parents 3b504d5 + 372d4c6 commit d142dbb

File tree

7 files changed

+113
-29
lines changed

7 files changed

+113
-29
lines changed

‎.github/workflows/php.yml‎

Lines 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‎

Lines changed: 24 additions & 5 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) {
58-
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
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) {
74+
$phpcsFile->addError('Comment block is missing', $stackPtr, 'NoCommentBlock');
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‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
functionfunctionWithNoPrecedingDocBlock() {}
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‎

Lines 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‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@
758758
<exclude-pattern>*/Test/*</exclude-pattern>
759759
<exclude-pattern>*Test.php</exclude-pattern>
760760
<exclude-pattern>*/PHPCSUtils/*</exclude-pattern>
761+
<!-- duplicates Magento2.Annotation.MethodAnnotationStructure.NoCommentBlock-->
762+
<exclude name="Magento2.Annotation.MethodArguments.NoCommentBlock"/>
761763
</rule>
762764

763765
<rule ref="Internal.NoCodeFound">
@@ -770,6 +772,6 @@
770772
<exclude name="PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound" />
771773
<!-- Following sniffs have an equivalent in PHPCS -->
772774
<exclude name="PHPCompatibility.Syntax.ForbiddenCallTimePassByReference" />
773-
<exclude name="PHPCompatibility.Keywords.ForbiddenNamesAsDeclared" />
775+
<exclude name="PHPCompatibility.Keywords.ForbiddenNames" />
774776
</rule>
775777
</ruleset>

‎composer.json‎

Lines 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 || ~8.3.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‎

Lines 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)

AltStyle によって変換されたページ (->オリジナル) /