<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="KiviCare API" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">

	<description>Custom WordPress Coding Standards for KiviCare API plugin.</description>

	<!-- What to scan -->
	<file>src</file>
	<file>tests</file>
	<exclude-pattern>/vendor/</exclude-pattern>
	<exclude-pattern>/node_modules/</exclude-pattern>
	<exclude-pattern>*.min.js</exclude-pattern>
	<exclude-pattern>*.min.css</exclude-pattern>

	<!-- How to scan -->
	<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
	<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
	<arg value="sp"/> <!-- Show sniff and progress -->
	<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
	<arg name="colors"/>
	<arg name="extensions" value="php"/>
	<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->

	<!-- Rules: Check PHP version compatibility -->
	<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
	<config name="testVersion" value="8.1-"/>
	<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
	<rule ref="PHPCompatibilityWP"/>

	<!-- Rules: WordPress Coding Standards -->
	<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
	<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
	<config name="minimum_supported_wp_version" value="6.0"/>

	<rule ref="WordPress">
		<!-- This rule does not apply here since we are adhering to the PSR-4 standard -->
		<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
		<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
		
		<!-- Allow short array syntax -->
		<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
		
		<!-- Allow modern PHP syntax -->
		<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found"/>
	</rule>

	<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
		<properties>
			<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
			<property name="prefixes" type="array" value="kivicare_api,KiviCare_API,KIVICARE_API"/>
		</properties>
	</rule>

	<rule ref="WordPress.WP.I18n">
		<properties>
			<!-- Value: replace the text domain used. -->
			<property name="text_domain" type="array" value="kivicare-api"/>
		</properties>
	</rule>

	<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
		<properties>
			<property name="blank_line_check" value="true"/>
		</properties>
	</rule>

	<!-- Rules: Allow WordPress VIP Go coding standards for better performance -->
	<!-- https://github.com/Automattic/VIP-Coding-Standards/ -->
	<rule ref="WordPress-VIP-Go">
		<!-- Allow direct database queries - we need them for KiviCare integration -->
		<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery"/>
		<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
		
		<!-- Allow file system writes for logging -->
		<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fopen"/>
		<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fwrite"/>
	</rule>

	<!-- Custom rules for KiviCare API -->
	<rule ref="Generic.Commenting.DocComment"/>
	<rule ref="Squiz.Commenting.ClassComment"/>
	<rule ref="Squiz.Commenting.FunctionComment"/>
	<rule ref="Generic.Commenting.DocComment.MissingShort"/>

	<!-- Security Rules -->
	<rule ref="WordPress.Security.EscapeOutput"/>
	<rule ref="WordPress.Security.NonceVerification"/>
	<rule ref="WordPress.Security.ValidatedSanitizedInput"/>

	<!-- Database Rules -->
	<rule ref="WordPress.DB.PreparedSQL"/>
	<rule ref="WordPress.DB.SlowDBQuery"/>

</ruleset>