-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into deprecated-versi…
…on-range
- Loading branch information
Showing
15 changed files
with
784 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento2\Sniffs\Legacy; | ||
|
||
use PHP_CodeSniffer\Files\File; | ||
use PHP_CodeSniffer\Sniffs\Sniff; | ||
use PHP_CodeSniffer\Util\Tokens; | ||
|
||
class EscapeMethodsOnBlockClassSniff implements Sniff | ||
{ | ||
private const ESCAPER_METHODS = [ | ||
'escapeCss' => true, | ||
'escapeHtml' => true, | ||
'escapeHtmlAttr' => true, | ||
'escapeJs' => true, | ||
'escapeJsQuote' => true, | ||
'escapeQuote' => true, | ||
'escapeUrl' => true, | ||
'escapeXssInUrl' => true, | ||
]; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function register() | ||
{ | ||
return [ | ||
T_OBJECT_OPERATOR, | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(File $phpcsFile, $stackPtr) | ||
{ | ||
$tokens = $phpcsFile->getTokens(); | ||
|
||
if ($stackPtr <= 1 || !isset($tokens[$stackPtr + 2])) { | ||
return; | ||
} | ||
|
||
$objectPtr = $stackPtr - 1; | ||
if ($tokens[$objectPtr]['code'] !== T_VARIABLE) { | ||
$objectPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $objectPtr, null, true); | ||
|
||
if (!$objectPtr) { | ||
return; | ||
} | ||
} | ||
|
||
if ($tokens[$objectPtr]['code'] !== T_VARIABLE | ||
|| $tokens[$objectPtr]['content'] !== '$block' | ||
) { | ||
return; | ||
} | ||
|
||
$methodPtr = $stackPtr + 1; | ||
if ($tokens[$methodPtr]['code'] !== T_STRING) { | ||
$methodPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $methodPtr, null, true); | ||
|
||
if (!$methodPtr) { | ||
return; | ||
} | ||
} | ||
|
||
if ($tokens[$methodPtr]['code'] !== T_STRING | ||
|| !isset(self::ESCAPER_METHODS[$tokens[$methodPtr]['content']]) | ||
) { | ||
return; | ||
} | ||
|
||
$openParenPtr = $methodPtr + 1; | ||
if ($tokens[$openParenPtr]['code'] !== T_OPEN_PARENTHESIS) { | ||
$openParenPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $openParenPtr, null, true); | ||
|
||
if (!$openParenPtr) { | ||
return; | ||
} | ||
} | ||
|
||
if ($tokens[$openParenPtr]['code'] !== T_OPEN_PARENTHESIS) { | ||
return; | ||
} | ||
|
||
$fix = $phpcsFile->addFixableWarning( | ||
'Using %s on $block is deprecated. Please use equivalent method on $escaper', | ||
$methodPtr, | ||
'Found', | ||
[ | ||
$tokens[$methodPtr]['content'], // method name | ||
] | ||
); | ||
|
||
if ($fix) { | ||
$phpcsFile->fixer->replaceToken($objectPtr, '$escaper'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?php | ||
|
||
/** | ||
* Handler for PHP errors/warnings/notices that converts them to exceptions. | ||
*/ | ||
class ErrorHandler | ||
{ | ||
|
||
} | ||
|
||
class NotAnErrorHandler | ||
{ | ||
|
||
} | ||
|
||
class FaultyHandler | ||
{ | ||
|
||
} | ||
|
||
class SomeHandler | ||
{ | ||
|
||
} | ||
|
||
class YetAnotherHandler | ||
{ | ||
|
||
} | ||
|
||
class GreenHandler | ||
{ | ||
|
||
} | ||
|
||
class EmptyHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Handler for PHP errors/warnings/notices that converts them to exceptions. | ||
* | ||
* @api is ok here | ||
* @deprecated can be used in this context | ||
* @see is ok here | ||
*/ | ||
class ExampleHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @api | ||
* @since 100.0.2 | ||
*/ | ||
class ApiHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @api | ||
*/ | ||
class AsyncApiHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class GroupRepositoryHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
class DeprecatedHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated Should not be used | ||
*/ | ||
class AncientHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated | ||
* @see | ||
*/ | ||
class AgedHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated Should not be used | ||
* @see | ||
*/ | ||
class ArhaicHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated Should not be used | ||
* @see Magento\Framework\NewHandler | ||
*/ | ||
class OldHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @see Magento\Framework\NewHandler | ||
*/ | ||
class SomethingHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @see | ||
*/ | ||
class DoNotCareHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated | ||
* @see Magento\Framework\NewHandler | ||
*/ | ||
class OldHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated This class will be removed in version 1.0.0 without replacement | ||
*/ | ||
class DeprecatedButHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated This class will be removed in version 123.45.6789 without replacement | ||
*/ | ||
class DeprecatedButHandlerLongVersion | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated It's also deprecated - This class will be removed in version 1.0.0 without replacement | ||
*/ | ||
class AlsoDeprecatedButHandler | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @deprecated It's also deprecated - This class will be removed in version 123.45.6789 without replacement | ||
*/ | ||
class AlsoDeprecatedButHandlerLongVersion | ||
{ | ||
|
||
} | ||
|
||
class OnlyUselessCommentContent | ||
{ | ||
|
||
} |
Oops, something went wrong.