Skip to content

Commit a5b8698

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into eslint-quotes
2 parents 70da04c + 0263b89 commit a5b8698

File tree

83 files changed

+1348
-4413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1348
-4413
lines changed

.github/workflows/php.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
dependencies:
2121
- "lowest"
2222
- "highest"
23-
experimental:
24-
- false
23+
exclude:
24+
- php-version: "8.1"
25+
dependencies: "lowest"
2526
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies
2627

2728
steps:
@@ -36,6 +37,7 @@ jobs:
3637
uses: shivammathur/setup-php@v2
3738
with:
3839
php-version: ${{ matrix.php-version }}
40+
ini-file: development
3941
env:
4042
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4143

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
.vscode/
1010

1111
.phpunit.result.cache
12+
.DS_Store

Magento2/Helpers/Commenting/PHPDocFormattingValidator.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens)
121121
if ($deprecatedPtr === -1) {
122122
return true;
123123
}
124-
125-
$seeTagRequired = false;
126-
if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) {
127-
$seeTagRequired = true;
128-
}
129124
$seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens);
130125
if ($seePtr === -1) {
131-
return !$seeTagRequired;
126+
if (preg_match(
127+
"/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/",
128+
$tokens[$deprecatedPtr + 2]['content']
129+
)) {
130+
return true;
131+
}
132+
return false;
132133
}
134+
133135
return $tokens[$seePtr + 2]['code'] === T_DOC_COMMENT_STRING;
134136
}
135137

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2021 Adobe
3+
* Copyright 2022 Adobe
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
77

88
use Magento2\Rector\Src\AddArrayAccessInterfaceReturnTypes;
9-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9+
use Rector\Config\RectorConfig;
1010

11-
return static function (ContainerConfigurator $containerConfigurator): void {
12-
$services = $containerConfigurator->services();
13-
$services->set(AddArrayAccessInterfaceReturnTypes::class);
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->rule(AddArrayAccessInterfaceReturnTypes::class);
1413
};
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2021 Adobe
3+
* Copyright 2022 Adobe
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
77

88
use Magento2\Rector\Src\ReplaceMbStrposNullLimit;
9-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9+
use Rector\Config\RectorConfig;
1010

11-
return static function (ContainerConfigurator $containerConfigurator): void {
12-
$services = $containerConfigurator->services();
13-
$services->set(ReplaceMbStrposNullLimit::class);
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->rule(ReplaceMbStrposNullLimit::class);
1413
};
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2021 Adobe
3+
* Copyright 2022 Adobe
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
77

88
use Magento2\Rector\Src\ReplaceNewDateTimeNull;
9-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9+
use Rector\Config\RectorConfig;
1010

11-
return static function (ContainerConfigurator $containerConfigurator): void {
12-
$services = $containerConfigurator->services();
13-
$services->set(ReplaceNewDateTimeNull::class);
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->rule(ReplaceNewDateTimeNull::class);
1413
};
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22
/**
3-
* Copyright 2021 Adobe
3+
* Copyright 2022 Adobe
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types=1);
77

88
use Magento2\Rector\Src\ReplacePregSplitNullLimit;
9-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9+
use Rector\Config\RectorConfig;
1010

11-
return static function (ContainerConfigurator $containerConfigurator): void {
12-
$services = $containerConfigurator->services();
13-
$services->set(ReplacePregSplitNullLimit::class);
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->rule(ReplacePregSplitNullLimit::class);
1413
};

Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento2\Sniffs\Annotation;
99

10+
use Magento2\Helpers\Commenting\PHPDocFormattingValidator;
1011
use PHP_CodeSniffer\Files\File;
1112
use PHP_CodeSniffer\Sniffs\Sniff;
1213

@@ -20,12 +21,18 @@ class MethodAnnotationStructureSniff implements Sniff
2021
*/
2122
private $annotationFormatValidator;
2223

24+
/**
25+
* @var PHPDocFormattingValidator
26+
*/
27+
private $PHPDocFormattingValidator;
28+
2329
/**
2430
* AnnotationStructureSniff constructor.
2531
*/
2632
public function __construct()
2733
{
2834
$this->annotationFormatValidator = new AnnotationFormatValidator();
35+
$this->PHPDocFormattingValidator = new PHPDocFormattingValidator();
2936
}
3037

3138
/**
@@ -50,6 +57,17 @@ public function process(File $phpcsFile, $stackPtr)
5057
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
5158
return;
5259
}
60+
61+
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
62+
$phpcsFile->addWarning(
63+
'Motivation behind the added @deprecated tag MUST be explained. '
64+
. '@see tag MUST be used with reference to new implementation when code is deprecated '
65+
. 'and there is a new alternative.',
66+
$stackPtr,
67+
'InvalidDeprecatedTagUsage'
68+
);
69+
}
70+
5371
$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
5472
$functionPtrContent = $tokens[$stackPtr + 2]['content'];
5573
if (preg_match('/(?i)__construct/', $functionPtrContent)) {

Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ public function process(File $phpcsFile, $stackPtr)
3737
return;
3838
}
3939

40+
// Ignore empty constructor function blocks when using property promotion
41+
if ($tokens[$stackPtr]['code'] === T_FUNCTION &&
42+
strpos($phpcsFile->getDeclarationName($stackPtr), '__construct') === 0 &&
43+
count($phpcsFile->getMethodParameters($stackPtr)) > 0 &&
44+
array_reduce($phpcsFile->getMethodParameters($stackPtr), static function ($result, $methodParam) {
45+
return $result && isset($methodParam['property_visibility']);
46+
}, true)) {
47+
48+
return;
49+
}
50+
4051
parent::process($phpcsFile, $stackPtr);
4152
}//end process()
4253
}

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
6767
}
6868

6969
$commentStart = $tokens[$commentEnd]['comment_opener'];
70+
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStart, $tokens) !== true) {
71+
$phpcsFile->addWarning(
72+
'Motivation behind the added @deprecated tag MUST be explained. '
73+
. '@see tag MUST be used with reference to new implementation when code is deprecated '
74+
. 'and there is a new alternative.',
75+
$stackPtr,
76+
'InvalidDeprecatedTagUsage'
77+
);
78+
}
7079
$varAnnotationPosition = null;
7180
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
7281
if ($tokens[$tag]['content'] === '@var') {

0 commit comments

Comments
 (0)