init
This commit is contained in:
66
README.md
Normal file
66
README.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Sept coding standard
|
||||||
|
|
||||||
|
We are using [PHP CodeSniffer][1] with the great [Symfony PHP CodeSniffer Coding Standard
|
||||||
|
of djoos][2] and some sniffs of [Slevomat Coding Standard][3], both adopted to our own needs.
|
||||||
|
|
||||||
|
|
||||||
|
## Goals of our coding standard
|
||||||
|
|
||||||
|
* Using already existing standards (PSR-1, PSR-2, Symfony).
|
||||||
|
* Coding standard can be used across different projects.
|
||||||
|
* Avoid duplications (also between code, CVS history and documentation).
|
||||||
|
* Ensure code quality across different dev setups (e.g. different IDEs).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
If you use [Composer][4], you can install ProjektMOTOR Coding Standard in your project with the following
|
||||||
|
command:
|
||||||
|
|
||||||
|
```BASH
|
||||||
|
composer require --dev 1sept/sept-coding-standard
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional: To install coding standard automatically edit your composer script:
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
scripts: {
|
||||||
|
"post-install-cmd": [
|
||||||
|
"@auto-scripts"
|
||||||
|
],
|
||||||
|
"post-update-cmd": [
|
||||||
|
"@auto-scripts"
|
||||||
|
],
|
||||||
|
"auto-scripts": {
|
||||||
|
"phpcs --config-set installed_paths vendor/1sept/1sept-coding-standard/ProjektMOTORCodingStandard/": "script",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Just create a `phpcs.xml.dist` in your project's root directory with the following content:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ruleset name="projektmotor-coding-standard">
|
||||||
|
<rule ref="vendor/1sept/1sept-coding-standard/ruleset.xml">
|
||||||
|
<!-- If the standard is too hard, you can exclude some rules like this: -->
|
||||||
|
<!-- <exclude name="Generic.Arrays.DisallowLongArraySyntax.Found" /> -->
|
||||||
|
<!-- <exclude name="Generic.Files.LineLength.TooLong" /> -->
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<!-- Exclude project specific files if you want -->
|
||||||
|
<!-- <exclude-pattern>WakkaFormatter</exclude-pattern> -->
|
||||||
|
</ruleset>
|
||||||
|
```
|
||||||
|
|
||||||
|
And then you can execute the CodeSniffer like this:
|
||||||
|
|
||||||
|
vendor/bin/phpcs -s -p --colors src/
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
[1]: https://github.com/squizlabs/PHP_CodeSniffer#readme
|
||||||
|
[2]: https://github.com/djoos/Symfony-coding-standard
|
||||||
|
[3]: https://github.com/slevomat/coding-standard
|
||||||
|
[4]: https://getcomposer.org/
|
||||||
25
composer.json
Normal file
25
composer.json
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "1sept/sept-coding-standard",
|
||||||
|
"type": "phpcodesniffer-standard",
|
||||||
|
"description": "Internal PHP coding standard of Sept",
|
||||||
|
"keywords": ["coding standard", "phpcs", "psr", "code sniffer", "symfony"],
|
||||||
|
"homepage": "https://1sept.ru",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "First September",
|
||||||
|
"homepage": "https://1sept.ru"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"slevomat/coding-standard": ">=8.19",
|
||||||
|
"squizlabs/php_codesniffer": "^3.0"
|
||||||
|
},
|
||||||
|
"support" : {
|
||||||
|
"source": "https://git.1sept.ru/1sept/sept-coding-standard.git",
|
||||||
|
"issues": "https://git.1sept.ru/1sept/sept-coding-standard.git/issues"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"squizlabs/php_codesniffer": "<3 || >=4"
|
||||||
|
}
|
||||||
|
}
|
||||||
206
ruleset.xml
Normal file
206
ruleset.xml
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
|
||||||
|
|
||||||
|
<arg name="basepath" value="."/>
|
||||||
|
<arg name="cache" value=".phpcs-cache"/>
|
||||||
|
<arg name="colors"/>
|
||||||
|
<arg name="extensions" value="php"/>
|
||||||
|
|
||||||
|
<rule ref="PSR12">
|
||||||
|
<exclude name="Generic.Files.LineLength"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml"><!-- relative path to your ruleset.xml -->
|
||||||
|
<!-- sniffs to exclude because of deprecation -->
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat" />
|
||||||
|
<!-- keep it for debugging reasons to be able to list all rules vendor/bin/phpcs -e | grep SlevomatCodingStandard -->
|
||||||
|
<!--<exclude name="*" />-->
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.RequireSingleLineCall.RequiredSingleLineCall" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Attributes.AttributesOrder" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Files.FileLength.FileTooLong" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.ClassLength.ClassTooLong" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.DisallowArrowFunction.DisallowedArrowFunction" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Exceptions.DisallowNonCapturingCatch.DisallowedNonCapturingCatch" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion.DisallowedConstructorPropertyPromotion" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Files.FunctionLength.FunctionLength" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.FunctionLength.FunctionLength" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall.DisallowedTrailingComma" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.DisallowNamedArguments.DisallowedNamedArgument" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration.MissingTrailingComma" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.ClassStructure.IncorrectGroupOrder" />
|
||||||
|
<exclude name="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall.DisallowDirectMagicInvokeCall" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.RequireArrowFunction.RequiredArrowFunction" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature.RequiredSingleLineSignature" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature.RequiredMultiLineSignature" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Files.LineLength.LineTooLong" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode.DisallowedCommentAfterCode" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Numbers.RequireNumericLiteralSeparator.RequiredNumericLiteralSeparator" />
|
||||||
|
|
||||||
|
<!-- Не работает фикс -->
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceBeforeDeclare" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountBeforeFirstUse" />
|
||||||
|
<!-- Хорошее правило, может его надо включить! -->
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment.OneLinePropertyComment" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountAfterLastUse" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountAfterControlStructure" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix" />
|
||||||
|
|
||||||
|
<!-- <exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces.NonFullyQualified" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators.DisallowedPostIncrementOperator" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing.IncorrectLinesCountBeforeControlStructure" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountBeforeControlStructure" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing.IncorrectLinesCountAfterControlStructure" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants.DisallowedLateStaticBindingForConstant" /> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountAfterLastUse" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.TraitUseSpacing.IncorrectLinesCountBeforeFirstUse" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment.OneLinePropertyComment" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDifferentAnnotationsTypes" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.UselessFunctionDocComment" /> -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <exclude name="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowEmpty.DisallowedEmpty" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator.DisallowedShortTernaryOperator" /> -->
|
||||||
|
<!-- Hello PHP 8 -->
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowNullSafeObjectOperator.DisallowedNullSafeObjectOperator" />
|
||||||
|
<!-- cause they are allowed and wanted in symfony -->
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison.DisallowedYodaComparison" />
|
||||||
|
<!-- threw a false positive in ArticleImportCommand of HSM -->
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses" />
|
||||||
|
|
||||||
|
<!-- <exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator.RequiredShortTernaryOperator" />
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.RequireYodaComparison.RequiredYodaComparison" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall.MissingTrailingComma" /> -->
|
||||||
|
|
||||||
|
<!-- didn't work with symfony form types cause of unused param options -->
|
||||||
|
<exclude name="SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions.NonFullyQualifiedException"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
|
||||||
|
<!-- $count++ is not allowed wtf -->
|
||||||
|
<exclude name="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators"/>
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
|
||||||
|
|
||||||
|
<!-- Хорошее правило но надо настраивать под него проект -->
|
||||||
|
<exclude name="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix" />
|
||||||
|
|
||||||
|
<!-- <exclude name="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax.DisallowedArrayTypeHintSyntax"/>
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint" />
|
||||||
|
<exclude name="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable" />
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint" /> -->
|
||||||
|
<exclude name="Generic.Files.LineLength.MaxExceeded" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />
|
||||||
|
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />
|
||||||
|
|
||||||
|
<!-- Хорошее правило Assignment in if condition is not allowed -->
|
||||||
|
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.AssignmentInCondition" />
|
||||||
|
|
||||||
|
<exclude name="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration.MissingDescription" />
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
|
||||||
|
<properties>
|
||||||
|
<property name="searchAnnotations" value="true"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
|
||||||
|
<properties>
|
||||||
|
<property name="spacesCountAroundEqualsSign" value="0"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
|
||||||
|
<properties>
|
||||||
|
<property name="rootNamespaces" type="array">
|
||||||
|
<element key="src" value="App"/>
|
||||||
|
<element key="tests" value="App\Tests"/>
|
||||||
|
<element key="tests/features/bootstrap" value="App\Tests\Behat"/>
|
||||||
|
</property>
|
||||||
|
<property name="ignoredNamespaces" type="array">
|
||||||
|
<element value="DoctrineMigrations"/>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
|
||||||
|
<properties>
|
||||||
|
<property name="linesCountAfterOpeningBrace" value="0"/>
|
||||||
|
<property name="linesCountBeforeClosingBrace" value="0"/>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
|
||||||
|
<properties>
|
||||||
|
<property name="linesCountBeforeDeclare" value="0" />
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="SlevomatCodingStandard.Attributes.AttributesOrder">
|
||||||
|
<properties>
|
||||||
|
<property name="order" type="array">
|
||||||
|
<element value="ORM\Table"/>
|
||||||
|
<element value="ORM\Entity"/>
|
||||||
|
<element value="ORM\"/>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<file>src/</file>
|
||||||
|
<file>tests/</file>
|
||||||
|
<file>config/</file>
|
||||||
|
<file>public/</file>
|
||||||
|
|
||||||
|
<exclude-pattern>./src/Migrations/*</exclude-pattern>
|
||||||
|
<exclude-pattern>./src/Kernel.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./public/index.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./config/bundles.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./config/bootstrap.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./config/preload.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./tests/features/bootstrap/bootstrap.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./tests/object-manager.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./tests/symfony-container.php</exclude-pattern>
|
||||||
|
<exclude-pattern>./tests/bootstrap.php</exclude-pattern>
|
||||||
|
|
||||||
|
</ruleset>
|
||||||
|
|
||||||
|
<!-- composer require "squizlabs/php_codesniffer=*" dev -->
|
||||||
|
<!-- composer require slevomat/coding-standard dev -->
|
||||||
Reference in New Issue
Block a user