Skip to content

Commit

Permalink
Merge branch 'feature/3424-pear-functiondeclaration-handle-attributes…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Sep 27, 2021
2 parents 4214784 + 18c5d6f commit 8ea08a5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct
if ($tokens[$i]['code'] === T_WHITESPACE
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
) {
// This is an empty line, so don't check the indent.
$foundIndent = $expectedIndent;

$error = 'Blank lines are not allowed in a multi-line '.$type.' declaration';
$fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($i, '');
}

// This is an empty line, so don't check the indent.
continue;
} else if ($tokens[$i]['code'] === T_WHITESPACE) {
$foundIndent = $tokens[$i]['length'];
} else if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
Expand Down 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 8ea08a5

Please sign in to comment.