Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into eslint-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Oct 14, 2022
2 parents 70da04c + 0263b89 commit a5b8698
Show file tree
Hide file tree
Showing 83 changed files with 1,348 additions and 4,413 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ jobs:
dependencies:
- "lowest"
- "highest"
experimental:
- false
exclude:
- php-version: "8.1"
dependencies: "lowest"
name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies

steps:
Expand All @@ -36,6 +37,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-file: development
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.vscode/

.phpunit.result.cache
.DS_Store
14 changes: 8 additions & 6 deletions Magento2/Helpers/Commenting/PHPDocFormattingValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens)
if ($deprecatedPtr === -1) {
return true;
}

$seeTagRequired = false;
if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) {
$seeTagRequired = true;
}
$seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens);
if ($seePtr === -1) {
return !$seeTagRequired;
if (preg_match(
"/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/",
$tokens[$deprecatedPtr + 2]['content']
)) {
return true;
}
return false;
}

return $tokens[$seePtr + 2]['code'] === T_DOC_COMMENT_STRING;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* Copyright 2021 Adobe
* Copyright 2022 Adobe
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento2\Rector\Src\AddArrayAccessInterfaceReturnTypes;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Config\RectorConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(AddArrayAccessInterfaceReturnTypes::class);
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(AddArrayAccessInterfaceReturnTypes::class);
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* Copyright 2021 Adobe
* Copyright 2022 Adobe
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento2\Rector\Src\ReplaceMbStrposNullLimit;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Config\RectorConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplaceMbStrposNullLimit::class);
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReplaceMbStrposNullLimit::class);
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* Copyright 2021 Adobe
* Copyright 2022 Adobe
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento2\Rector\Src\ReplaceNewDateTimeNull;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Config\RectorConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplaceNewDateTimeNull::class);
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReplaceNewDateTimeNull::class);
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* Copyright 2021 Adobe
* Copyright 2022 Adobe
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento2\Rector\Src\ReplacePregSplitNullLimit;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Config\RectorConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ReplacePregSplitNullLimit::class);
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ReplacePregSplitNullLimit::class);
};
18 changes: 18 additions & 0 deletions Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento2\Sniffs\Annotation;

use Magento2\Helpers\Commenting\PHPDocFormattingValidator;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

Expand All @@ -20,12 +21,18 @@ class MethodAnnotationStructureSniff implements Sniff
*/
private $annotationFormatValidator;

/**
* @var PHPDocFormattingValidator
*/
private $PHPDocFormattingValidator;

/**
* AnnotationStructureSniff constructor.
*/
public function __construct()
{
$this->annotationFormatValidator = new AnnotationFormatValidator();
$this->PHPDocFormattingValidator = new PHPDocFormattingValidator();
}

/**
Expand All @@ -50,6 +57,17 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
return;
}

if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
$phpcsFile->addWarning(
'Motivation behind the added @deprecated tag MUST be explained. '
. '@see tag MUST be used with reference to new implementation when code is deprecated '
. 'and there is a new alternative.',
$stackPtr,
'InvalidDeprecatedTagUsage'
);
}

$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
$functionPtrContent = $tokens[$stackPtr + 2]['content'];
if (preg_match('/(?i)__construct/', $functionPtrContent)) {
Expand Down
11 changes: 11 additions & 0 deletions Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// Ignore empty constructor function blocks when using property promotion
if ($tokens[$stackPtr]['code'] === T_FUNCTION &&
strpos($phpcsFile->getDeclarationName($stackPtr), '__construct') === 0 &&
count($phpcsFile->getMethodParameters($stackPtr)) > 0 &&
array_reduce($phpcsFile->getMethodParameters($stackPtr), static function ($result, $methodParam) {
return $result && isset($methodParam['property_visibility']);
}, true)) {

return;
}

parent::process($phpcsFile, $stackPtr);
}//end process()
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
}

$commentStart = $tokens[$commentEnd]['comment_opener'];
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStart, $tokens) !== true) {
$phpcsFile->addWarning(
'Motivation behind the added @deprecated tag MUST be explained. '
. '@see tag MUST be used with reference to new implementation when code is deprecated '
. 'and there is a new alternative.',
$stackPtr,
'InvalidDeprecatedTagUsage'
);
}
$varAnnotationPosition = null;
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
if ($tokens[$tag]['content'] === '@var') {
Expand Down
76 changes: 38 additions & 38 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => 'Magento\Framework\Filesystem\DriverInterface::changePermissions()
or Magento\Framework\Filesystem\DriverInterface::changePermissionsRecursively()',
or Magento\Framework\Filesystem\DriverInterface::changePermissionsRecursively',
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => 'Magento\Framework\Filesystem\DriverInterface::copy()',
'^copy$' => 'Magento\Framework\Filesystem\DriverInterface::copy',
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
Expand All @@ -54,21 +54,21 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => 'Magento\Framework\Filesystem\DriverInterface::getParentDirectory()',
'^dirname$' => 'Magento\Framework\Filesystem\DriverInterface::getParentDirectory',
'^dngettext$' => null,
'^domxml_.*$' => null,
'^fbsql_.*$' => null,
'^fbsql$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => 'Magento\Framework\Filesystem\DriverInterface::fileOpen()',
'^fclose$' => 'Magento\Framework\Filesystem\DriverInterface::fileClose()',
'^fsockopen$' => 'Magento\Framework\Filesystem\Driver\Http::open()',
'^fopen$' => 'Magento\Framework\Filesystem\DriverInterface::fileOpen',
'^fclose$' => 'Magento\Framework\Filesystem\DriverInterface::fileClose',
'^fsockopen$' => 'Magento\Framework\Filesystem\Driver\Http::open',
'^ftp_.*$' => null,
'^fwrite$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()',
'^fputs$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()',
'^gettext$' => 'Magento\Framework\Translate\AdapterInterface::translate()',
'^_$' => 'Magento\Framework\Translate\AdapterInterface::translate()',
'^fwrite$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite',
'^fputs$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite',
'^gettext$' => 'Magento\Framework\Translate\AdapterInterface::translate',
'^_$' => 'Magento\Framework\Translate\AdapterInterface::translate',
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
Expand All @@ -84,7 +84,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => 'Magento\Framework\Filesystem\DriverInterface::createDirectory()',
'^mkdir$' => 'Magento\Framework\Filesystem\DriverInterface::createDirectory',
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
Expand All @@ -102,7 +102,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo()',
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo',
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
Expand All @@ -112,30 +112,30 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^print_r$' => null,
'^printf$' => null,
'^putenv$' => null,
'^readfile$' => 'Magento\Framework\Filesystem\DriverInterface::fileRead()',
'^readfile$' => 'Magento\Framework\Filesystem\DriverInterface::fileRead',
'^readgzfile$' => null,
'^readline$' => 'Magento\Framework\Filesystem\DriverInterface::fileReadLine()',
'^readline$' => 'Magento\Framework\Filesystem\DriverInterface::fileReadLine',
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => 'Magento\Framework\Filesystem\DriverInterface::rename()',
'^rmdir$' => 'Magento\Framework\Filesystem\DriverInterface::deleteDirectory()',
'^rename$' => 'Magento\Framework\Filesystem\DriverInterface::rename',
'^rmdir$' => 'Magento\Framework\Filesystem\DriverInterface::deleteDirectory',
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^ini_set$' => null,
'^ini_alter$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => 'Magento\Framework\Translate\AdapterInterface::setlocale()',
'^setlocale$' => 'Magento\Framework\Translate\AdapterInterface::setLocale',
'^setrawcookie$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => 'Magento\Framework\Filesystem\DriverInterface::symlink()',
'^symlink$' => 'Magento\Framework\Filesystem\DriverInterface::symlink',
'^syslog$' => null,
'^touch$' => 'Magento\Framework\Filesystem\DriverInterface::touch()',
'^touch$' => 'Magento\Framework\Filesystem\DriverInterface::touch',
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
Expand All @@ -158,7 +158,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => 'Magento\Framework\Filesystem\DriverInterface::fileFlush()',
'^fflush$' => 'Magento\Framework\Filesystem\DriverInterface::fileFlush',
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
Expand Down Expand Up @@ -204,23 +204,23 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => 'Magento\Framework\Filesystem\DriverInterface::getRealPath()',
'^realpath$' => 'Magento\Framework\Filesystem\DriverInterface::getRealPath',
'^linkinfo$' => null,
'^lstat$' => 'Magento\Framework\Filesystem\DriverInterface::stat()',
'^lstat$' => 'Magento\Framework\Filesystem\DriverInterface::stat',
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^is_dir$' => 'Magento\Framework\Filesystem\DriverInterface::isDirectory()',
'^is_dir$' => 'Magento\Framework\Filesystem\DriverInterface::isDirectory',
'^is_executable$' => null,
'^is_file$' => 'Magento\Framework\Filesystem\DriverInterface::isFile()',
'^is_file$' => 'Magento\Framework\Filesystem\DriverInterface::isFile',
'^is_link$' => null,
'^is_readable$' => 'Magento\Framework\Filesystem\DriverInterface::isReadable()',
'^is_writable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable()',
'^is_writeable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable()',
'^is_readable$' => 'Magento\Framework\Filesystem\DriverInterface::isReadable',
'^is_writable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable',
'^is_writeable$' => 'Magento\Framework\Filesystem\DriverInterface::isWritable',
'^is_uploaded_file$' => null,
'^glob$' => 'Magento\Framework\Filesystem\Glob::glob()',
'^glob$' => 'Magento\Framework\Filesystem\Glob::glob',
'^ssh2_.*$' => null,
'^delete$' => 'Magento\Framework\Filesystem\DriverInterface::deleteFile()',
'^delete$' => 'Magento\Framework\Filesystem\DriverInterface::deleteFile',
'^file.*$' => null,
'^chop$' => 'rtrim()',
'^sizeof$' => 'count()',
Expand All @@ -229,15 +229,15 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^strval$' => '(string) construction',
'^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml',
'^getimagesize$' => 'getimagesizefromstring',
'^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists()',
'^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents()',
'^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents()',
'^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv()',
'^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv()',
'^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell()',
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek()',
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile()',
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock()',
'^file_exists$' => 'Magento\Framework\Filesystem\DriverInterface::isExists',
'^file_get_contents$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetContents',
'^file_put_contents$' => 'Magento\Framework\Filesystem\DriverInterface::filePutContents',
'^fgetcsv$' => 'Magento\Framework\Filesystem\DriverInterface::fileGetCsv',
'^fputcsv$' => 'Magento\Framework\Filesystem\DriverInterface::filePutCsv',
'^ftell$' => 'Magento\Framework\Filesystem\DriverInterface::fileTell',
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek',
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile',
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock',
'^date_sunrise$' => 'date_sun_info',
'^date_sunset$' => 'date_sun_info',
'^strptime$' => 'date_parse_from_format',
Expand Down
Loading

0 comments on commit a5b8698

Please sign in to comment.