<?xml version="1.0" encoding="UTF-8"?>

<!-- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset -->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="../../../vendor/squizlabs/php_codesniffer/phpcs.xsd"
         name="AcquiaPHP"
>

  <description>Acquia's PHP coding standards.</description>

  <!-- Drupal sniffs -->
  <!-- These provide PHPCBF integration, unlike their Squiz equivalents -->
  <rule ref="Drupal.Classes.ClassDeclaration" />
  <rule ref="Drupal.Classes.UnusedUseStatement"/>
  <!-- https://www.php-fig.org/psr/psr-12/#5-control-structures -->
  <rule ref="Drupal.ControlStructures.ControlSignature" />
  <rule ref="Drupal.Functions.FunctionDeclaration" />
  <rule ref="Drupal.Scope.MethodScope"/>
  <rule ref="Drupal.WhiteSpace.ScopeIndent"/>

  <!-- Generic sniffs -->
  <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
  <rule ref="Generic.Files.ByteOrderMark"/>
  <rule ref="Generic.Files.EndFileNewline" />
  <rule ref="Generic.Files.LineEndings"/>
  <rule ref="Generic.Formatting.SpaceAfterCast"/>
  <rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
  <rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
    <properties>
      <property name="checkClosures" value="true"/>
    </properties>
  </rule>
  <rule ref="Generic.NamingConventions.ConstructorName"/>
  <rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
  <rule ref="Generic.PHP.DeprecatedFunctions"/>
  <rule ref="Generic.PHP.DisallowShortOpenTag"/>
  <rule ref="Generic.PHP.LowerCaseKeyword"/>
  <rule ref="Generic.PHP.UpperCaseConstant"/>
  <rule ref="Generic.WhiteSpace.DisallowTabIndent"/>

  <!-- Internal sniffs -->
  <rule ref="Internal.NoCodeFound">
    <!-- No PHP code in *.md, *.txt, or *.yml -->
    <exclude-pattern>*.(md|txt|yml)</exclude-pattern>
  </rule>

  <!-- MySource sniffs -->
  <rule ref="MySource.Debug.DebugCode"/>

  <!-- PEAR sniffs -->
  <rule ref="PEAR.Files.IncludingFile"/>
  <!-- Disable some error messages that we do not want. -->
  <rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Files.IncludingFile.UseInclude">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Files.IncludingFile.UseRequire">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.FunctionCallSignature.OpeningIndent">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.ValidDefaultValue"/>
  <rule ref="PEAR.Functions.FunctionCallSignature"/>
  <!-- The sniffs inside PEAR.Functions.FunctionCallSignature silenced below are
    also silenced in Drupal CS' ruleset.xml. The code below is a 1-to-1 copy
    from that file. -->
  <!-- Disable some error messages that we already cover. -->
  <rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
    <severity>0</severity>
  </rule>
  <!-- Disable some error messages that we do not want. -->
  <rule ref="PEAR.Functions.FunctionCallSignature.Indent">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
    <severity>0</severity>
  </rule>
  <rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
    <severity>0</severity>
  </rule>

  <!-- PHP Compatibility sniffs -->
  <!-- The lowest version of PHP supported by both Drupal and Acquia Cloud.
    @see https://www.drupal.org/docs/8/system-requirements/php-requirements
    @see https://docs.acquia.com/acquia-cloud/arch/tech-platform/
    For instructions on overriding this value in your project,
    @see https://github.com/acquia/coding-standards-php/pull/37 -->
  <config name="testVersion" value="7.4-"/>
  <rule ref="PHPCompatibility">
    <exclude name="PHPCompatibility.Extensions.RemovedExtensions.famRemoved"/>
  </rule>

  <!-- PSR-2 sniffs -->
  <rule ref="PSR2.Classes.PropertyDeclaration">
    <exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
  </rule>
  <rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
  <rule ref="PSR2.Namespaces.UseDeclaration">
    <exclude name="PSR2.Namespaces.UseDeclaration.UseAfterNamespace"/>
  </rule>

  <!-- PSR-12 sniffs -->
  <rule ref="PSR12.Functions.ReturnTypeDeclaration" />

  <!-- SlevomatCodingStandard sniffs -->
  <rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
  <rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint" />
  <rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint" />
  <rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint" />
  <!-- Superglobals are superbad. See linked issue for discussion.
  @see https://github.com/acquia/coding-standards-php/issues/49 -->
  <rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable" />

  <!-- Squiz sniffs -->
  <rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
  <rule ref="Squiz.Arrays.ArrayDeclaration">
    <exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
    <exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
  </rule>
  <!-- Disable some error messages that we do not want. -->
  <rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.FirstValueNoNewline">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.NoComma">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.NotLowerCase">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
  <!-- Disable some error messages that we already cover. -->
  <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
  <!-- Disable some error messages that we already cover. -->
  <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
    <severity>0</severity>
  </rule>
  <!-- Standard yet to be finalized on this
    (https://www.drupal.org/node/1539712). -->
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
    <properties>
      <property name="equalsSpacing" value="1"/>
    </properties>
  </rule>
  <rule
    ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
    <severity>0</severity>
  </rule>
  <rule ref="Squiz.PHP.LowercasePHPFunctions"/>
  <rule ref="Squiz.Strings.ConcatenationSpacing">
    <properties>
      <property name="spacing" value="1"/>
      <property name="ignoreNewlines" value="true"/>
    </properties>
  </rule>
  <rule ref="Squiz.WhiteSpace.FunctionSpacing">
    <properties>
      <property name="spacing" value="1"/>
    </properties>
  </rule>
  <rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
  <rule ref="Squiz.WhiteSpace.OperatorSpacing" />
  <rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
  <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>

  <!-- Zend sniffs -->
  <rule ref="Zend.Files.ClosingTag"/>

</ruleset>
