Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,21 @@ public function processBracket($phpcsFile, $openBracket, $tokens, $type='functio
// Each line between the brackets should contain a single parameter.
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
// Skip brackets, like arrays, as they can contain commas.
if (isset($tokens[$i]['bracket_opener']) === true) {
if (isset($tokens[$i]['bracket_closer']) === true) {
$i = $tokens[$i]['bracket_closer'];
continue;
}

if (isset($tokens[$i]['parenthesis_opener']) === true) {
if (isset($tokens[$i]['parenthesis_closer']) === true) {
$i = $tokens[$i]['parenthesis_closer'];
continue;
}

if (isset($tokens[$i]['attribute_closer']) === true) {
$i = $tokens[$i]['attribute_closer'];
continue;
}

if ($tokens[$i]['code'] !== T_COMMA) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,55 @@ new ExceptionMessage(),
) {
}
}

// Issue #608 - multi-attributes are not handled correctly.
function ParamWithMultiAttributeOnSameLine(
#[AttributeA, AttributeB] string $param,
) {
}

function ParamWithMultiAttributeOnSameLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])] string $param,
) {
}

function ParamWithMultiAttributeOnSameLine(
#[AttributeA, AttributeB] string $paramA, int $paramB
) {
}

function ParamWithMultiAttributeOnSameLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])] string $param, int $paramB
) {
}

function ParamWithAttributeOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[Attribute]
string $param,
) {
}

function ParamWithMultipleAttributesOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[AttributeA]
#[AttributeB]
string $param,
) {
}

function ParamWithAttributeOnOwnLineWithParamsShouldNotBeSeenAsMultipleFnParamse(
#[Attribute(10, 20)]
string $param,
) {
}

function ParamWithMultiAttributeOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[AttributeA, AttributeB]
string $param,
) {
}

function ParamWithMultiAttributeOnOwnLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])]
string $param,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,57 @@ new ExceptionMessage(),
) {
}
}

// Issue #608 - multi-attributes are not handled correctly.
function ParamWithMultiAttributeOnSameLine(
#[AttributeA, AttributeB] string $param,
) {
}

function ParamWithMultiAttributeOnSameLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])] string $param,
) {
}

function ParamWithMultiAttributeOnSameLine(
#[AttributeA, AttributeB] string $paramA,
int $paramB
) {
}

function ParamWithMultiAttributeOnSameLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])] string $param,
int $paramB
) {
}

function ParamWithAttributeOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[Attribute]
string $param,
) {
}

function ParamWithMultipleAttributesOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[AttributeA]
#[AttributeB]
string $param,
) {
}

function ParamWithAttributeOnOwnLineWithParamsShouldNotBeSeenAsMultipleFnParamse(
#[Attribute(10, 20)]
string $param,
) {
}

function ParamWithMultiAttributeOnOwnLineShouldNotBeSeenAsMultipleFnParams(
#[AttributeA, AttributeB]
string $param,
) {
}

function ParamWithMultiAttributeOnOwnLineWithParamsShouldNotBeSeenAsMultipleFnParams(
#[AttributeA(10, 'test'), AttributeB([1, 2, 3,])]
string $param,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function getErrorList($testFile='')
252 => 1,
253 => 1,
254 => 1,
318 => 1,
323 => 1,
];
} else {
$errors = [
Expand Down