-
Notifications
You must be signed in to change notification settings - Fork 160
Create phpcs static check for DiConfigTest #233
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 12 commits into
magento:develop
from
loginesta:AC-660
Aug 30, 2021
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f0b61be
AC-660: Create phpcs static check for DiConfigTest
loginesta 7be675f
AC-660: Create phpcs static check for DiConfigTest
loginesta c9a0725
Merge branch 'develop' into AC-660
loginesta 6b3aeda
Merge branch 'develop' of github.com:magento/magento-coding-standard …
loginesta e84ed42
Merge branch 'AC-660' of github.com:loginesta/magento-coding-standard…
loginesta d58d4b5
Update Magento2/ruleset.xml
loginesta d0039ff
AC-660: Create phpcs static check for DiConfigTest
loginesta d8d8cb7
AC-660: Create phpcs static check for DiConfigTest
loginesta 5e4b15b
AC-660: Create phpcs static check for DiConfigTest
loginesta d08c40f
AC-660: Create phpcs static check for DiConfigTest
loginesta 6031c1e
AC-660: Create phpcs static check for DiConfigTest
loginesta 8c60047
AC-660: Create phpcs static check for DiConfigTest
loginesta 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,80 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento2\Sniffs\Legacy; | ||
|
||
use DOMDocument; | ||
use PHP_CodeSniffer\Files\File; | ||
use PHP_CodeSniffer\Sniffs\Sniff; | ||
|
||
class DiConfigSniff implements Sniff | ||
{ | ||
private const WARNING_CODE = 'FoundObsoleteAttribute'; | ||
private const ERROR_CODE = 'WrongXML'; | ||
|
||
private $xpathObsoleteElems = [ | ||
'param', | ||
'instance', | ||
'array', | ||
'item[@key]', | ||
'value' | ||
]; | ||
|
||
private $messages = [ | ||
'param' => 'The <param> node is obsolete. Instead, use the <argument name="..." xsi:type="...">', | ||
'instance' => 'The <instance> node is obsolete. Instead, use the <argument name="..." xsi:type="object">', | ||
'array' => 'The <array> node is obsolete. Instead, use the <argument name="..." xsi:type="array">', | ||
'item[@key]' => 'The <item key="..."> node is obsolete. Instead, use the <item name="..." xsi:type="...">', | ||
'value' => 'The <value> node is obsolete. Instead, provide the actual value as a text literal.' | ||
]; | ||
|
||
public function register(): array | ||
{ | ||
return [ | ||
T_INLINE_HTML | ||
]; | ||
} | ||
|
||
public function process(File $phpcsFile, $stackPtr): int | ||
{ | ||
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); | ||
if ($xml === false) { | ||
$phpcsFile->addError( | ||
sprintf( | ||
"Couldn't parse contents of '%s', check that they are in valid XML format", | ||
$phpcsFile->getFilename(), | ||
), | ||
$stackPtr, | ||
self::ERROR_CODE | ||
); | ||
} | ||
|
||
foreach ($this->xpathObsoleteElems as $obsoleteElem) { | ||
$found = $xml->xpath($obsoleteElem); | ||
if ($found === true) { | ||
$phpcsFile->addWarning( | ||
$this->messages[$obsoleteElem], | ||
$stackPtr, | ||
self::WARNING_CODE | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Format the incoming XML to avoid tags split into several lines. | ||
* | ||
* @param File $phpcsFile | ||
* @return false|string | ||
*/ | ||
private function getFormattedXML(File $phpcsFile) | ||
{ | ||
$doc = new DomDocument('1.0'); | ||
$doc->formatOutput = true; | ||
$doc->loadXML($phpcsFile->getTokensAsString(0, 999999)); | ||
return $doc->saveXML(); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Tests\Legacy; | ||
|
||
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
|
||
class DiConfigUnitTest extends AbstractSniffUnitTest | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getErrorList(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getWarningList(): array | ||
{ | ||
return [ | ||
9 => 1, | ||
10 => 1, | ||
11 => 1, | ||
12 => 1, | ||
13 => 1, | ||
15 => 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<root> | ||
<instance> | ||
<param name="param1" new_attribute="2"> | ||
<array key="amounts"> | ||
<item key="item1" new_attribute="3"> | ||
<value new_attribute="4">scalar20</value> | ||
</item> | ||
<item>50.00</item> | ||
</array> | ||
</param> | ||
</instance> | ||
</root> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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 would renamve this property as it's not xpath anymore, also it would be good to add a phpdoc