-
Notifications
You must be signed in to change notification settings - Fork 160
AC-678: Create phpcs sniff for ObsoleteResponseTest #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-devops-reposync-svc
merged 3 commits into
magento:develop
from
eliseacornejo:AC-678
Oct 14, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
<?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; | ||
|
||
class ObsoleteResponseSniff implements Sniff | ||
{ | ||
private const WARNING_CODE_METHOD = 'FoundObsoleteResponseMethod'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $obsoleteResponseMethods = [ | ||
'loadLayout', | ||
'renderLayout', | ||
'_redirect', | ||
'_forward', | ||
'_setActiveMenu', | ||
'_addBreadcrumb', | ||
'_addContent', | ||
'_addLeft', | ||
'_addJs', | ||
'_moveBlockToContainer', | ||
]; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function register() | ||
{ | ||
return [ | ||
T_OBJECT_OPERATOR, | ||
T_FUNCTION | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(File $phpcsFile, $stackPtr) | ||
{ | ||
$tokens = $phpcsFile->getTokens(); | ||
$stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1); | ||
|
||
foreach ($this->obsoleteResponseMethods as $method) { | ||
if ($tokens[$stringPos]['content'] === $method) { | ||
$phpcsFile->addWarning( | ||
sprintf('Contains obsolete response method: %s.', $method), | ||
$stackPtr, | ||
self::WARNING_CODE_METHOD | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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,39 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
$this->_view->loadLayout(['default', 'test'], true, true, false); | ||
$this->_view->renderLayout(); | ||
|
||
protected function _addBreadcrumb($label, $title = null, $link = null) | ||
{ | ||
$this->getLayout()->getBlock('test')->addLink($label, $title, $link); | ||
} | ||
|
||
$this->editPost = $objectManagerHelper->getObject( | ||
TestClass::class, | ||
[ | ||
'_redirect' => $this->redirect, | ||
] | ||
); | ||
|
||
$this->_redirect('test/path'); | ||
|
||
$this->_forward('grid'); | ||
|
||
$this->_initAction()->_setActiveMenu( | ||
'Magento_Invitation::report_magento_invitation_order' | ||
)->_addBreadcrumb( | ||
__('Invitation Report by Customers'), | ||
__('Invitation Report by Order Conversion Rate') | ||
)->_addLeft( | ||
)->_addJs( | ||
$this->_view->getLayout()->createBlock(TestBlock::class)->setTemplate('Test::test.phtml') | ||
); | ||
|
||
private function _addContent(AbstractBlock $block) | ||
{ | ||
return $this->_moveBlockToContainer($block, 'content'); | ||
} |
This file contains hidden or 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,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento2\Tests\Legacy; | ||
|
||
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
|
||
class ObsoleteResponseUnitTest extends AbstractSniffUnitTest | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getErrorList($testFile = '') | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getWarningList($testFile = '') | ||
{ | ||
return [ | ||
7 => 1, | ||
8 => 1, | ||
10 => 1, | ||
22 => 1, | ||
24 => 1, | ||
26 => 1, | ||
28 => 1, | ||
31 => 1, | ||
32 => 1, | ||
36 => 1, | ||
38 => 1 | ||
]; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be not clear how these static tests failures should be addressed. Can we add a bit more information and replacement suggestion to the message:
I.e.
"\Magento\Framework\App\ViewInterface::renderLayout method is deprecated. Please use \Magento\Framework\Controller\ResultInterface::renderResult instead."
...
"\Magento\Framework\App\Action\Action::_redirect" method is deprecated. Please use \Magento\Backend\Model\View\Result\Redirect instead.
...
"\Magento\Backend\App\AbstractAction::_addBreadcrumb method is deprecated. Please use \Magento\Backend\Model\View\Result\Page::addBreadcrumb instead."
and so on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be implemented by having
$obsoleteResponseMethods
as associative arrayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please @sivaschenko review! thanks