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

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

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

+8-6
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

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
};
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
};
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
};
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

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

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

+9
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') {

Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php

+38-38
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
4040
'^chdir$' => null,
4141
'^chgrp$' => null,
4242
'^chmod$' => 'Magento\Framework\Filesystem\DriverInterface::changePermissions()
43-
or Magento\Framework\Filesystem\DriverInterface::changePermissionsRecursively()',
43+
or Magento\Framework\Filesystem\DriverInterface::changePermissionsRecursively',
4444
'^chown$' => null,
4545
'^chroot$' => null,
4646
'^com_load_typelib$' => null,
47-
'^copy$' => 'Magento\Framework\Filesystem\DriverInterface::copy()',
47+
'^copy$' => 'Magento\Framework\Filesystem\DriverInterface::copy',
4848
'^curl_.*$' => null,
4949
'^cyrus_connect$' => null,
5050
'^dba_.*$' => null,
@@ -54,21 +54,21 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
5454
'^dcngettext$' => null,
5555
'^dgettext$' => null,
5656
'^dio_.*$' => null,
57-
'^dirname$' => 'Magento\Framework\Filesystem\DriverInterface::getParentDirectory()',
57+
'^dirname$' => 'Magento\Framework\Filesystem\DriverInterface::getParentDirectory',
5858
'^dngettext$' => null,
5959
'^domxml_.*$' => null,
6060
'^fbsql_.*$' => null,
6161
'^fbsql$' => null,
6262
'^fdf_add_doc_javascript$' => null,
6363
'^fdf_open$' => null,
64-
'^fopen$' => 'Magento\Framework\Filesystem\DriverInterface::fileOpen()',
65-
'^fclose$' => 'Magento\Framework\Filesystem\DriverInterface::fileClose()',
66-
'^fsockopen$' => 'Magento\Framework\Filesystem\Driver\Http::open()',
64+
'^fopen$' => 'Magento\Framework\Filesystem\DriverInterface::fileOpen',
65+
'^fclose$' => 'Magento\Framework\Filesystem\DriverInterface::fileClose',
66+
'^fsockopen$' => 'Magento\Framework\Filesystem\Driver\Http::open',
6767
'^ftp_.*$' => null,
68-
'^fwrite$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()',
69-
'^fputs$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()',
70-
'^gettext$' => 'Magento\Framework\Translate\AdapterInterface::translate()',
71-
'^_$' => 'Magento\Framework\Translate\AdapterInterface::translate()',
68+
'^fwrite$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite',
69+
'^fputs$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite',
70+
'^gettext$' => 'Magento\Framework\Translate\AdapterInterface::translate',
71+
'^_$' => 'Magento\Framework\Translate\AdapterInterface::translate',
7272
'^gz.*$' => null,
7373
'^header$' => null,
7474
'^highlight_file$' => null,
@@ -84,7 +84,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
8484
'^link$' => null,
8585
'^mail$' => null,
8686
'^mb_send_mail$' => null,
87-
'^mkdir$' => 'Magento\Framework\Filesystem\DriverInterface::createDirectory()',
87+
'^mkdir$' => 'Magento\Framework\Filesystem\DriverInterface::createDirectory',
8888
'^move_uploaded_file$' => null,
8989
'^msession_.*$' => null,
9090
'^msg_send$' => null,
@@ -102,7 +102,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
102102
'^parse_str$' => null,
103103
'^parse_url$' => null,
104104
'^parsekit_compile_string$' => null,
105-
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo()',
105+
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo',
106106
'^pcntl_.*$' => null,
107107
'^posix_.*$' => null,
108108
'^pfpro_.*$' => null,
@@ -112,30 +112,30 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
112112
'^print_r$' => null,
113113
'^printf$' => null,
114114
'^putenv$' => null,
115-
'^readfile$' => 'Magento\Framework\Filesystem\DriverInterface::fileRead()',
115+
'^readfile$' => 'Magento\Framework\Filesystem\DriverInterface::fileRead',
116116
'^readgzfile$' => null,
117-
'^readline$' => 'Magento\Framework\Filesystem\DriverInterface::fileReadLine()',
117+
'^readline$' => 'Magento\Framework\Filesystem\DriverInterface::fileReadLine',
118118
'^readlink$' => null,
119119
'^register_shutdown_function$' => null,
120120
'^register_tick_function$' => null,
121-
'^rename$' => 'Magento\Framework\Filesystem\DriverInterface::rename()',
122-
'^rmdir$' => 'Magento\Framework\Filesystem\DriverInterface::deleteDirectory()',
121+
'^rename$' => 'Magento\Framework\Filesystem\DriverInterface::rename',
122+
'^rmdir$' => 'Magento\Framework\Filesystem\DriverInterface::deleteDirectory',
123123
'^scandir$' => null,
124124
'^session_.*$' => null,
125125
'^set_include_path$' => null,
126126
'^ini_set$' => null,
127127
'^ini_alter$' => null,
128128
'^set_time_limit$' => null,
129129
'^setcookie$' => null,
130-
'^setlocale$' => 'Magento\Framework\Translate\AdapterInterface::setlocale()',
130+
'^setlocale$' => 'Magento\Framework\Translate\AdapterInterface::setLocale',
131131
'^setrawcookie$' => null,
132132
'^sleep$' => null,
133133
'^socket_.*$' => null,
134134
'^stream_.*$' => null,
135135
'^sybase_.*$' => null,
136-
'^symlink$' => 'Magento\Framework\Filesystem\DriverInterface::symlink()',
136+
'^symlink$' => 'Magento\Framework\Filesystem\DriverInterface::symlink',
137137
'^syslog$' => null,
138-
'^touch$' => 'Magento\Framework\Filesystem\DriverInterface::touch()',
138+
'^touch$' => 'Magento\Framework\Filesystem\DriverInterface::touch',
139139
'^trigger_error$' => null,
140140
'^unlink$' => null,
141141
'^vprintf$' => null,
@@ -158,7 +158,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
158158
'^fdf_.*$' => null,
159159
'^fget.*$' => null,
160160
'^fread$' => null,
161-
'^fflush$' => 'Magento\Framework\Filesystem\DriverInterface::fileFlush()',
161+
'^fflush$' => 'Magento\Framework\Filesystem\DriverInterface::fileFlush',
162162
'^get_browser$' => null,
163163
'^get_headers$' => null,
164164
'^get_meta_tags$' => null,
@@ -204,23 +204,23 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
204204
'^gettype$' => null,
205205
'^var_dump$' => null,
206206
'^tempnam$' => null,
207-
'^realpath$' => 'Magento\Framework\Filesystem\DriverInterface::getRealPath()',
207+
'^realpath$' => 'Magento\Framework\Filesystem\DriverInterface::getRealPath',
208208
'^linkinfo$' => null,
209-
'^lstat$' => 'Magento\Framework\Filesystem\DriverInterface::stat()',
209+
'^lstat$' => 'Magento\Framework\Filesystem\DriverInterface::stat',
210210
'^stat$' => null,
211211
'^lchgrp$' => null,
212212
'^lchown$' => null,
213-
'^is_dir$' => 'Magento\Framework\Filesystem\DriverInterface::isDirectory()',
213+
'^is_dir$' => 'Magento\Framework\Filesystem\DriverInterface::isDirectory',
214214
'^is_executable$' => null,
215-
'^is_file$' => 'Magento\Framework\Filesystem\DriverInterface::isFile()',
215+
'^is_file$' => 'Magento\Framework\Filesystem\DriverInterface::isFile',
216216
'^is_link$' => null,
217-
'^is_readable$' => 'Magento\Framework\Filesystem\DriverInterface::isReadable()',
218-
'^is_writable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable()',
219-
'^is_writeable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable()',
217+
'^is_readable$' => 'Magento\Framework\Filesystem\DriverInterface::isReadable',
218+
'^is_writable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable',
219+
'^is_writeable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable',
220220
'^is_uploaded_file$' => null,
221-
'^glob$' => 'Magento\Framework\Filesystem\Glob::glob()',
221+
'^glob$' => 'Magento\Framework\Filesystem\Glob::glob',
222222
'^ssh2_.*$' => null,
223-
'^delete$' => 'Magento\Framework\Filesystem\DriverInterface::deleteFile()',
223+
'^delete$' => 'Magento\Framework\Filesystem\DriverInterface::deleteFile',
224224
'^file.*$' => null,
225225
'^chop$' => 'rtrim()',
226226
'^sizeof$' => 'count()',
@@ -229,15 +229,15 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
229229
'^strval$' => '(string) construction',
230230
'^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml',
231231
'^getimagesize$' => 'getimagesizefromstring',
232-
'^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists()',
233-
'^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents()',
234-
'^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents()',
235-
'^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv()',
236-
'^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv()',
237-
'^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell()',
238-
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek()',
239-
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile()',
240-
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock()',
232+
'^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists',
233+
'^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents',
234+
'^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents',
235+
'^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv',
236+
'^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv',
237+
'^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell',
238+
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek',
239+
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile',
240+
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock',
241241
'^date_sunrise$' => 'date_sun_info',
242242
'^date_sunset$' => 'date_sun_info',
243243
'^strptime$' => 'date_parse_from_format',

0 commit comments

Comments
 (0)