Skip to content

Commit 8ea08a5

Browse files
committed
Merge branch 'feature/3424-pear-functiondeclaration-handle-attributes' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 4214784 + 18c5d6f commit 8ea08a5

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
lines changed

src/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,14 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct
460460
if ($tokens[$i]['code'] === T_WHITESPACE
461461
&& $tokens[$i]['line'] !== $tokens[($i + 1)]['line']
462462
) {
463-
// This is an empty line, so don't check the indent.
464-
$foundIndent = $expectedIndent;
465-
466463
$error = 'Blank lines are not allowed in a multi-line '.$type.' declaration';
467464
$fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
468465
if ($fix === true) {
469466
$phpcsFile->fixer->replaceToken($i, '');
470467
}
468+
469+
// This is an empty line, so don't check the indent.
470+
continue;
471471
} else if ($tokens[$i]['code'] === T_WHITESPACE) {
472472
$foundIndent = $tokens[$i]['length'];
473473
} else if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
@@ -507,6 +507,13 @@ public function processArgumentList($phpcsFile, $stackPtr, $indent, $type='funct
507507
$lastLine = $tokens[$i]['line'];
508508
continue;
509509
}
510+
511+
if ($tokens[$i]['code'] === T_ATTRIBUTE) {
512+
// Skip attributes as they have their own indentation rules.
513+
$i = $tokens[$i]['attribute_closer'];
514+
$lastLine = $tokens[$i]['line'];
515+
continue;
516+
}
510517
}//end for
511518

512519
}//end processArgumentList()

src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,47 @@ private string $private,
372372
) {
373373
}
374374
}
375+
376+
class ConstructorPropertyPromotionMultiLineAttributesOK
377+
public function __construct(
378+
#[ORM\ManyToOne(
379+
Something: true,
380+
SomethingElse: 'text',
381+
)]
382+
#[Groups([
383+
'ArrayEntry',
384+
'Another.ArrayEntry',
385+
])]
386+
#[MoreGroups(
387+
[
388+
'ArrayEntry',
389+
'Another.ArrayEntry',
390+
]
391+
)]
392+
private Type $property
393+
) {
394+
// Do something.
395+
}
396+
}
397+
398+
class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent
399+
public function __construct(
400+
#[ORM\ManyToOne(
401+
Something: true,
402+
SomethingElse: 'text',
403+
)]
404+
#[Groups([
405+
'ArrayEntry',
406+
'Another.ArrayEntry',
407+
])]
408+
#[MoreGroups(
409+
[
410+
'ArrayEntry',
411+
'Another.ArrayEntry',
412+
]
413+
)]
414+
private Type $property
415+
) {
416+
// Do something.
417+
}
418+
}

src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,47 @@ class ConstructorPropertyPromotionMultiLineDocblockAndAttributeIncorrectIndent
370370
) {
371371
}
372372
}
373+
374+
class ConstructorPropertyPromotionMultiLineAttributesOK
375+
public function __construct(
376+
#[ORM\ManyToOne(
377+
Something: true,
378+
SomethingElse: 'text',
379+
)]
380+
#[Groups([
381+
'ArrayEntry',
382+
'Another.ArrayEntry',
383+
])]
384+
#[MoreGroups(
385+
[
386+
'ArrayEntry',
387+
'Another.ArrayEntry',
388+
]
389+
)]
390+
private Type $property
391+
) {
392+
// Do something.
393+
}
394+
}
395+
396+
class ConstructorPropertyPromotionMultiLineAttributesIncorrectIndent
397+
public function __construct(
398+
#[ORM\ManyToOne(
399+
Something: true,
400+
SomethingElse: 'text',
401+
)]
402+
#[Groups([
403+
'ArrayEntry',
404+
'Another.ArrayEntry',
405+
])]
406+
#[MoreGroups(
407+
[
408+
'ArrayEntry',
409+
'Another.ArrayEntry',
410+
]
411+
)]
412+
private Type $property
413+
) {
414+
// Do something.
415+
}
416+
}

src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public function getErrorList($testFile='FunctionDeclarationUnitTest.inc')
9797
369 => 1,
9898
370 => 1,
9999
371 => 1,
100+
400 => 1,
101+
404 => 1,
100102
];
101103
} else {
102104
$errors = [

0 commit comments

Comments
 (0)