<?xml version="1.0"?>
<ruleset
	name="WPCS - MCP Adapter"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd"
>
	<description>Sniffs for the MCP Adapter plugin</description>

	<!-- What to scan: include any root-level PHP files, and the /includes folder -->
	<file>./includes/</file>
	<file>./mcp-adapter.php</file>

	<!-- These are excluded from the above paths.-->
	<exclude-pattern>**/build/**</exclude-pattern>
	<exclude-pattern>**/node_modules/**</exclude-pattern>
	<exclude-pattern>**/vendor/**</exclude-pattern>

	<!-- How to scan: include CLI args so you don't need to pass them manually -->
	<!-- Usage instructions: https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Usage -->
	<!-- Annotated ruleset:
	https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
	<!-- Show sniff and progress -->
	<arg value="sp" />
	<!-- Strip the file paths down to the relevant bit -->
	<arg name="basepath" value="./" />
	<!-- Enable colors in report -->
	<arg name="colors" />
	<!-- Only lint php files by default -->
	<arg name="extensions" value="php" />
	<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next
	scan. -->
	<arg name="cache" value="tests/_output/phpcs-cache.json" />
	<!-- Enables parallel processing when available for faster results. -->
	<arg name="parallel" value="20" />
	<!-- Set severity to 1 to see everything that isn't effectively turned off. -->
	<arg name="severity" value="1" />

	<!-- Ruleset Config: set these to match your project constraints. -->

	<!--
		Tests for PHP version compatibility.
	https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#Recomended-additional-rulesets
	-->
	<config name="testVersion" value="7.4-" />

	<!--
		Tests for WordPress version compatibility.
	https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
	-->
	<config name="minimum_wp_version" value="6.8" />

	<!--
		Load WordPress VIP Go standards
		We do this first, since we don't trust them to disable rules that we want to use.
		@see: https://docs.wpvip.com/technical-references/vip-code-analysis-bot/phpcs-report/
	-->
	<rule ref="WordPress-VIP-Go">
		<!-- Deprecated: @todo remove in PHPCS 4.0 -->
		<exclude name="WordPressVIPMinimum.JS" />
	</rule>
	<rule ref="WordPress-Extra">
		<!-- @todo: TO EVALUATE. -->
		<!-- Allow PSR-4 class/file naming instead of WordPress class/file naming scheme -->
		<!-- @TODO to evaluate -->
		<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound" />
		<exclude name="WordPress.NamingConventions.PrefixAllGlobals.InvalidPrefixPassed" />
		<exclude name="WordPress.Files.FileName" />
		<!-- Allow modern PHP syntax -->
		<exclude name="Universal.Operators.DisallowShortTernary" />
		<!-- Needed to typehint, see: https://github.com/WordPress/WordPress-Coding-Standards/issues/403 -->
		<exclude name="Generic.Commenting.DocComment.MissingShort" />
		<!-- Allow internal hook names without prefixes -->
		<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound" />
		<!-- Allow unused parameters in interface implementations -->
		<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
	</rule>

	<!--
		Load PHPCompatibility & PHPCompatibilityWP
		@see: https://github.com/PHPCompatibility/PHPCompatibilityWP
	-->
	<rule ref="PHPCompatibilityWP" />

	<!--
		Checks from PCP
		@see https://github.com/wordpress/plugin-check
	-->
	<rule
		ref="./vendor/wpackagist-plugin/plugin-check/vendor/plugin-check/phpcs-sniffs/PluginCheck/ruleset.xml" />
	<rule ref="./vendor/wpackagist-plugin/plugin-check/phpcs-rulesets/plugin-check.ruleset.xml" />

	<!-- Check for superfluous whitespace - These get suppressed in VIP-GO.-->
	<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
		<severity>5</severity>
	</rule>
	<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
		<severity>5</severity>
	</rule>
	<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine">
		<severity>5</severity>
	</rule>
	<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
		<properties>
			<property name="blank_line_check" value="true" />
		</properties>
	</rule>

	<!--
		Slevomat Coding Standards to keep our code clean and modern.
		See: https://github.com/slevomat/coding-standard/tree/master#alphabetical-list-of-sniffs
	-->
	<rule ref="SlevomatCodingStandard.Arrays.ArrayAccess" />
	<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation" />
	<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement" />

	<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
	<rule ref="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion" />
	<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants" />
	<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition" />
	<rule ref="SlevomatCodingStandard.Classes.DisallowMultiPropertyDefinition" />
	<rule ref="SlevomatCodingStandard.Classes.DisallowStringExpressionPropertyFetch" />
	<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference">
		<properties>
			<!-- Doesn't use PHPCompatibility-->
			<property name="enableOnObjects" value="false" />
		</properties>
	</rule>
	<rule ref="SlevomatCodingStandard.Classes.RequireSelfReference" />
	<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding" />

	<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch" />
	<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit" />
	<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses" />
	<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn" />
	<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator" />

	<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch" />
	<rule ref="SlevomatCodingStandard.Exceptions.DisallowNonCapturingCatch" />
	<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />

	<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
	<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
	<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue" />

	<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
		<properties>
			<property name="caseSensitive" value="true" />
		</properties>
	</rule>
	<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse" />
	<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation">
		<properties>
			<!-- Support PHPStan annotations -->
			<property name="ignoredAnnotationNames" type="array">
				<element value="@phpstan-import-type" />
				<element value="@phpstan-param" />
				<element value="@phpstan-return" />
				<element value="@phpstan-template" />
				<element value="@phpstan-type" />
				<element value="@phpstan-var" />
			</property>
		</properties>
	</rule>
	<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions" />
	<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses" />
	<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
	<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace" />

	<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall" />
	<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking" />
	<rule ref="SlevomatCodingStandard.PHP.ShortList" />
	<rule ref="SlevomatCodingStandard.PHP.TypeCast" />
	<rule ref="SlevomatCodingStandard.PHP.UselessParentheses" />
	<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon" />

	<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints" />
	<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
	<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition" />

	<rule ref="SlevomatCodingStandard.Variables.DisallowVariableVariable" />
	<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable" />
	<rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
		<properties>
			<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true" />
		</properties>
	</rule>
	<rule ref="SlevomatCodingStandard.Variables.UselessVariable" />

	<!--
		Ignore Rules for Tests
	-->
	<rule ref="PluginCheck.CodeAnalysis.Offloading.OffloadedContent">
		<exclude-pattern>/tests/*</exclude-pattern>
	</rule>

	<!-- Do not apply filename rules for unit tests -->
	<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
		<exclude-pattern>tests/*</exclude-pattern>
	</rule>
	<rule ref="WordPress.Files.FileName.InvalidClassFileName">
		<exclude-pattern>tests/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
		<properties>
			<property name="prefixes" type="array">
				<element value="mcp-adapter" />
				<element value="WPMCP" />
			</property>
		</properties>
	</rule>

	<!-- Plugin-specific rule configs-->
	<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
		<properties>
			<property name="prefixes" type="array">
				<!-- @todo: Should we use a namespace or prefix ? -->
				<element value="mcp-adapter" />
				<element value="WP_MCP" />
			</property>
		</properties>
	</rule>
</ruleset>
