<?xml version="1.0"?>
<ruleset name="Newfold">
    <description>The Newfold PHP Code Sniffer standard.</description>

    <arg name="colors"/>

    <!-- Sets the supported PHP version range. -->
    <config name="testVersion" value="7.3-"/>

    <!-- Sets the minimum supported WP version to 5.8, which requires PHP 5.6+ -->
    <config name="minimum_supported_wp_version" value="5.8"/>

    <!-- For CI, don't fail on warnings -->
    <config name="ignore_warnings_on_exit" value="1"/>

    <exclude-pattern>*/phpunit.xml*</exclude-pattern>
    <exclude-pattern>*/languages/*</exclude-pattern>

    <exclude-pattern>*/tests/_data/*</exclude-pattern>
    <exclude-pattern>*/tests/_output/*</exclude-pattern>
    <exclude-pattern>*/tests/_support/*</exclude-pattern>

    <!-- Third-party code -->
    <exclude-pattern>*/bower-components/*</exclude-pattern>
    <exclude-pattern>*/node_modules/*</exclude-pattern>
    <exclude-pattern>*/vendor/*</exclude-pattern>

    <!-- Ensure certain file types aren't sniffed -->
    <exclude-pattern>*.js</exclude-pattern>
    <exclude-pattern>*.css</exclude-pattern>

    <!-- Don't worry about files that don't contain any code -->
    <rule ref="Internal.NoCodeFound">
        <severity>0</severity>
    </rule>

    <!-- Ignore mixed line-endings warnings -->
    <rule ref="Internal.LineEndings.Mixed">
        <severity>0</severity>
    </rule>

    <!-- Internal exceptions (often occur on minified files) -->
    <rule ref="Internal.Tokenizer.Exception">
        <severity>0</severity>
    </rule>

    <rule ref="WordPress-Docs">
        <!-- Don't worry about page comment blocks -->
        <exclude name="Squiz.Commenting.FileComment.Missing"/>

        <!-- Don't worry about capitalizing long lines -->
        <exclude name="Generic.Commenting.DocComment.LongNotCapital"/>
    </rule>

    <rule ref="WordPress-Extra">
        <!-- Forget about file names -->
        <exclude name="WordPress.Files.FileName"/>

        <!-- Allow same line control structures e.g. if ( true ) { echo 1; } -->
        <exclude name="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace"/>

        <!-- Don't require punctuation after inline comments -->
        <exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>

        <!-- Allow empty catch statements -->
        <exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>

        <!-- Comment punctuation doesn't matter -->
        <exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
    </rule>

    <!-- Make missing translator comment a warning. -->
    <rule ref="WordPress.WP.I18n.MissingTranslatorsComment">
        <type>warning</type>
    </rule>

    <!-- Sometimes we need to override globals -->
    <rule ref="WordPress.WP.GlobalVariablesOverride.OverrideProhibited">
        <type>warning</type>
    </rule>

    <!-- Loads the PHP Compatibility ruleset. -->
    <rule ref="PHPCompatibilityWP"/>

    <!-- Throws Warnings for TODO comments in PHP and JS -->
    <rule ref="Generic.Commenting.Todo"/>
    <rule ref="Generic.Commenting.Todo.CommentFound">
        <message>Please review this TODO comment: %s</message>
        <severity>3</severity>
    </rule>

    <!-- Custom Newfold sniff to detect invalid "::class::" usage in PHP versions below 8 -->
    <rule ref="Newfold.PHP.ForbiddenDoubleColonClass"/>

</ruleset>
