Skip to content

Commit 47072f0

Browse files
Merge pull request #98 from magento-commerce/imported-eliseacornejo-magento-coding-standard-311
[Imported] AC-678: Create phpcs sniff for ObsoleteResponseTest
2 parents 3c477b1 + c420516 commit 47072f0

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
namespace Magento2\Sniffs\Legacy;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
class ObsoleteResponseSniff implements Sniff
14+
{
15+
private const WARNING_CODE_METHOD = 'FoundObsoleteResponseMethod';
16+
17+
/**
18+
* @var string[]
19+
*/
20+
private $obsoleteResponseMethods = [
21+
'loadLayout' => 'Please use \Magento\Framework\View\Layout\Builder::build instead.',
22+
'renderLayout' => 'Please use \Magento\Framework\Controller\ResultInterface::renderResult instead.',
23+
'_redirect' => 'Please use \Magento\Backend\Model\View\Result\Redirect::render instead.',
24+
'_forward' => 'Please use \Magento\Backend\Model\View\Result\Forward::forward instead.',
25+
'_setActiveMenu' => 'Please use \Magento\Backend\Model\View\Result\Page::setActiveMenu instead.',
26+
'_addBreadcrumb' => 'Please use \Magento\Backend\Model\View\Result\Page::addBreadcrumb instead.',
27+
'_addContent' => 'Please use \Magento\Backend\Model\View\Result\Page::addContent instead.',
28+
'_addLeft' => 'Please use \Magento\Backend\Model\View\Result\Page::addLeft instead.',
29+
'_addJs' => 'Please use \Magento\Backend\Model\View\Result\Page::addJs instead.',
30+
'_moveBlockToContainer' => 'Please use \Magento\Backend\Model\View\Result\Page::moveBlockToContainer instead.',
31+
];
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function register()
37+
{
38+
return [
39+
T_OBJECT_OPERATOR,
40+
T_FUNCTION
41+
];
42+
}
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public function process(File $phpcsFile, $stackPtr)
48+
{
49+
$tokens = $phpcsFile->getTokens();
50+
$stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
51+
52+
foreach ($this->obsoleteResponseMethods as $method => $errorMessage) {
53+
if ($tokens[$stringPos]['content'] === $method) {
54+
$phpcsFile->addWarning(
55+
sprintf('%s method is deprecated. %s', $method, $errorMessage),
56+
$stackPtr,
57+
self::WARNING_CODE_METHOD
58+
);
59+
}
60+
}
61+
}
62+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$this->_view->loadLayout(['default', 'test'], true, true, false);
8+
$this->_view->renderLayout();
9+
10+
protected function _addBreadcrumb($label, $title = null, $link = null)
11+
{
12+
$this->getLayout()->getBlock('test')->addLink($label, $title, $link);
13+
}
14+
15+
$this->editPost = $objectManagerHelper->getObject(
16+
TestClass::class,
17+
[
18+
'_redirect' => $this->redirect,
19+
]
20+
);
21+
22+
$this->_redirect('test/path');
23+
24+
$this->_forward('grid');
25+
26+
$this->_initAction()->_setActiveMenu(
27+
'Magento_Invitation::report_magento_invitation_order'
28+
)->_addBreadcrumb(
29+
__('Invitation Report by Customers'),
30+
__('Invitation Report by Order Conversion Rate')
31+
)->_addLeft(
32+
)->_addJs(
33+
$this->_view->getLayout()->createBlock(TestBlock::class)->setTemplate('Test::test.phtml')
34+
);
35+
36+
private function _addContent(AbstractBlock $block)
37+
{
38+
return $this->_moveBlockToContainer($block, 'content');
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento2\Tests\Legacy;
8+
9+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
10+
11+
class ObsoleteResponseUnitTest extends AbstractSniffUnitTest
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function getErrorList($testFile = '')
17+
{
18+
return [];
19+
}
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function getWarningList($testFile = '')
25+
{
26+
return [
27+
7 => 1,
28+
8 => 1,
29+
10 => 1,
30+
22 => 1,
31+
24 => 1,
32+
26 => 1,
33+
28 => 1,
34+
31 => 1,
35+
32 => 1,
36+
36 => 1,
37+
38 => 1
38+
];
39+
}
40+
}

Magento2/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@
322322
<severity>8</severity>
323323
<type>warning</type>
324324
</rule>
325+
<rule ref="Magento2.Legacy.ObsoleteResponse">
326+
<severity>8</severity>
327+
<type>warning</type>
328+
</rule>
325329

326330
<!-- Severity 7 warnings: General code issues. -->
327331
<rule ref="Generic.Arrays.DisallowLongArraySyntax">

0 commit comments

Comments
 (0)