From 4a93b2bcdbc3c9178e67f102b4f416624d792a25 Mon Sep 17 00:00:00 2001 From: Nic Wortel Date: Thu, 11 Jan 2024 16:42:26 +0100 Subject: [PATCH] Enforce blank lines between class members --- NicWortel/ruleset.xml | 8 ++++++++ composer.json | 2 +- tests/correct/class.php | 26 ++++++++++++++++++++++++++ tests/expected.csv | 3 +++ tests/incorrect/members-newlines.php | 21 +++++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/correct/class.php create mode 100644 tests/incorrect/members-newlines.php diff --git a/NicWortel/ruleset.xml b/NicWortel/ruleset.xml index c12bc94..5a9e1ce 100644 --- a/NicWortel/ruleset.xml +++ b/NicWortel/ruleset.xml @@ -45,6 +45,14 @@ + + + + + + + + diff --git a/composer.json b/composer.json index dbe167e..ed0eec0 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": "^8.1", "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "slevomat/coding-standard": "^8.8", + "slevomat/coding-standard": "^8.9", "squizlabs/php_codesniffer": "^3.7" }, "require-dev": { diff --git a/tests/correct/class.php b/tests/correct/class.php new file mode 100644 index 0000000..60d329a --- /dev/null +++ b/tests/correct/class.php @@ -0,0 +1,26 @@ +foo; + } + + public function bar(): string + { + return $this->bar; + } +} diff --git a/tests/expected.csv b/tests/expected.csv index 7690acf..cd88358 100644 --- a/tests/expected.csv +++ b/tests/expected.csv @@ -27,6 +27,9 @@ "tests/incorrect/imports-unused.php",8,1,error,"Type array_filter is not used in this file.",SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse,5,1 "tests/incorrect/imports-unused.php",8,26,error,"Header blocks must be separated by a single blank line",PSR12.Files.FileHeader.SpacingAfterBlock,5,1 "tests/incorrect/imports-unused.php",9,1,error,"Type PHP_VERSION is not used in this file.",SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse,5,1 +"tests/incorrect/members-newlines.php",11,20,error,"Expected 1 blank line between class members, found 0.",SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers,5,1 +"tests/incorrect/members-newlines.php",13,12,error,"Expected 1 blank line after method, found 0.",SlevomatCodingStandard.Classes.MethodSpacing.IncorrectLinesCountBetweenMethods,5,1 +"tests/incorrect/members-newlines.php",13,12,error,"Expected 1 blank line between class members, found 0.",SlevomatCodingStandard.Classes.ClassMemberSpacing.IncorrectCountOfBlankLinesBetweenMembers,5,1 "tests/incorrect/namespaces.php",10,12,error,"Class \DateTime should not be referenced via a fully qualified name, but via a use statement.",SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName,5,1 "tests/incorrect/namespaces.php",12,10,error,"Function array_filter() should not be referenced via a fallback global name, but via a use statement.",SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName,5,1 "tests/incorrect/namespaces.php",14,12,error,"Constant PHP_VERSION should not be referenced via a fallback global name, but via a use statement.",SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName,5,1 diff --git a/tests/incorrect/members-newlines.php b/tests/incorrect/members-newlines.php new file mode 100644 index 0000000..8cc8fdc --- /dev/null +++ b/tests/incorrect/members-newlines.php @@ -0,0 +1,21 @@ +foo; + } + public function bar(): string + { + return $this->bar; + } +}