Skip to content

Commit

Permalink
Merge pull request #253 from magento-l3/ACP2E-2635
Browse files Browse the repository at this point in the history
ACP2E-2635: Replace phpcompatibility/php-compatibility with magento/php-compatibility-fork
  • Loading branch information
victor-v-rad authored Dec 1, 2023
2 parents 6cbe6a3 + 2a50cc7 commit 7aef678
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ jobs:
run: composer install

- name: Run rector
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
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
27 changes: 23 additions & 4 deletions Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,33 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0);
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0);
$prevSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr, $commentEndPtr);
if (!$commentStartPtr || $prevSemicolon) {
$commentEndPtr = $stackPtr;
$tokensToFind = [
\T_SEMICOLON,
\T_OPEN_CURLY_BRACKET,
\T_CLOSE_CURLY_BRACKET,
\T_ATTRIBUTE_END,
\T_DOC_COMMENT_CLOSE_TAG
];

do {
$commentEndPtr = $phpcsFile->findPrevious($tokensToFind, $commentEndPtr - 1);
if ($commentEndPtr !== false
&& $tokens[$commentEndPtr]['code'] === \T_ATTRIBUTE_END
&& isset($tokens[$commentEndPtr]['attribute_opener'])
) {
$commentEndPtr = $tokens[$commentEndPtr]['attribute_opener'];
}
} while ($commentEndPtr !== false && !in_array($tokens[$commentEndPtr]['code'], $tokensToFind, true));

if ($commentEndPtr === false || $tokens[$commentEndPtr]['code'] !== \T_DOC_COMMENT_CLOSE_TAG) {
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
return;
}

$commentStartPtr = $tokens[$commentEndPtr]['comment_opener']
?? $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $commentEndPtr - 1);

if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
$phpcsFile->addWarning(
'Motivation behind the added @deprecated tag MUST be explained. '
Expand Down
54 changes: 53 additions & 1 deletion Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

function functionWithNoPrecedingDocBlock() {}
/**
* Class for method structure for annotations test cases
*/
Expand Down Expand Up @@ -398,3 +398,55 @@ class MethodAnnotationFixture
return false;
}
}

/**
* Class with comment
*/
class ClassWithDocBlock
{
private function methodWithNoDocBlock(): bool
{
return false;
}

#[
/**
* This docBloc is not for the method but for the attribute
*/
\ReturnTypeWillChange
]
public function methodWithDocBlockInsideAttributesDelimiters(string $text): string
{
return $text;
}

#[\ReturnTypeWillChange]
public function methodWithAttributeAndNoDocBlock(string $text): string
{
return $text;
}

/**
* Short description.
*
* @param string $text
* @return string
*/
#[\ReturnTypeWillChange]
public function methodWithAttributeAndValidDocBlock(string $text): string
{
return $text;
}

#[\ReturnTypeWillChange]
/**
* Short description.
*
* @param string $text
* @return string
*/
public function methodWithAttributeAndValidDocBlock2(string $text): string
{
return $text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MethodAnnotationStructureUnitTest extends AbstractSniffUnitTest
public function getErrorList()
{
return [
2 => 1,
10 => 1,
18 => 1,
30 => 1,
Expand All @@ -40,6 +41,9 @@ public function getErrorList()
289 => 1,
298 => 1,
396 => 1,
407 => 1,
418 => 1,
424 => 1,
];
}

Expand Down
2 changes: 1 addition & 1 deletion Magento2/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,6 @@
<exclude name="PHPCompatibility.Miscellaneous.RemovedAlternativePHPTags.MaybeASPOpenTagFound" />
<!-- Following sniffs have an equivalent in PHPCS -->
<exclude name="PHPCompatibility.Syntax.ForbiddenCallTimePassByReference" />
<exclude name="PHPCompatibility.Keywords.ForbiddenNamesAsDeclared" />
<exclude name="PHPCompatibility.Keywords.ForbiddenNames" />
</rule>
</ruleset>
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"AFL-3.0"
],
"type": "phpcodesniffer-standard",
"version": "32",
"version": "33",
"require": {
"php": "~8.1.0 || ~8.2.0",
"webonyx/graphql-php": "^15.0",
"ext-simplexml": "*",
"ext-dom": "*",
"phpcompatibility/php-compatibility": "^9.3",
"squizlabs/php_codesniffer": "^3.6.1",
"rector/rector": "^0.17.12",
"phpcsstandards/phpcsutils": "^1.0.5"
"phpcsstandards/phpcsutils": "^1.0.5",
"magento/php-compatibility-fork": "^0.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
Expand All @@ -36,8 +36,8 @@
}
},
"scripts": {
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility",
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility/PHPCompatibility"
"post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility",
"post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..,../../magento/php-compatibility-fork/PHPCompatibility"
},
"config": {
"allow-plugins": {
Expand Down
39 changes: 23 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7aef678

Please sign in to comment.