Skip to content

Version 10 master update #272

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
merged 44 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ac5f9fd
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
0cb8f67
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
4a78a94
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
e4698fb
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
e4f5540
Update Magento2/ruleset.xml
jcuerdo Sep 8, 2021
2751031
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 8, 2021
e3f4d87
Merge pull request #58 from magento-commerce/imported-magento-magento…
jcuerdo Sep 8, 2021
8b2cd90
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
702cd60
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
76359c2
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
e2c2d07
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
a25e2ca
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
dc49aaa
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
f4b0117
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
64512dd
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
df14044
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
2f4c72e
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
7a6f29f
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
a2864d2
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 13, 2021
74c47b2
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 13, 2021
dae1ab3
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 13, 2021
d528da6
AC-666: Static check for CopyrightTest for another extensions files
eliseacornejo Sep 13, 2021
6a735c1
AC-666: Static check for CopyrightTest for another extensions files
eliseacornejo Sep 13, 2021
9b4da0c
Merge pull request #60 from magento-commerce/imported-magento-magento…
jcuerdo Sep 13, 2021
0d6cb3c
Merge pull request #61 from magento-commerce/imported-magento-magento…
eliseacornejo Sep 13, 2021
26a3b65
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Sep 13, 2021
b00d7cf
Merge pull request #62 from magento-commerce/imported-magento-magento…
eliseacornejo Sep 13, 2021
ef00afd
Fixed wrongly returning error for valid descriptions
svera Sep 13, 2021
95c56c9
Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
svera Sep 14, 2021
2a57af8
Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
svera Sep 14, 2021
f209db6
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
1ed4156
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
efaffac
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
62e0fc1
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
5b4b543
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
0c29f5b
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
3fb9cba
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
d238849
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
e92e17d
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
0fb55fc
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
a25482e
Merge pull request #63 from magento-commerce/imported-svera-magento-c…
svera Sep 14, 2021
813a761
Increased version to 10
svera Sep 14, 2021
f7df455
Increased version to 10
svera Sep 14, 2021
ec62c5c
Merge pull request #65 from magento-commerce/imported-svera-magento-c…
sivaschenko Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
AC-661: Create phpcs static check for XmlTest
  • Loading branch information
jcuerdo committed Sep 9, 2021
commit 702cd60d087c65061e5ebc6a017a4a20ee4360d7
114 changes: 114 additions & 0 deletions Magento2/Sniffs/Legacy/WidgetXMLSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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;

/**
* Test for obsolete nodes/attributes in the module.xml
*/
class WidgetXMLSniff implements Sniff
{
private const ERROR_CODE_OBSOLETE = 'FoundObsoleteNode';
private const ERROR_CODE_FACTORY = 'FoundFactory';
private const ERROR_CODE_XML = 'WrongXML';

/**
* @inheritdoc
*/
public function register(): array
{
return [
T_INLINE_HTML
];
}

/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
if($stackPtr > 0) {
return;
}

$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(),
),
1,
self::ERROR_CODE_XML
);
}

$foundElements = $xml->xpath('/widgets/*[@type]');

foreach ($foundElements as $element) {
if (property_exists($element->attributes(), 'type')) {
$type = $element['type'];
if (preg_match('/\//', $type)) {
$phpcsFile->addError(
"Factory name detected: {$type}.",
dom_import_simplexml($element)->getLineNo() - 1,
self::ERROR_CODE_FACTORY
);
}
}
}

$foundElements = $xml->xpath('/widgets/*/supported_blocks');
foreach ($foundElements as $element) {
$phpcsFile->addError(
"Obsolete node: <supported_blocks>. To be replaced with <supported_containers>",
dom_import_simplexml($element)->getLineNo() - 1,
self::ERROR_CODE_OBSOLETE
);
}

$foundElements = $xml->xpath('/widgets/*/*/*/block_name');
foreach ($foundElements as $element) {
$phpcsFile->addError(
"Obsolete node: <block_name>. To be replaced with <container_name>",
dom_import_simplexml($element)->getLineNo() - 1,
self::ERROR_CODE_OBSOLETE
);
}
}

/**
* Check if the element passed is in the currently sniffed line
*
* @param SimpleXMLElement $element
* @param int $stackPtr
* @return bool
*/
private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $stackPtr): bool
{
$node = dom_import_simplexml($element);

return $node->getLineNo() === $stackPtr + 1;
}

/**
* 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();
}
}
19 changes: 19 additions & 0 deletions Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets>
<widget type="/Deprecated">
<label translate="true">Catalog New Products List</label>
<description translate="true">List of Products that are set as New</description>
<supported_blocks>Deprecated
<block>
<block_name>Deprecated</block_name>
</block>
</supported_blocks>
</widget>
</widgets>

31 changes: 31 additions & 0 deletions Magento2/Tests/Legacy/WidgetXMLUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Tests\Legacy;

use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

class WidgetXMLUnitTest extends AbstractSniffUnitTest
{
/**
* @inheritdoc
*/
public function getErrorList($testFile = '')
{
return [
9 => 1,
12 => 1,
14 => 1,
];
}

/**
* @inheritdoc
*/
public function getWarningList($testFile = '')
{
return [];
}
}