Skip to content

Commit aed5868

Browse files
authored
Merge pull request #3 from YouweGit/youwe-magento2
Added magento/magento-coding-standard to keep closer to Magento standards
2 parents 2913e79 + 5c29465 commit aed5868

File tree

8 files changed

+146
-91
lines changed

8 files changed

+146
-91
lines changed

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 2.0.0
8+
### Added
9+
- Composer package youwe/coding-standard which is now included in the Youwe coding standards for Magento 2.
10+
- Comments for why the ruleset was added.
11+
- Coding standards for phtml templates.
12+
- Package [magento/magento-coding-standard](https://github.com/magento/magento-coding-standard) as a requirement.
13+
The version v25 is used as a base. If not compatible please update the `phpcs.xml` in project root.
14+
15+
### Removed
16+
- Rule PSR2.Methods.MethodDeclaration.Underscore since this is already excluded by Magento.
17+
- Argument colors and added it in the common Youwe coding standards.
18+
- Old coding ruleset directories and migrated them to YouweMagento2.
19+
720
## 1.7.0 - 2021-12-24
821
### Changed
922
- Vendor from MediactMagento2 to Magento2
1023
- Copyrights.
1124

1225
### Removed
13-
- Dependency squizlabs/php_codesniffer.
26+
- Dependency squizlabs/php_codesniffer.

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Introduction
22

3-
This is the MediaCT coding standard for Magento 2 projects. It is based on
4-
the default MediaCT coding standard but some tests have been removed to create
3+
This is the Youwe coding standard for Magento 2 projects. It is based on
4+
the default Magento2 coding standard but some tests have been removed to create
55
a workable and fast standard.
66

77
# Installation
88

99
Use composer to require the standard in a project.
1010

1111
```shell
12-
composer require --dev mediact/coding-standard-magento2
12+
composer require --dev youwe/coding-standard-magento2 -W
1313
```
1414

1515
To let PHPCS know that this standard should be used add a phpcs.xml file in the
@@ -18,20 +18,20 @@ root of the project.
1818
```xml
1919
<?xml version="1.0"?>
2020
<ruleset>
21-
<rule ref="./vendor/mediact/coding-standard-magento2/src/MediactMagento2"/>
21+
<rule ref="YouweMagento2"/>
2222
</ruleset>
2323
```
2424

2525
# Integration with PHPStorm and automatic testing
2626

2727
The recommended way to enable the coding standard in PHPStorm and automatic
28-
testing is by requiring the MediaCT testing suite in a project.
28+
testing is by requiring the Youwe testing suite in a project.
2929

3030
```shell
31-
composer require --dev mediact/testing-suite
31+
composer require --dev youwe/testing-suite
3232
```
3333

34-
For more information go to [MediaCT Testing Suite](https://github.com/mediact/testing-suite).
34+
For more information go to [Youwe Testing Suite](https://github.com/YouweGit/testing-suite).
3535

3636
# Contribution guidelines
3737

composer.json

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
{
22
"name": "youwe/coding-standard-magento2",
33
"description": "Youwe PHP Coding Standard for Magento2",
4-
"type": "phpcs-sniffs",
5-
"homepage": "https://github.com/YouweGit/coding-standard-magento2",
64
"license": "proprietary",
5+
"type": "phpcodesniffer-standard",
76
"authors": [
87
{
98
"name": "Youwe B.V.",
109
"email": "[email protected]"
1110
}
1211
],
12+
"homepage": "https://github.com/YouweGit/coding-standard-magento2",
1313
"require": {
14-
"youwe/coding-standard": ">=3.3.0"
14+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
15+
"magento/magento-coding-standard": ">= 9",
16+
"youwe/coding-standard": "^3.5.0"
1517
},
1618
"autoload": {
1719
"psr-0": {
18-
"MediactMagento2": "src/MediactMagento2",
19-
"Magento2": "src/Magento2"
20+
"YouweMagento2": "src/YouweMagento2"
2021
}
22+
},
23+
"config": {
24+
"allow-plugins": {
25+
"dealerdirect/phpcodesniffer-composer-installer": true
26+
},
27+
"sort-packages": true
2128
}
2229
}

src/Magento2/ruleset.xml

-50
This file was deleted.

src/MediactMagento2/phpmd.xml

-17
This file was deleted.

src/MediactMagento2/ruleset.xml

-11
This file was deleted.
File renamed without changes.

src/YouweMagento2/ruleset.xml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright Youwe. All rights reserved.
5+
* https://www.youweagency.com
6+
*
7+
* TODO:: Create a separate ruleset for phtml files, since a lot of exceptions need to be made just for adding phtml to code sniffer.
8+
*/
9+
-->
10+
<ruleset name="YouweMagento2">
11+
<description>Youwe coding standards for Magento2 websites and modules</description>
12+
<!-- TODO:: Check if these values are correct. Did not see anything about how to configure this in documentation -->
13+
<arg name="extensions" value="php/PHP,phtml/PHP,js/JS,css/CSS,xml/XML,less/CSS" />
14+
15+
<!-- Base rules on Youwe -->
16+
<rule ref="Youwe">
17+
<!-- Magento 2 does not use return types everywhere in the code base yet. So we cannot make this mandatory. -->
18+
<exclude name="GlobalCommon.Php7.ReturnType" />
19+
<!-- Magento 2 still uses $_ to tell if it's protected, so we cannot mandate this. -->
20+
<exclude name="GlobalCommon.NamingConventions.ValidVariableName" />
21+
<!-- TODO:: Check if this rule still needs to be excluded. Seems logical that all classes should start with camelcase -->
22+
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
23+
<!--TODO:: Check if this should not be excluded. Seems logical to add throws in function comment. -->
24+
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" />
25+
<!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. -->
26+
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" />
27+
<!-- Magento 2 still does not strict type arguments of functions. This is why this rule is excluded. -->
28+
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing" />
29+
</rule>
30+
31+
<!-- Import most rules from official Magento2 coding standard -->
32+
<rule ref="Magento2">
33+
<!-- Excluded because short descriptions are not mandatory in Youwe for a method. -->
34+
<exclude name="Magento2.Annotation" />
35+
<!--
36+
Excluded because in PHP 8.1 it's already possible to declare what type it is.
37+
Also most class properties are self-explanatory.
38+
-->
39+
<exclude name="Magento2.Commenting.ClassPropertyPHPDocFormatting" />
40+
</rule>
41+
42+
<!-- Detects function that use a for-loops call in their function. -->
43+
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed">
44+
<exclude-pattern>*.phtml</exclude-pattern>
45+
</rule>
46+
47+
<rule ref="Generic.Commenting.DocComment">
48+
<!-- default Magento 2 templates also not cohere to this. -->
49+
<exclude-pattern>*.phtml</exclude-pattern>
50+
</rule>
51+
52+
<rule ref="Generic.ControlStructures.InlineControlStructure.NotAllowed">
53+
<!-- Magento 2 templates do not cohere to this rule. -->
54+
<exclude-pattern>*.phtml</exclude-pattern>
55+
</rule>
56+
57+
<rule ref="Generic.Files.LineLength.TooLong">
58+
<!-- Magento 2 phtml & xml both have long lines think of checkout_index_index.xml -->
59+
<exclude-pattern>*.phtml</exclude-pattern>
60+
<exclude-pattern>*.xml</exclude-pattern>
61+
</rule>
62+
63+
<rule ref="PEAR.Functions.FunctionCallSignature">
64+
<!-- default Magento 2 templates also not cohere to this. -->
65+
<exclude-pattern>*.phtml</exclude-pattern>
66+
</rule>
67+
68+
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
69+
<!-- In some cases Magento 2 still uses underscores for their properties. -->
70+
<exclude-pattern>*.phtml</exclude-pattern>
71+
</rule>
72+
73+
<rule ref="PSR2.ControlStructures.ControlStructureSpacing">
74+
<!-- default Magento 2 templates also not cohere to this. -->
75+
<exclude-pattern>*.phtml</exclude-pattern>
76+
</rule>
77+
78+
<rule ref="PSR12.ControlStructures.ControlStructureSpacing">
79+
<!-- default Magento 2 templates also not cohere to this. -->
80+
<exclude-pattern>*.phtml</exclude-pattern>
81+
</rule>
82+
83+
<rule ref="PSR12.Files.FileHeader.SpacingAfterBlock">
84+
<!-- default Magento 2 templates also not cohere to this. -->
85+
<exclude-pattern>*.phtml</exclude-pattern>
86+
</rule>
87+
88+
<rule ref="PSR12.Operators.OperatorSpacing">
89+
<!-- default Magento 2 templates also not cohere to this. -->
90+
<exclude-pattern>*.phtml</exclude-pattern>
91+
</rule>
92+
93+
<rule ref="Squiz.ControlStructures.ControlSignature">
94+
<!-- Magento 2 uses a different notation for patterns like do { / if { for phtml that's why this was excluded. -->
95+
<exclude-pattern>*.phtml</exclude-pattern>
96+
</rule>
97+
98+
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing">
99+
<!-- default Magento 2 templates also not cohere to this. -->
100+
<exclude-pattern>*.phtml</exclude-pattern>
101+
</rule>
102+
103+
<rule ref="Squiz.WhiteSpace.MemberVarSpacing" >
104+
<properties>
105+
<property name="spacingBeforeFirst" value="0"/>
106+
</properties>
107+
</rule>
108+
109+
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace">
110+
<!-- Magento 2 phptml files end differently and use endif; for example. -->
111+
<exclude-pattern>*.phtml</exclude-pattern>
112+
</rule>
113+
</ruleset>

0 commit comments

Comments
 (0)