<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
         name="WordPress Coding Standards based custom ruleset for your plugin">
    <description>Generally-applicable sniffs for WordPress plugins.</description>

    <!-- What to scan -->
    <file>.</file>
    <exclude-pattern>/bin/</exclude-pattern>
    <exclude-pattern>/tests/</exclude-pattern>
    <exclude-pattern>/vendor/</exclude-pattern>
    <exclude-pattern>/node_modules/</exclude-pattern>

    <!-- How to scan -->
    <!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
    <!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
    <arg value="sp"/> <!-- Show sniff and progress -->
    <arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
    <!--    <arg name="colors"/>-->
    <arg name="extensions" value="php"/>
    <arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->

    <!-- Rules: Check PHP version compatibility -->
    <!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
    <config name="testVersion" value="7.4-"/>
    <!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
    <rule ref="PHPCompatibilityWP"/>

    <!-- Rules: WordPress Coding Standards -->
    <!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
    <!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
    <config name="minimum_supported_wp_version" value="5.1.0"/>

    <rule ref="WordPress"/>

    <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
        <properties>
            <!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
            <property name="prefixes" type="array" value="shpg"/>
        </properties>
        <exclude-pattern>/includes/templates/</exclude-pattern>
    </rule>

    <rule ref="WordPress.WP.I18n">
        <properties>
            <!-- Value: replace the text domain used. -->
            <property name="text_domain" type="array" value="shoplic-pg"/>
        </properties>
    </rule>

    <rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
        <properties>
            <property name="blank_line_check" value="true"/>
        </properties>
    </rule>

    <rule ref="WordPress.Files.FileName">
        <exclude-pattern>abstract-*\.php</exclude-pattern>
    </rule>

    <rule ref="Squiz.Commenting.FunctionComment">
        <properties>
            <property name="minimumVisibility" value="public"/>
            <property name="skipIfInheritdoc" value="true"/>
        </properties>
    </rule>

    <!-- We allow short syntax. -->
    <rule ref="Generic.Arrays.DisallowShortArraySyntax">
        <severity>0</severity>
    </rule>

    <!-- Allow closure definition in one line. -->
    <rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
        <properties>
            <property name="checkClosures" value="false"/>
            <property name="checkFunctions" value="true"/>
        </properties>
    </rule>

    <!-- Allow space indent. Too many conflicts with PhpStorm. -->
    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed">
        <severity>0</severity>
    </rule>
    <!-- Too many conflicts with PhpStorm. -->
    <rule ref="WordPress.WhiteSpace.PrecisionAlignment.Found">
        <severity>0</severity>
    </rule>

    <!-- Allow empty class comment. -->
    <rule ref="Squiz.Commenting.ClassComment">
        <severity>0</severity>
    </rule>

    <!-- Allow missing package tag. -->
    <rule ref="Squiz.Commenting.FileComment.MissingPackageTag">
        <severity>0</severity>
    </rule>

    <!-- Registers and uninstall.php have sample code comments. -->
    <rule ref="Squiz.PHP.CommentedOutCode">
        <exclude-pattern>/includes/registers/</exclude-pattern>
    </rule>
    <rule ref="Squiz.Commenting.InlineComment.InvalidEndChar">
        <exclude-pattern>/includes/registers/</exclude-pattern>
        <exclude-pattern>/uninstall.php</exclude-pattern>
    </rule>

    <!-- Too many registers comments, and too trivial. -->
    <rule ref="Squiz.Commenting.FunctionComment">
        <exclude-pattern>/core/abstracts/registers/</exclude-pattern>
        <exclude-pattern>/includes/registers/</exclude-pattern>
    </rule>
    <rule ref="Squiz.Commenting.FunctionComment">
        <exclude-pattern>/core/abstracts/registers/</exclude-pattern>
        <exclude-pattern>/core/regs/</exclude-pattern>
    </rule>
    <rule ref="Squiz.Commenting.VariableComment">
        <exclude-pattern>/core/abstracts/registers/</exclude-pattern>
        <exclude-pattern>/core/regs/</exclude-pattern>
    </rule>
    <rule ref="Generic.Commenting.DocComment">
        <exclude-pattern>/core/abstracts/registers/</exclude-pattern>
        <exclude-pattern>/core/regs/</exclude-pattern>
    </rule>

    <!-- Allow using error_log, or something. -->
    <rule ref="WordPress.PHP.DevelopmentFunctions">
        <severity>0</severity>
    </rule>

    <!-- Allow assignment in control structures such as if (). -->
    <rule ref="Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure">
        <severity>0</severity>
    </rule>
    <rule ref="WordPress.CodeAnalysis.AssignmentInCondition">
        <severity>0</severity>
    </rule>

    <!-- Allow semicolons on new line. -->
    <rule ref="Squiz.WhiteSpace.SemicolonSpacing.Incorrect">
        <severity>0</severity>
    </rule>
    <rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket">
        <severity>0</severity>
    </rule>

    <!-- Allow short ternary -->
    <rule ref="WordPress.PHP.DisallowShortTernary">
        <severity>0</severity>
    </rule>

</ruleset>
