Skip to content

Commit

Permalink
Fix docblock detection for multiline attribs (#132)
Browse files Browse the repository at this point in the history
Fixes #131.
  • Loading branch information
andrewnicols committed Mar 23, 2024
1 parent c4ad1ef commit bddb630
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 4 additions & 0 deletions moodle/Tests/Sniffs/Commenting/MissingDocblockSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
4 changes: 2 additions & 2 deletions moodle/Util/Docblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit bddb630

Please sign in to comment.