phpcs.xml.dist 6.2 KB
<?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" />
        <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="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>

    <!-- Only enable some checks regarding type hints -->
    <!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
    <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
        <!-- Traversable type hints often end up as mixed[], so we skip them for now -->
        <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
        <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
        <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />

        <!-- Will cause BC breaks to method signatures - disabled for now -->
        <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
        <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />

        <properties>
            <property name="enableObjectTypeHint" value="true" />
            <property name="enableEachParameterAndReturnInspection" value="false" />
        </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>