PHPLIB-330: Add first version of our coding standard

parent a72cbe38
......@@ -7,3 +7,7 @@ vendor/
phpunit.phar
phpunit.xml
.phpunit.result.cache
# phpcs
.phpcs-cache
phpcs.xml
<?php
// Since doctrine/coding-standard requires PHP 7, we can't add it as a dependency
// yet. This autoload file adds more information to the phpcs error message,
// telling the user how they can fix the error presented to them by phpcs.
if (! file_exists(__DIR__ . '/../vendor/doctrine/coding-standard')) {
echo <<<ERRORMESSAGE
==============================================================================
ERROR: Doctrine coding standard is not installed. To rectify this, please run:
composer require --dev doctrine/coding-standard=^6.0
==============================================================================
ERRORMESSAGE;
}
......@@ -18,6 +18,7 @@
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
"sebastian/comparator": "^1.0 || ^2.0 || ^3.0",
"squizlabs/php_codesniffer": "^3.4",
"symfony/phpunit-bridge": "^4.4@dev"
},
"autoload": {
......
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors" />
<!-- Ignore warnings, show progress of the run, and show sniff names -->
<arg value="nps"/>
<autoload>.phpcs/autoload.php</autoload>
<file>.phpcs</file>
<file>src</file>
<file>tests</file>
<rule ref="Doctrine">
<!-- Exclude sniffs that require newer PHP versions -->
<!-- Available with PHP 7.0 -->
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
<!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration" />
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
<!-- Available with PHP 7.1 -->
<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
<exclude name="SlevomatCodingStandard.PHP.ShortList.LongListUsed" />
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
<!-- No statement alignment so far -->
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
<!-- Class naming sniffs are excluded to preserve BC -->
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming" />
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming" />
<!-- Forbid useless annotations - Git and LICENCE file provide more accurate information -->
<!-- Disable forbidden annotation sniff as excluding @api from the list doesn't work -->
<exclude name="SlevomatCodingStandard.Commenting.ForbiddenAnnotations.AnnotationForbidden" />
<!-- Keep long typehints (for now) -->
<exclude name="SlevomatCodingStandard.PHP.TypeCast.InvalidCastUsed" />
<exclude name="SlevomatCodingStandard.TypeHints.LongTypeHints" />
<!-- Don't require a full stop after @throws tags -->
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
<!-- Disable some sniffs as they can cause functional changes. These will be enabled later -->
<exclude name="Generic.PHP.ForbiddenFunctions.FoundWithAlternative" />
<exclude name="SlevomatCodingStandard.Classes.UnusedPrivateElements" />
<exclude name="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison" />
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit" />
<exclude name="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn" />
<exclude name="SlevomatCodingStandard.Functions.StaticClosure" />
<exclude name="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<exclude name="SlevomatCodingStandard.Operators.DisallowEqualOperators" />
<!-- These sniffs cause a large diff, so enable them in separate steps -->
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup" />
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
<exclude name="Squiz.Strings.DoubleQuoteUsage" />
<!-- Sniff currently breaks, see https://github.com/slevomat/coding-standard/issues/727 -->
<exclude name="SlevomatCodingStandard.Namespaces.NamespaceSpacing" />
</rule>
<!-- Change use statement sorting to be compatible with PSR-12 -->
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="psr12Compatible" value="true"/>
</properties>
</rule>
<!-- Forbid fully qualified names even for colliding names -->
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="allowFallbackGlobalConstants" value="false"/>
<property name="allowFallbackGlobalFunctions" value="false"/>
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingClasses" value="false"/>
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingConstants" value="false"/>
<property phpcs-only="true" name="allowFullyQualifiedNameForCollidingFunctions" value="false"/>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>/src/GridFS/StreamWrapper</exclude-pattern>
<exclude-pattern>/tests/DocumentationExamplesTest.php</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>/tests/Compat/PolyfillAssertTrait.php</exclude-pattern>
</rule>
</ruleset>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment