Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into psr-control-stru…
Browse files Browse the repository at this point in the history
…cture-spacing
  • Loading branch information
fredden committed Oct 8, 2024
2 parents 8878552 + f5cf74f commit aef1174
Show file tree
Hide file tree
Showing 128 changed files with 1,359 additions and 592 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
dependencies:
- "lowest"
- "highest"
exclude:
- php-version: "8.1"
dependencies: "lowest"
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies

steps:
Expand Down Expand Up @@ -93,4 +90,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
4 changes: 2 additions & 2 deletions Magento2/Helpers/Assert.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2023 Adobe
* All Rights Reserved.
*/

declare(strict_types=1);
Expand Down
4 changes: 2 additions & 2 deletions Magento2/Helpers/Commenting/PHPDocFormattingValidator.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Helpers\Commenting;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Helpers/Tokenizer/AbstractTokenizer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
namespace Magento2\Helpers\Tokenizer;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Helpers/Tokenizer/Parameter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
namespace Magento2\Helpers\Tokenizer;

Expand Down
5 changes: 2 additions & 3 deletions Magento2/Helpers/Tokenizer/Variable.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/

namespace Magento2\Helpers\Tokenizer;

/**
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Rector/Src/AddArrayAccessInterfaceReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down
2 changes: 1 addition & 1 deletion Magento2/Rector/Src/ReplaceMbStrposNullLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\LNumber;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down
2 changes: 1 addition & 1 deletion Magento2/Rector/Src/ReplaceNewDateTimeNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down
2 changes: 1 addition & 1 deletion Magento2/Rector/Src/ReplacePregSplitNullLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Annotation/AnnotationFormatValidator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down
33 changes: 27 additions & 6 deletions Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -51,13 +51,34 @@ 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);
if (!$commentStartPtr) {
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
$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, 'NoCommentBlock');
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
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Annotation/MethodArgumentsSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Classes/AbstractApiSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Classes;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Classes;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\CodeAnalysis;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Commenting;

Expand Down Expand Up @@ -63,15 +63,30 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];

if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
$phpcsFile->addWarning(
$fix = $phpcsFile->addFixableWarning(
sprintf(
'%s description must contain meaningful information beyond what its name provides or be removed.',
ucfirst($tokens[$stackPtr]['content'])
),
$stackPtr,
'InvalidDescription'
);

if ($fix) {
for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

if (
$tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE
&& $tokens[$commentCloserPtr + 1]['code'] === T_WHITESPACE
) {
$phpcsFile->fixer->replaceToken($commentCloserPtr + 1, '');
}
}
}

if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
Expand Down Expand Up @@ -105,11 +120,35 @@ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
}

if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
$phpcsFile->addWarning(
$fix = $phpcsFile->addFixableWarning(
sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
$i,
'ForbiddenTags'
);

if ($fix) {
for ($j = $i - 1; $j > $commentStartPtr; $j--) {
if (!in_array($tokens[$j]['code'], [T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE], true)) {
break;
}

if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
break;
}

$phpcsFile->fixer->replaceToken($j, '');
}

$phpcsFile->fixer->replaceToken($i, '');

for ($j = $i + 1; $j < $commentCloserPtr; $j++) {
$phpcsFile->fixer->replaceToken($j, '');

if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
break;
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -32,6 +32,7 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
T_NULLABLE,
T_BITWISE_AND,
T_TYPE_UNION,
T_READONLY,
];

/**
Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Commenting;

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Exceptions/DirectThrowSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Exceptions;

Expand Down
5 changes: 2 additions & 3 deletions Magento2/Sniffs/Exceptions/ThrowCatchSniff.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/

namespace Magento2\Sniffs\Exceptions;

use function array_slice;
Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Exceptions;

Expand Down
5 changes: 3 additions & 2 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2018 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Functions;

Expand Down Expand Up @@ -104,6 +104,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^parsekit_compile_string$' => null,
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo',
'^pcntl_.*$' => null,
'^posix_isatty$' => 'stream_isatty',
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Functions/StaticFunctionSniff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
namespace Magento2\Sniffs\Functions;

Expand Down
Loading

0 comments on commit aef1174

Please sign in to comment.