<?xml version="1.0"?>
<!--
	- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
	- https://github.com/squizlabs/PHP_CodeSniffer/tree/master/src/Standards
-->
<ruleset name="MediaWiki">

    <file>src/</file>
    <file>tests/</file>

    <rule ref="Generic.Arrays.DisallowLongArraySyntax" />
    <rule ref="Generic.Classes" />
    <rule ref="Generic.CodeAnalysis">
        <exclude name="Generic.CodeAnalysis.EmptyStatement" />
        <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
    </rule>
    <rule ref="Generic.ControlStructures" />

    <rule ref="Generic.Files.ByteOrderMark" />
    <rule ref="Generic.Files.LineEndings" />
    <rule ref="Generic.Files.LineLength">
        <properties>
            <!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/1094 -->
            <property name="lineLimit" value="170" />
            <property name="absoluteLineLimit" value="170" />
        </properties>
    </rule>

    <rule ref="Generic.Formatting.DisallowMultipleStatements" />

    <rule ref="Generic.Functions.CallTimePassByReference" />
    <rule ref="Generic.Functions.FunctionCallArgumentSpacing" />

    <rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />

    <rule ref="Generic.Metrics.NestingLevel">
        <properties>
            <property name="nestingLevel" value="3" />
            <property name="absoluteNestingLevel" value="3" />
        </properties>
    </rule>

    <rule ref="Generic.Metrics.CyclomaticComplexity">
        <properties>
            <property name="complexity" value="10" />
            <property name="absoluteComplexity" value="10" />
        </properties>
    </rule>

    <rule ref="Generic.NamingConventions" />
    <!-- TODO: create variation of this sniff that allows underscores in test methods -->
    <rule ref="Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps">
        <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
        <exclude-pattern>*Test\.php</exclude-pattern>
    </rule>

    <rule ref="Generic.NamingConventions.InterfaceNameSuffix.Missing">
        <severity>0</severity>
    </rule>

    <rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />
    <rule ref="Generic.PHP.DeprecatedFunctions" />
    <rule ref="Generic.PHP.DisallowShortOpenTag" />
    <rule ref="Generic.PHP.ForbiddenFunctions" />
    <rule ref="Generic.PHP.LowerCaseConstant" />
    <rule ref="Generic.PHP.LowerCaseKeyword" />
    <rule ref="Generic.PHP.SAPIUsage" />

    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />

    <rule ref="PSR1" />
    <!-- TODO: create variation of this sniff that allows underscores in test methods -->
    <rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
        <!-- Exclude test methods like "testGivenInvalidInput_methodThrowsException". -->
        <exclude-pattern>*Test\.php</exclude-pattern>
    </rule>

    <rule ref="PSR2.Classes.PropertyDeclaration" />
    <rule ref="PSR2.ControlStructures.ElseIfDeclaration" />
    <rule ref="PSR2.Namespaces" />

    <rule ref="Squiz.Arrays.ArrayBracketSpacing" />
    <rule ref="Squiz.CSS.SemicolonSpacing" />
    <rule ref="Squiz.Classes.DuplicateProperty" />
    <rule ref="Squiz.Classes.SelfMemberReference" />
    <rule ref="Squiz.Classes.ValidClassName" />
    <rule ref="Squiz.Functions.FunctionDuplicateArgument" />
    <rule ref="Squiz.Functions.GlobalFunction" />
    <rule ref="Squiz.Scope" />

    <rule ref="Squiz.Strings.DoubleQuoteUsage" />
    <rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
        <severity>0</severity>
    </rule>

    <rule ref="Squiz.WhiteSpace.CastSpacing" />
    <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
    <rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing" />

    <rule ref="Squiz.WhiteSpace.OperatorSpacing">
        <properties>
            <property name="ignoreNewlines" value="true" />
        </properties>
        <exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore" />
        <exclude name="Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter" />
    </rule>

    <rule ref="Squiz.WhiteSpace.ScopeClosingBrace" />
    <rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing" />
    <rule ref="Squiz.WhiteSpace.SemicolonSpacing" />
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
    <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
        <severity>0</severity>
    </rule>

    <rule ref="Zend.Files.ClosingTag" />

    <!-- MediaWiki.WhiteSpace.SpaceyParenthesis replica for up-to-date codesniffer version -->
    <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
        <properties>
            <property name="equalsSpacing" value="1" />
            <property name="requiredSpacesAfterOpen" value="1" />
            <property name="requiredSpacesBeforeClose" value="1" />
        </properties>
    </rule>

    <rule ref="PEAR.Functions.FunctionCallSignature">
        <properties>
            <property name="requiredSpacesAfterOpen" value="1" />
            <property name="requiredSpacesBeforeClose" value="1" />
        </properties>
        <exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
        <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
        <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
        <exclude name="PEAR.Functions.FunctionCallSignature.OpeningIndent" />
    </rule>
</ruleset>
