Skip to content

AC-663 PHPCS classes test #274

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

Conversation

svera
Copy link
Contributor

@svera svera commented Sep 16, 2021

This second part of AC-663 is focused on checking that all references to classes in xml files under etc follows PSR standards.

</field>
<field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" canRestore="1">
<label>New Order Status</label>
<source_model>Sales\MODEL\Config\Source\Order\Status\NewStatus</source_model>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this line? Should it work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcuerdo is not in the Magento namespace, thus it is ignored

}
if ($testFile === 'ClassesConfigurationUnitTest.2.xml') {
return [
22 => 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lines 22 and 42 there are no classes...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcuerdo sniffer returns the position of the opening tag where the issue happens

$classes = $this->getXmlNode(
$xml,
'
/config//resource_adapter | /config/*[not(name()="sections")]//class[not(ancestor::observers)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regexp must be updated almost certainly, as I think some of these paths are no longer accurate. Could you please check them out @sivaschenko ?

</field>
<field id="order_status" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" canRestore="1">
<label>New Order Status</label>
<source_model>Sales\MODEL\Config\Source\Order\Status\NewStatus</source_model>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcuerdo is not in the Magento namespace, thus it is ignored

}
if ($testFile === 'ClassesConfigurationUnitTest.2.xml') {
return [
22 => 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcuerdo sniffer returns the position of the opening tag where the issue happens

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @svera ! Please see my review comments

@svera svera marked this pull request as ready for review October 13, 2021 10:51
loginesta
loginesta previously approved these changes Oct 13, 2021
@@ -148,6 +148,14 @@
<exclude-pattern>*\.xml$</exclude-pattern>
<exclude-pattern>*\.js$</exclude-pattern>
</rule>
<rule ref="Magento2.Legacy.ClassReferencesInConfigurationFiles">
<include-pattern>*\/etc/*.xml$</include-pattern>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout files are tested in this sniff as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivaschenko there are also checks which involve references to classes in layouts, look at collectClassesInLayout(). Maybe we should rename this sniff to ClassReferencesInXMLFilesSniff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the naming is fine. Should we add the include pattern for layout files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed layout files check from sniff, so I guess we no longer need to include its pattern here @sivaschenko

{
return $this->getValuesFromXmlTagAttribute(
$xml,
'/layout//@module',
Copy link
Contributor Author

@svera svera Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivaschenko I see a lot of occurrences of <page layout="... but none of <layout>... module=""> which are the ones we are looking for at the moment. Are these also outdated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this check can be removed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as talked offline @sivaschenko

@svera
Copy link
Contributor Author

svera commented Oct 14, 2021

@magento import pr to magento-commerce/magento-coding-standard

@m2-github-services
Copy link
Contributor

@svera the Pull Request is successfully imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants