<?xml version="1.0"?>
<ruleset name="Webthink">
    <description>The coding standard for webthink</description>

    <exclude-pattern>\.git</exclude-pattern>
    <exclude-pattern>*/vendor/*</exclude-pattern>

    <arg name="colors" />
    <arg value="s" />

    <!-- Use the PSR2 Standard-->
    <rule ref="PSR2" />

    <!-- Always user array brackets -->
    <rule ref="Generic.Arrays.DisallowLongArraySyntax" />
    <rule ref="Generic.CodeAnalysis.AssignmentInCondition" />
    <rule ref="Generic.CodeAnalysis.EmptyStatement" />
    <rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
    <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall" />
    <rule ref="Generic.CodeAnalysis.JumbledIncrementer" />
    <rule ref="Generic.CodeAnalysis.UnconditionalIfStatement" />

    <!-- Do not use final both in class and functions -->
    <rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier" />
    <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
        <!-- Relax for tests -->
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>
    <rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />

    <rule ref="Generic.Files.OneObjectStructurePerFile" />
    <rule ref="Generic.Formatting.NoSpaceAfterCast" />

    <!-- Default cyclomatic is on 10 for warning and 20 for error -->
    <rule ref="Generic.Metrics.CyclomaticComplexity" />

    <!-- Based on Object calisthenics we should avoid deep nesting -->
    <rule ref="Generic.Metrics.NestingLevel">
        <properties>
            <property name="nestingLevel" value="3" />
            <property name="absoluteNestingLevel" value="4" />
        </properties>
    </rule>

    <!-- Disallow old PHP4 constructor names -->
    <rule ref="Generic.NamingConventions.ConstructorName" />

    <!-- Forbid any content before opening tag -->
    <rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />

    <rule ref="Generic.Strings.UnnecessaryStringConcat">
        <properties>
            <property name="error" value="false" />
        </properties>
    </rule>
    <rule ref="Generic.PHP.DeprecatedFunctions" />
    <rule ref="Squiz.Arrays.ArrayBracketSpacing" />
    <rule ref="Squiz.Classes.ClassFileName" />
    <rule ref="Squiz.Classes.LowercaseClassKeywords" />
    <rule ref="Squiz.Classes.SelfMemberReference" />
    <rule ref="Squiz.Commenting.DocCommentAlignment" />
    <rule ref="Squiz.Operators.ValidLogicalOperators" />
    <rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops">
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>
    <rule ref="Squiz.PHP.Eval" />
    <rule ref="Squiz.PHP.LowercasePHPFunctions" />
    <rule ref="Squiz.PHP.NonExecutableCode" />
    <rule ref="Squiz.Scope.StaticThisUsage" />

    <!-- Spacing rules -->
    <rule ref="Squiz.Strings.ConcatenationSpacing">
        <properties>
            <!-- The one space policy is applied according to PSR-12 -->
            <property name="spacing" value="1" />
            <property name="ignoreNewlines" value="true" />
        </properties>
    </rule>
    <rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace" />
    <rule ref="Squiz.WhiteSpace.SemicolonSpacing" />
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
        <properties>
            <property name="ignoreBlankLines" value="false" />
        </properties>
    </rule>
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
        <severity>10</severity>
    </rule>
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
        <severity>10</severity>
    </rule>
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
        <severity>10</severity>
    </rule>

    <!-- Do not use a close tag for PHP -->
    <rule ref="Zend.Files.ClosingTag" />

    <!-- Do not allow variables that are not CamelCase -->
    <rule ref="Zend.NamingConventions.ValidVariableName">
        <exclude name="Zend.NamingConventions.ValidVariableName.ContainsNumbers" />
        <exclude name="Zend.NamingConventions.ValidVariableName.StringVarContainsNumbers" />
        <exclude name="Zend.NamingConventions.ValidVariableName.MemberVarContainsNumbers" />
        <exclude name="Zend.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
    </rule>

    <rule ref="Webthink.Commenting">
        <exclude name="Webthink.Commenting.DeprecatedTags" />
    </rule>

    <rule ref="Webthink.Metrics.MethodPerClassLimit">
        <!-- Relax some rules for tests -->
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>
    <rule ref="Webthink.Metrics.MethodParametersLimit">
        <!-- Relax some rules for tests -->
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>

    <rule ref="Webthink.NamingConventions">
        <exclude name="Webthink.NamingConventions.PluralClassName" />
        <exclude name="Webthink.NamingConventions.SingularClassName" />
    </rule>
    <!-- On tests you do not want to prefix the Test classes with `Abstract` -->
    <rule ref="Webthink.NamingConventions.ValidAbstractName">
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>

    <!-- Rules related to comments -->
    <rule ref="PEAR.Commenting.ClassComment">
        <!-- Relax the rule for tests -->
        <exclude-pattern>*/tests/*</exclude-pattern>
        <exclude name="PEAR.Commenting.ClassComment.MissingPackageTag" />
        <exclude name="PEAR.Commenting.ClassComment.MissingAuthorTag" />
        <exclude name="PEAR.Commenting.ClassComment.MissingCategoryTag" />
        <exclude name="PEAR.Commenting.ClassComment.MissingLinkTag" />
        <exclude name="PEAR.Commenting.ClassComment.MissingLicenseTag" />
    </rule>

    <rule ref="PEAR.Commenting.FunctionComment">
        <!-- Relax the rule for tests -->
        <exclude-pattern>*/tests/*</exclude-pattern>
        <exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParamType" />
        <exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParamName" />
        <exclude name="PEAR.Commenting.FunctionComment.MissingParamComment" />
    </rule>
    <!-- Do not use # for comments -->
    <rule ref="PEAR.Commenting.InlineComment" />
</ruleset>
