Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEAR/FunctionDeclaration: ignore multi-line attributes for promoted properties #3427

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
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
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.
}
}
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.
}
}
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