<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	name="bbPress"
	xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">

	<description>Apply WordPress Coding Standards to all Core files with specific bbPress exclusions</description>

	<!--
	#############################################################################
	COMMAND LINE ARGUMENTS
	https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
	#############################################################################
	-->

	<file>.</file>

	<!-- Test data and fixtures -->
	<exclude-pattern>/tests/*</exclude-pattern>
	<exclude-pattern>/tests/phpunit/build*</exclude-pattern>
	<exclude-pattern>/tests/phpunit/data/*</exclude-pattern>

	<!-- Directories and third party library exclusions -->
	<exclude-pattern>/node_modules/*</exclude-pattern>
	<exclude-pattern>/vendor/*</exclude-pattern>

	<!-- Exclude the build folder in the current directory, as Travis puts the checkout in a build directory. -->
	<exclude-pattern type="relative">^build/*</exclude-pattern>

	<!-- Exclude the NBBC parser. See https://github.com/bbpress/nbbc -->
	<exclude-pattern>/src/includes/admin/parser\.php$</exclude-pattern>

	<arg name="extensions" value="php"/>

	<!-- Strip the filepaths down to the relevant bit. -->
	<arg name="basepath" value="./"/>

	<!-- Check up to 20 files simultaneously. -->
	<arg name="parallel" value="20"/>

	<!-- Show progress, show the error codes for each message (source). -->
	<arg value="ps"/>

	<!-- Surface warnings in reports, but only fail the build on errors. -->
	<config name="ignore_warnings_on_exit" value="1"/>


	<!--
	#############################################################################
	SET UP THE RULES TO USE
	#############################################################################
	-->

	<!-- bbPress follows only a subset of the WordPress Coding Standards Rules -->
	<rule ref="WordPress-Extra">
		<!-- Set the minimum supported WP version for all sniff which use it in one go.
			 Ref: https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters
		-->
		<properties>
			<property name="minimum_supported_version" value="6.0"/>
		</properties>

		<!-- Set the custom test class whitelist for all sniffs which use it in one go.
			 Ref: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-unit-test-classes
		-->
		<property name="custom_test_class_whitelist" type="array">
			<element value="BBP_UnitTestCase"/>
		</property>

	</rule>

	<!-- Check the code for PHP cross-version compatibility. -->
	<config name="testVersion" value="7.2-"/>
	<rule ref="PHPCompatibilityWP"/>


	<!--
	#############################################################################
	SNIFF SPECIFIC CONFIGURATION
	#############################################################################
	-->

	<!-- Verify that all gettext calls use the correct text domain. -->
	<rule ref="WordPress.WP.I18n">
		<properties>
			<property name="text_domain" type="array">
				<element value="bbpress"/>
			</property>
		</properties>
	</rule>

	<!-- Verify that everything in the global namespace is prefixed. -->
	<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
		<properties>
			<property name="prefixes" type="array" extend="true">
				<element value="bbp"/>
			</property>
		</properties>
	</rule>

	<rule ref="WordPress.Arrays.MultipleStatementAlignment">
		<properties>
			<!-- No need to adjust alignment of large arrays when the item with the largest key is removed. -->
			<property name="exact" value="false"/>
			<!-- Don't align multi-line items if ALL items in the array are multi-line. -->
			<property name="alignMultilineItems" value="!=100"/>
			<!-- Array Assignment operator should always be on the same line as the array key. -->
			<property name="ignoreNewlines" value="false"/>
		</properties>
	</rule>

	<rule ref="WordPress.Files.FileName">
		<exclude-pattern>*/includes/admin/converters/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.WP.Capabilities">
		<properties>
			<property name="custom_capabilities" type="array">

				<!-- Primary bbPress Admin caps -->
				<element value="assign_moderators" />
				<element value="bbp_forums_admin" />
				<element value="bbp_topics_admin" />
				<element value="bbp_replies_admin" />
				<element value="bbp_topic_tags_admin" />
				<element value="bbp_about_page" />
				<element value="bbp_settings_page" />
				<element value="bbp_tools_page" />
				<element value="bbp_tools_repair_page" />
				<element value="bbp_tools_import_page" />
				<element value="bbp_tools_import_users" />
				<element value="bbp_tools_upgrade_page" />

				<!-- Primary bbPress Role caps -->
				<element value="spectate" />
				<element value="participate" />
				<element value="moderate" />
				<element value="keep_gate" />
				<element value="throttle" />
				<element value="view_trash" />

				<!-- Forum caps -->
				<element value="manage_forum_attributes" />
				<element value="publish_forums" />
				<element value="edit_forum" />
				<element value="edit_forums" />
				<element value="edit_others_forums" />
				<element value="delete_forum" />
				<element value="delete_forums" />
				<element value="delete_others_forums" />
				<element value="read_forum" />
				<element value="read_private_forums" />
				<element value="read_hidden_forums" />

				<!-- Topic caps -->
				<element value="publish_topics" />
				<element value="edit_topic" />
				<element value="edit_topics" />
				<element value="edit_others_topics" />
				<element value="delete_topic" />
				<element value="delete_topics" />
				<element value="delete_others_topics" />
				<element value="read_topic" />
				<element value="read_private_topics" />
				<element value="read_hidden_topics" />

				<!-- Reply caps -->
				<element value="publish_replies" />
				<element value="edit_reply" />
				<element value="edit_replies" />
				<element value="edit_others_replies" />
				<element value="delete_reply" />
				<element value="delete_replies" />
				<element value="delete_others_replies" />
				<element value="read_reply" />
				<element value="read_private_replies" />

				<!-- Topic tag caps -->
				<element value="manage_topic_tags" />
				<element value="edit_topic_tag" />
				<element value="edit_topic_tags" />
				<element value="delete_topic_tag" />
				<element value="delete_topic_tags" />
				<element value="remove_topic_tag" />
				<element value="assign_topic_tags" />
			</property>
		</properties>
	</rule>


	<!--
	#############################################################################
	SELECTIVE EXCLUSIONS
	Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
	#############################################################################
	-->

	<rule ref="Generic.Formatting.MultipleStatementAlignment.IncorrectWarning">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.Formatting.MultipleStatementAlignment.NotSameWarning">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.WhiteSpace.ScopeIndent.Incorrect">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.WhiteSpace.ScopeIndent.IncorrectExact">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.NamingConventions.ValidClassName.StartWithCapital">
		<exclude-pattern>/bbpress\.php$</exclude-pattern>
		<exclude-pattern>/src/bbpress\.php$</exclude-pattern>
		<exclude-pattern>/src/includes/admin/converters/bbPress1\.php$</exclude-pattern>
		<exclude-pattern>/src/includes/admin/converters/e107v1\.php$</exclude-pattern>
		<exclude-pattern>/src/includes/admin/converters/phpBB\.php$</exclude-pattern>
		<exclude-pattern>/src/includes/admin/converters/vBulletin\.php$</exclude-pattern>
		<exclude-pattern>/src/includes/admin/converters/vBulletin3\.php$</exclude-pattern>
	</rule>

	<rule ref="PEAR.Files.IncludingFile.UseRequire">
		<exclude-pattern>/bbpress\.php$</exclude-pattern>
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.EmbeddedPhp.ContentBeforeEnd">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.EmbeddedPhp.ContentBeforeOpen">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
		<exclude-pattern>/src/templates/*</exclude-pattern>
	</rule>

	<!--
	"bbp" is the deliberately chosen project prefix. Suppress the ShortPrefixPassed
	warning that WPCS 3.0+ raises for prefixes shorter than 4 characters.
	-->
	<rule ref="WordPress.NamingConventions.PrefixAllGlobals.ShortPrefixPassed">
		<severity>0</severity>
	</rule>

	<!--
	#############################################################################
	TEMPORARY ADJUSTMENTS
	Adjustments which should be removed once the associated issues have been reviewed and resolved.
	#############################################################################
	-->

	<rule ref="Generic.CodeAnalysis.AssignmentInCondition.Found">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence.MissingParentheses">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.Files.OneObjectStructurePerFile.MultipleFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing.SpaceBeforeClose">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="NormalizedArrays.Arrays.ArrayBraceSpacing.SpaceBeforeArrayCloserSingleLine">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLine">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.Functions.FunctionCallSignature.FirstArgumentPosition">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeOpenBracket">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.CommentedOutCode.Found">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.DisallowMultipleAssignments.Found">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.EmbeddedPhp.ContentAfterEnd">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.EmbeddedPhp.ContentAfterOpen">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.PHP.EmbeddedPhp.SpacingAfterOpen">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Squiz.Strings.ConcatenationSpacing.PaddingFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Universal.Files.SeparateFunctionsFromOO.Mixed">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.classFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames.require_onceFound">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.Files.FileName.InvalidClassFileName">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.Security.EscapeOutput.OutputNotEscaped">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.Security.NonceVerification.Missing">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.Security.NonceVerification.Recommended">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

	<rule ref="WordPress.WP.AlternativeFunctions.json_encode_json_encode">
		<exclude-pattern>/src/*</exclude-pattern>
	</rule>

</ruleset>
