<?xml version="1.0"?>
<ruleset
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
    <arg name="basepath" value="."/>
    <arg name="extensions" value="php"/>
    <arg name="parallel" value="80"/>
    <arg name="cache" value=".phpcs-cache"/>
    <arg name="colors"/>

    <!-- Show progress of the run and show sniff names -->
    <arg value="ps"/>

    <config name="php_version" value="80100"/>

    <file>src</file>
    <file>tests</file>

    <rule ref="Doctrine">
        <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
        <exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
        <exclude name="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants.DisallowedLateStaticBindingForConstant"/>
        <exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterLastControlStructure"/>
        <!-- https://github.com/doctrine/coding-standard/issues/288 -->
        <exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable"/>

        <exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
        <!-- https://github.com/slevomat/coding-standard/issues/867 -->
        <exclude name="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing.IncorrectLinesCountAfterLastControlStructure"/>
        <!-- See https://github.com/squizlabs/PHP_CodeSniffer/issues/2937 -->
        <exclude name="Squiz.Arrays.ArrayDeclaration.ValueNoNewline"/>
        <exclude name="Squiz.NamingConventions.ValidVariableName.PublicHasUnderscore"/>
    </rule>

    <rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
        <exclude-pattern>*/src/Configuration.php</exclude-pattern>
        <exclude-pattern>*/src/Connection.php</exclude-pattern>
        <exclude-pattern>*/src/Driver</exclude-pattern>
        <exclude-pattern>*/src/Event/Listeners</exclude-pattern>
        <exclude-pattern>*/src/Platforms</exclude-pattern>
        <exclude-pattern>*/src/Schema</exclude-pattern>
        <exclude-pattern>*/src/Tools/Console/Helper/ConnectionHelper.php</exclude-pattern>
    </rule>

    <rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly">
        <!-- ext-sqlite3 throws generic exceptions. -->
        <!-- Catching \Exception is legit here, and we don't want to widen types to \Throwable. -->
        <exclude-pattern>src/Driver/SQLite3/*</exclude-pattern>

        <!-- Catching \Exception is legit for `\DateTime::__construct()`. -->
        <exclude-pattern>src/Types/DateTimeType.php</exclude-pattern>
        <exclude-pattern>src/Types/VarDateTimeType.php</exclude-pattern>

        <!-- Catching \Exception is legit for `\DateTimeImmutable::__construct()`. -->
        <exclude-pattern>src/Types/DateTimeImmutableType.php</exclude-pattern>
        <exclude-pattern>src/Types/VarDateTimeImmutableType.php</exclude-pattern>
    </rule>

    <rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>

    <rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion">
        <exclude-pattern>tests/*</exclude-pattern>
    </rule>

    <rule ref="Squiz.Classes.ClassFileName.NoMatch">
        <exclude-pattern>*/tests/*</exclude-pattern>
    </rule>

    <rule ref="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase">
        <exclude-pattern>src/Events.php</exclude-pattern>
    </rule>

    <!-- see https://github.com/squizlabs/PHP_CodeSniffer/issues/2099 -->
    <rule ref="Squiz.Commenting.FunctionComment.InvalidNoReturn">
        <exclude-pattern>src/Platforms/AbstractPlatform.php</exclude-pattern>
        <exclude-pattern>src/Schema/AbstractSchemaManager.php</exclude-pattern>
        <exclude-pattern>tests/Platforms/AbstractPlatformTestCase.php</exclude-pattern>
    </rule>

    <!-- see https://github.com/squizlabs/PHP_CodeSniffer/issues/2838 -->
    <rule ref="Squiz.Commenting.FunctionComment.SpacingAfter">
        <exclude-pattern>src/Driver/AbstractMySQLDriver.php</exclude-pattern>
    </rule>

    <rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
        <exclude-pattern>tests/Functional/DataAccess/FetchClass.php</exclude-pattern>
    </rule>

    <rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
        <!--
            These files use the underlying driver APIs that don't comply with the coding standard
            phpcs wrongly complains about them, and that has been reported here:
            https://github.com/squizlabs/PHP_CodeSniffer/issues/2950
        -->
        <exclude-pattern>src/Driver/IBMDB2/Connection.php</exclude-pattern>
        <exclude-pattern>src/Driver/Mysqli/Exception/ConnectionFailed.php</exclude-pattern>
        <exclude-pattern>tests/Functional/Driver/Mysqli/ResultTest.php</exclude-pattern>
    </rule>

    <!-- See https://github.com/squizlabs/PHP_CodeSniffer/issues/2837 -->
    <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps">
        <exclude-pattern>src/Connection.php</exclude-pattern>
        <exclude-pattern>src/Schema/Comparator.php</exclude-pattern>
        <exclude-pattern>src/SQLParserUtils.php</exclude-pattern>
    </rule>

    <!-- some statement classes close cursor using an empty while-loop -->
    <rule ref="Generic.CodeAnalysis.EmptyStatement.DetectedWhile">
        <exclude-pattern>src/Driver/SQLSrv/Result.php</exclude-pattern>
        <exclude-pattern>tests/Functional/ResultCacheTest.php</exclude-pattern>
    </rule>

    <!-- See https://github.com/slevomat/coding-standard/issues/770 -->
    <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
        <exclude-pattern>src/Driver/ExceptionConverterDriver.php</exclude-pattern>
        <exclude-pattern>src/Query/QueryBuilder.php</exclude-pattern>
    </rule>

    <!-- see https://github.com/doctrine/dbal/issues/3377 -->
    <rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator">
        <exclude-pattern>src/Schema/ColumnDiff.php</exclude-pattern>
    </rule>

    <!-- The SQLSRV_* functions are defined in the upper case by the sqlsrv extension and violate the standard
         see https://docs.microsoft.com/en-us/sql/connect/php/constants-microsoft-drivers-for-php-for-sql-server -->
    <rule ref="Squiz.PHP.LowercasePHPFunctions">
        <exclude-pattern>src/Driver/SQLSrv/Statement.php</exclude-pattern>
    </rule>

    <!-- This could be considered a bug in the sniff or the shortcoming of the Platform API design
         see https://github.com/squizlabs/PHP_CodeSniffer/issues/3035 -->
    <rule ref="Generic.CodeAnalysis.UselessOverridingMethod.Found">
        <exclude-pattern>src/Platforms/SQLitePlatform.php</exclude-pattern>
        <exclude-pattern>src/Platforms/*/Comparator.php</exclude-pattern>
        <exclude-pattern>src/Driver/PDO/SQLSrv/Connection.php</exclude-pattern>
        <exclude-pattern>src/Driver/PDO/SQLSrv/Statement.php</exclude-pattern>
    </rule>

    <!-- This issue is likely fixed in Slevomat Coding Standard 8.0.0 -->
    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName">
        <exclude-pattern>src/ParameterType.php</exclude-pattern>
    </rule>
</ruleset>
