Skip to content

Commit

Permalink
PEAR/FunctionDeclaration: ignore multi-line promoted properties
Browse files Browse the repository at this point in the history
Similar to (multi-line) arrays in a multi-line function declaration, ignore (multi-line) attributes for the purposes of the indentation checks in this sniff.

This does mean that inconsistent indentation within multi-line attributes/ for an attribute closer will not be fixed, but that should be handled by a dedicated attribute formatting sniff in my opinion.

Includes unit tests.

Fixes 3424
  • Loading branch information
jrfnl committed Sep 5, 2021
1 parent b10c327 commit 074622b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,13 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct
$lastLine = $tokens[$i]['line'];
continue;
}

if ($tokens[$i]['code'] === T_ATTRIBUTE) {
// Skip attributes as they have their own indentation rules.
$i = $tokens[$i]['attribute_closer'];
$lastLine = $tokens[$i]['line'];
continue;
}
}//end for

}//end processArgumentList()
Expand Down
44 changes: 44 additions & 0 deletions src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,47 @@ private string $private,
) {
}
}

class ConstructorPropertyPromotionMultiLineAttributesOK
public function __construct(
#[ORM\ManyToOne(
Something: true,
SomethingElse: 'text',
)]
#[Groups([
'ArrayEntry',
'Another.ArrayEntry',
])]
#[MoreGroups(
[
'ArrayEntry',
'Another.ArrayEntry',
]
)]
private Type $property
) {
// Do something.
}
}

class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent
public function __construct(
#[ORM\ManyToOne(
Something: true,
SomethingElse: 'text',
)]
#[Groups([
'ArrayEntry',
'Another.ArrayEntry',
])]
#[MoreGroups(
[
'ArrayEntry',
'Another.ArrayEntry',
]
)]
private Type $property
) {
// Do something.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,47 @@ class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent
) {
}
}

class ConstructorPropertyPromotionMultiLineAttributesOK
public function __construct(
#[ORM\ManyToOne(
Something: true,
SomethingElse: 'text',
)]
#[Groups([
'ArrayEntry',
'Another.ArrayEntry',
])]
#[MoreGroups(
[
'ArrayEntry',
'Another.ArrayEntry',
]
)]
private Type $property
) {
// Do something.
}
}

class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent
public function __construct(
#[ORM\ManyToOne(
Something: true,
SomethingElse: 'text',
)]
#[Groups([
'ArrayEntry',
'Another.ArrayEntry',
])]
#[MoreGroups(
[
'ArrayEntry',
'Another.ArrayEntry',
]
)]
private Type $property
) {
// Do something.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function getErrorList($testFile='FunctionDeclarationUnitTest.inc')
369 => 1,
370 => 1,
371 => 1,
400 => 1,
404 => 1,
];
} else {
$errors = [
Expand Down

0 comments on commit 074622b

Please sign in to comment.