diff --git a/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php b/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php index 05a0c16..8f007a1 100644 --- a/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php +++ b/moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php @@ -147,6 +147,10 @@ public static function docblockCorrectnessProvider(): array { 'fixture' => 'docblock_with_multiline_attributes', 'fixtureFilename' => null, 'errors' => [ + 59 => 'Missing docblock for class class_multiline_attribute_space_between', + 69 => 'Missing docblock for function method_multiline_attribute_space_between', + 81 => 'Missing docblock for interface interface_multiline_attribute_space_between', + 92 => 'Missing docblock for trait trait_multiline_attribute_space_between', ], 'warnings' => [], ]; 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 4d248e9..045f8d1 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 @@ -41,10 +41,53 @@ interface interface_multiline_attribute { /** * Trait with multiline attributes. */ - #[\Attribute( attr1: 'asdf', attr2: 'asdf', )] trait trait_multiline_attribute { } + +/** + * Example class. + */ + +#[\Attribute( + attr1: 'asdf', + attr2: 'asdf', +)] +class class_multiline_attribute_space_between { + + /** + * Method attribute. + */ + + #[\Attribute( + attr1: 'asdf', + attr2: 'asdf', + )] + function method_multiline_attribute_space_between(): void { + } +} + +/** + * Interface with multiline attributes. + */ + +#[\Attribute( + attr1: 'asdf', + attr2: 'asdf', +)] +interface interface_multiline_attribute_space_between { +} + +/** + * Trait with multiline attributes and space between. + */ + + #[\Attribute( + attr1: 'asdf', + attr2: 'asdf', +)] +trait trait_multiline_attribute_space_between { +} diff --git a/moodle/Util/Docblocks.php b/moodle/Util/Docblocks.php index 366e172..6631daa 100644 --- a/moodle/Util/Docblocks.php +++ b/moodle/Util/Docblocks.php @@ -215,12 +215,12 @@ public static function getDocBlockPointer( if ($token['code'] === T_ATTRIBUTE_END && isset($token['attribute_opener'])) { $commentEnd = $token['attribute_opener']; - $pointerLine = $token['line']; + $pointerLine = $tokens[$commentEnd]['line']; continue; } if ($token['line'] < ($pointerLine - 1)) { - // The comment msut be on the line immediately before the pointer, or immediately before the attribute. z + // The comment must be on the line immediately before the pointer, or immediately before the attribute. z return null; }