<?xml version="1.0"?>
<ruleset name="Webimpress Coding Standard"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="../../vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <description>Webimpress Coding Standard</description>

    <!-- display progress -->
    <arg value="p"/>
    <arg name="colors"/>

    <!-- PSR-2 base -->
    <rule ref="PSR2">
        <!-- Below 2 rules are covered by Generic.PHP.LowerCaseKeyword -->
        <exclude name="Squiz.ControlStructures.LowercaseDeclaration"/>
        <exclude name="Squiz.Functions.LowercaseFunctionKeywords"/>
        <!-- Replaced by WebimpressCodingStandard.WhiteSpace.ScopeIndent -->
        <exclude name="Generic.WhiteSpace.ScopeIndent"/>
        <exclude name="PSR2.Methods.FunctionCallSignature.Indent"/>
        <exclude name="PSR2.Methods.FunctionCallSignature.OpeningIndent"/>
        <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.Indent"/>
        <exclude name="Squiz.WhiteSpace.ScopeClosingBrace.Indent"/>
        <!-- Replaced by WebimpressCodingStandard.WhiteSpace.BraceBlankLine -->
        <exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
        <exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
        <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
        <exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
        <!-- Replaced by WebimpressCodingStandard.WhiteSpace.CommaSpacing -->
        <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeComma"/>
        <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg"/>
        <!-- Replaced by WebimpressCodingStandard.Formatting.Reference.UnexpectedSpace -->
        <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterReference"/>
        <!-- Replaced by WebimpressCodingStandard.Formatting.NoSpaceAfterSplat.SpaceFound -->
        <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterVariadic"/>
        <!-- Replaced by WebimpressCodingStandard.NamingConventions.ValidVariableName -->
        <exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
        <!-- Replaced by Generic.NamingConventions.CamelCapsFunctionName -->
        <exclude name="PSR1.Methods.CamelCapsMethodName"/>
    </rule>

    <!-- Only one space after type in property declaration - PHP 7.4+ -->
    <rule ref="PSR2.Classes.PropertyDeclaration.SpacingAfterType">
        <severity>5</severity>
    </rule>

    <!-- Generic Rules -->
    <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
    <rule ref="Generic.Classes.DuplicateClassName"/>
    <rule ref="Generic.CodeAnalysis.EmptyStatement"/>
    <rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
    <rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
    <rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
    <rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
    <rule ref="Generic.Formatting.MultipleStatementAlignment">
        <properties>
            <property name="maxPadding" value="1"/>
            <property name="error" value="true"/>
        </properties>
    </rule>
    <rule ref="Generic.Formatting.SpaceAfterCast"/>
    <rule ref="Generic.Formatting.SpaceAfterNot"/>
    <rule ref="Generic.NamingConventions.ConstructorName"/>
    <rule ref="Generic.NamingConventions.CamelCapsFunctionName"/>
    <rule ref="Generic.PHP.DiscourageGoto"/>
    <rule ref="Generic.PHP.ForbiddenFunctions">
        <properties>
            <property name="forbiddenFunctions" type="array">
                <element key="chop" value="rtrim"/>
                <element key="close" value="closedir"/>
                <element key="compact" value="null"/>
                <element key="delete" value="unset"/>
                <element key="doubleval" value="floatval"/>
                <element key="extract" value="null"/>
                <element key="fputs" value="fwrite"/>
                <element key="ini_alter" value="ini_set"/>
                <element key="is_double" value="is_float"/>
                <element key="is_integer" value="is_int"/>
                <element key="is_long" value="is_int"/>
                <element key="is_null" value="null"/>
                <element key="is_real" value="is_float"/>
                <element key="is_writeable" value="is_writable"/>
                <element key="join" value="implode"/>
                <element key="key_exists" value="array_key_exists"/>
                <element key="pos" value="current"/>
                <element key="settype" value="null"/>
                <element key="show_source" value="highlight_file"/>
                <element key="sizeof" value="count"/>
                <element key="strchr" value="strstr"/>
            </property>
        </properties>
    </rule>
    <rule ref="Generic.Strings.UnnecessaryStringConcat">
        <properties>
            <property name="allowMultiline" value="true"/>
        </properties>
    </rule>
    <rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>

    <!-- PEAR Rules -->
    <rule ref="PEAR.Commenting.InlineComment"/>

    <!-- PSR-12 Rules -->
    <rule ref="PSR12.Classes.ClassInstantiation"/>
    <rule ref="PSR12.Functions.NullableTypeDeclaration"/>

    <!-- Squiz Rules -->
    <rule ref="Squiz.Classes.ClassFileName"/>
    <rule ref="Squiz.Classes.SelfMemberReference"/>
    <rule ref="Squiz.Operators.IncrementDecrementUsage"/>
    <rule ref="Squiz.Operators.ValidLogicalOperators"/>
    <rule ref="Squiz.PHP.DisallowMultipleAssignments">
        <exclude name="Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure"/>
    </rule>
    <rule ref="Squiz.PHP.LowercasePHPFunctions"/>
    <rule ref="Squiz.PHP.NonExecutableCode"/>
    <rule ref="Squiz.Scope.StaticThisUsage"/>
    <rule ref="Squiz.Strings.ConcatenationSpacing">
        <properties>
            <property name="spacing" value="1"/>
            <property name="ignoreNewlines" value="true"/>
        </properties>
    </rule>
    <rule ref="Squiz.Strings.DoubleQuoteUsage"/>
    <rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
        <message>Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead</message>
    </rule>
    <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
    <rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
    <rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
        <properties>
            <property name="ignoreNewlines" value="true"/>
        </properties>
    </rule>
    <rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
        <properties>
            <property name="ignoreBlankLines" value="false"/>
        </properties>
    </rule>
</ruleset>
