Skip to content

Commit 1fd207f

Browse files
committed
Initial commit with adopted rules of symfony and slevomat coding standard
1 parent 6a84aa8 commit 1fd207f

File tree

3 files changed

+224
-1
lines changed

3 files changed

+224
-1
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="ProjektMOTOR">
3+
<description>The ProjektMOTOR coding standard.</description>
4+
5+
<rule ref="PSR1.Methods.CamelCapsMethodName">
6+
<exclude-pattern>tests/*</exclude-pattern>
7+
</rule>
8+
9+
<!-- Include the whole Symfony standard -->
10+
<rule ref="vendor/escapestudios/symfony2-coding-standard/Symfony/ruleset.xml"><!-- relative path to your ruleset.xml -->
11+
<!-- sniffs to exclude -->
12+
<exclude name="Symfony.Commenting.ClassComment.Missing" />
13+
<exclude name="Symfony.Commenting.FunctionComment.Missing" />
14+
<exclude name="Symfony.Commenting.License.Warning" />
15+
<exclude name="Symfony.Functions.Arguments.Invalid" />
16+
<exclude name="Symfony.NamingConventions.ValidClassName.InvalidInterfaceName" />
17+
<exclude name="Symfony.NamingConventions.ValidClassName.InvalidTraitName" />
18+
<exclude name="Squiz.Strings.ConcatenationSpacing.PaddingFound" />
19+
</rule>
20+
21+
22+
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml"><!-- relative path to your ruleset.xml -->
23+
<!-- keep it for debugging reasons to be able to list all rules vendor/bin/phpcs -e | grep SlevomatCodingStandard -->
24+
<!--<exclude name="*" />-->
25+
<exclude name="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants.DisallowedLateStaticBindingForConstant" />
26+
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountAfterLastUse" />
27+
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountBeforeFirstUse" />
28+
<exclude name="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment.OneLinePropertyComment" />
29+
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes" />
30+
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
31+
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterControlStructure" />
32+
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowEmpty.DisallowedEmpty" />
33+
<!-- cause they are allowed and wanted in symfony -->
34+
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison.DisallowedYodaComparison" />
35+
<!-- threw a false positive in ArticleImportCommand of HSM -->
36+
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed" />
37+
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses" />
38+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed" />
39+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator.RequiredShortTernaryOperator" />
40+
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison" />
41+
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma" />
42+
<!-- didn't work with symfony form types cause of unused param options -->
43+
<exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter" />
44+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
45+
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException"/>
46+
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
47+
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
48+
<!-- $count++ is not allowed wtf -->
49+
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator"/>
50+
<exclude name="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax"/>
51+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
52+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
53+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessDocComment"/>
54+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessParameterAnnotation"/>
55+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation"/>
56+
</rule>
57+
58+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
59+
<properties>
60+
<property name="searchAnnotations" value="true"/>
61+
</properties>
62+
</rule>
63+
64+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
65+
<properties>
66+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
67+
<property name="spacesCountAroundEqualsSign" value="0"/>
68+
</properties>
69+
</rule>
70+
71+
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
72+
<properties>
73+
<property
74+
name="rootNamespaces"
75+
type="array"
76+
value="
77+
tests=>App\Tests,
78+
src=>App,
79+
"
80+
/>
81+
<property name="ignoredNamespaces" type="array" value="DoctrineMigrations"/>
82+
</properties>
83+
</rule>
84+
85+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName">
86+
<exclude-pattern>config/bundles.php</exclude-pattern>
87+
<exclude-pattern>src/Kernel.php</exclude-pattern>
88+
</rule>
89+
90+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
91+
<properties>
92+
<property
93+
name="usefulAnnotations"
94+
type="array"
95+
value="
96+
@after,
97+
@before,
98+
@dataProvider,
99+
@deprecated,
100+
@required,
101+
@see,
102+
@ApiDoc,
103+
@Assert\,
104+
@QueryParam,
105+
@ORM\,
106+
@ParamConverter,
107+
@Route,
108+
@Template,
109+
@Security,
110+
@Method,
111+
@IsGranted,
112+
@Operation
113+
"
114+
/>
115+
<property name="enableEachParameterAndReturnInspection" value="true"/>
116+
</properties>
117+
</rule>
118+
119+
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
120+
<properties>
121+
<property name="linesCountAfterOpeningBrace" value="0"/>
122+
<property name="linesCountBeforeClosingBrace" value="0"/>
123+
</properties>
124+
</rule>
125+
126+
<rule ref="Generic.Files.LineLength">
127+
<properties>
128+
<property name="lineLimit" value="150" />
129+
<property name="absoluteLineLimit" value="150" />
130+
</properties>
131+
</rule>
132+
133+
<exclude-pattern>./src/Migrations/*</exclude-pattern>
134+
<exclude-pattern>./public/index.php</exclude-pattern>
135+
<exclude-pattern>./config/bundles.php</exclude-pattern>
136+
<exclude-pattern>./config/bootstrap.php</exclude-pattern>
137+
138+
<file>bin/</file>
139+
<file>config/</file>
140+
<file>public/</file>
141+
<file>src/</file>
142+
<file>tests/</file>
143+
144+
</ruleset>

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# symfony-coding-standard
2-
Symfony coding standards for ProjektMOTOR enriched by several useful rules
2+
Symfony coding standards for ProjektMOTOR enriched by several useful rules.
3+
4+
We at ProjektMOTOR love clean code. So we have a have an internal PHP coding standard based on
5+
symfony coding standard
6+
used for all our projects. We are using [PHP CodeSniffer][1] with the great [Symfony PHP CodeSniffer Coding Standard
7+
of djoos][2] and some sniffs of [Slevomat Coding Standard][3], both adopted to our own needs.
8+
9+
## Goals of our coding standard
10+
11+
* Using already existing standards (PSR-1, PSR-2)
12+
* Coding standard across different projects
13+
* Avoid duplications (also between code, CVS history and documentation)
14+
15+
## Installation
16+
17+
If you use [Composer][4], you can install ProjektMOTOR Coding Standard in your project with the following
18+
command:
19+
20+
```BASH
21+
composer require --dev projektmotor/coding-standard
22+
```
23+
24+
## Usage
25+
26+
Just create a `phpcs.xml.dist` in your project's root directory with the following content:
27+
28+
```xml
29+
<?xml version="1.0" encoding="UTF-8"?>
30+
<ruleset name="projektmotor-coding-standard">
31+
<rule ref="vendor/projektmotor/symfony-coding-standard/ProjektMOTORCodingStandard/ruleset.xml">
32+
<!-- If the standard is too hard, you can exclude some rules like this: -->
33+
<!-- <exclude name="Generic.Arrays.DisallowLongArraySyntax.Found" /> -->
34+
<!-- <exclude name="Generic.Files.LineLength.TooLong" /> -->
35+
</rule>
36+
37+
<!-- Exclude project specific files if you want -->
38+
<!-- <exclude-pattern>WakkaFormatter</exclude-pattern> -->
39+
</ruleset>
40+
```
41+
42+
And then you can execute the CodeSniffer like this:
43+
44+
vendor/bin/phpcs -s -p --colors src/
45+
46+
47+
---
48+
[1]: https://github.com/squizlabs/PHP_CodeSniffer#readme
49+
[2]: https://github.com/djoos/Symfony-coding-standard
50+
[3]: https://github.com/slevomat/coding-standard
51+
[4]: https://getcomposer.org/

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "projektmotor/symfony-coding-standard",
3+
"type": "phpcodesniffer-standard",
4+
"description": "Internal PHP coding standard of ProjektMOTOR",
5+
"keywords": ["coding standard", "phpcs", "psr", "code sniffer", "symfony"],
6+
"homepage": "https://www.projektmotor.de",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Robert Freigang",
11+
"email": "robert.freigang@projektmotor.de"
12+
},
13+
{
14+
"name": "ProjektMOTOR GmbH",
15+
"homepage": "https://www.projektmotor.de"
16+
}
17+
],
18+
"require": {
19+
"escapestudios/symfony2-coding-standard": "^3.5",
20+
"slevomat/coding-standard": "^5.0",
21+
"squizlabs/php_codesniffer": "^3.0"
22+
},
23+
"support" : {
24+
"source": "https://github.com/projektmotor/symfony-coding-standard",
25+
"issues": "https://github.com/projektmotor/symfony-coding-standard/issues"
26+
},
27+
"conflict": {
28+
"squizlabs/php_codesniffer": "<3 || >=4"
29+
}
30+
}

0 commit comments

Comments
 (0)