From 2c77fbdba7c003f77a3fa1ae09016449ff0b54e1 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 23 Mar 2024 11:13:17 +0100 Subject: [PATCH] Cover methods, interfaces and traits with space after attributes Plus fix some `#[\Attribute(` wrong constructors by renaming to custom one. --- .../Commenting/MissingDocblockSniffTest.php | 17 +++++++++++++++++ ...ly_with_attributes_incorrect_whitespace.php | 8 ++++++++ .../docblock_with_multiline_attributes.php | 18 +++++++++--------- ...ly_with_attributes_incorrect_whitespace.php | 14 ++++++++++++++ ...ly_with_attributes_incorrect_whitespace.php | 14 ++++++++++++++ 5 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/interface_only_with_attributes_incorrect_whitespace.php create mode 100644 moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/trait_only_with_attributes_incorrect_whitespace.php diff --git a/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php b/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php index 8f007a1..0f92795 100644 --- a/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php +++ b/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php @@ -108,6 +108,23 @@ public static function docblockCorrectnessProvider(): array { 'fixtureFilename' => null, 'errors' => [ 13 => 'Missing docblock for class class_only_with_attributes_incorrect_whitespace', + 20 => 'Missing docblock for function method_only_with_attributes_incorrect_whitespace', + ], + 'warnings' => [], + ], + 'Interface only with attributes and incorrect whitespace' => [ + 'fixture' => 'interface_only_with_attributes_incorrect_whitespace', + 'fixtureFilename' => null, + 'errors' => [ + 13 => 'Missing docblock for interface interface_only_with_attributes_incorrect_whitespace', + ], + 'warnings' => [], + ], + 'Trait only with attributes and incorrect whitespace' => [ + 'fixture' => 'trait_only_with_attributes_incorrect_whitespace', + 'fixtureFilename' => null, + 'errors' => [ + 13 => 'Missing docblock for trait trait_only_with_attributes_incorrect_whitespace', ], 'warnings' => [], ], diff --git a/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/class_only_with_attributes_incorrect_whitespace.php b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/class_only_with_attributes_incorrect_whitespace.php index 33c021e..6d50083 100644 --- a/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/class_only_with_attributes_incorrect_whitespace.php +++ b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/class_only_with_attributes_incorrect_whitespace.php @@ -11,4 +11,12 @@ #[with_multiple_attributes, and_another_attribute] class class_only_with_attributes_incorrect_whitespace { + /** + * Method level docblock. + */ + #[example_attribute] + #[with_multiple_attributes, and_another_attribute] + + function method_only_with_attributes_incorrect_whitespace(): void { + } } diff --git a/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/docblock_with_multiline_attributes.php b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/docblock_with_multiline_attributes.php index 045f8d1..f516255 100644 --- a/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/docblock_with_multiline_attributes.php +++ b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/docblock_with_multiline_attributes.php @@ -9,9 +9,9 @@ defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures. /** - * Example class. + * Example class. */ -#[\Attribute( +#[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -20,7 +20,7 @@ class class_multiline_attribute { /** * Method attribute. */ - #[\Attribute( + #[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -31,7 +31,7 @@ function method_multiline_attribute(): void { /** * Interface with multiline attributes. */ -#[\Attribute( +#[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -41,7 +41,7 @@ interface interface_multiline_attribute { /** * Trait with multiline attributes. */ -#[\Attribute( +#[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -52,7 +52,7 @@ trait trait_multiline_attribute { * Example class. */ -#[\Attribute( +#[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -62,7 +62,7 @@ class class_multiline_attribute_space_between { * Method attribute. */ - #[\Attribute( + #[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -74,7 +74,7 @@ function method_multiline_attribute_space_between(): void { * Interface with multiline attributes. */ -#[\Attribute( +#[someattribute( attr1: 'asdf', attr2: 'asdf', )] @@ -85,7 +85,7 @@ interface interface_multiline_attribute_space_between { * Trait with multiline attributes and space between. */ - #[\Attribute( + #[someattribute( attr1: 'asdf', attr2: 'asdf', )] diff --git a/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/interface_only_with_attributes_incorrect_whitespace.php b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/interface_only_with_attributes_incorrect_whitespace.php new file mode 100644 index 0000000..caa180b --- /dev/null +++ b/moodle/Tests/Sniffs/Commenting/fixtures/MissingDocblock/interface_only_with_attributes_incorrect_whitespace.php @@ -0,0 +1,14 @@ +