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
17 changes: 14 additions & 3 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,7 @@ public function getDeclarationName($stackPtr)
* 'name' => '$var', // The variable name.
* 'token' => integer, // The stack pointer to the variable name.
* 'content' => string, // The full content of the variable definition.
* 'attributes' => boolean, // Does the parameter have one or more attributes attached ?
* 'pass_by_reference' => boolean, // Is the variable passed by reference?
* 'reference_token' => integer, // The stack pointer to the reference operator
* // or FALSE if the param is not passed by reference.
Expand Down Expand Up @@ -1355,6 +1356,7 @@ public function getMethodParameters($stackPtr)
$defaultStart = null;
$equalToken = null;
$paramCount = 0;
$attributes = false;
$passByReference = false;
$referenceToken = false;
$variableLength = false;
Expand All @@ -1373,18 +1375,25 @@ public function getMethodParameters($stackPtr)
if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $this->tokens[$i]['parenthesis_closer']) {
$i = ($this->tokens[$i]['parenthesis_closer'] + 1);
$i = $this->tokens[$i]['parenthesis_closer'];
continue;
}
}

if (isset($this->tokens[$i]['bracket_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $this->tokens[$i]['bracket_closer']) {
$i = ($this->tokens[$i]['bracket_closer'] + 1);
$i = $this->tokens[$i]['bracket_closer'];
continue;
}
}

switch ($this->tokens[$i]['code']) {
case T_ATTRIBUTE:
$attributes = true;

// Skip to the end of the attribute.
$i = $this->tokens[$i]['attribute_closer'];
break;
case T_BITWISE_AND:
if ($defaultStart === null) {
$passByReference = true;
Expand Down Expand Up @@ -1501,6 +1510,7 @@ public function getMethodParameters($stackPtr)
$vars[$paramCount]['default_equal_token'] = $equalToken;
}

$vars[$paramCount]['attributes'] = $attributes;
$vars[$paramCount]['pass_by_reference'] = $passByReference;
$vars[$paramCount]['reference_token'] = $referenceToken;
$vars[$paramCount]['variable_length'] = $variableLength;
Expand All @@ -1526,6 +1536,7 @@ public function getMethodParameters($stackPtr)
$paramStart = ($i + 1);
$defaultStart = null;
$equalToken = null;
$attributes = false;
$passByReference = false;
$referenceToken = false;
$variableLength = false;
Expand Down
20 changes: 20 additions & 0 deletions tests/Core/File/GetMethodParametersTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,23 @@ abstract class ConstructorPropertyPromotionAbstractMethod {
// 3. The callable type is not supported for properties, but that's not the concern of this method.
abstract public function __construct(public callable $y, private ...$x);
}

/* testCommentsInParameter */
function commentsInParams(
// Leading comment.
?MyClass /*-*/ & /*-*/.../*-*/ $param /*-*/ = /*-*/ 'default value' . /*-*/ 'second part' // Trailing comment.
) {}

/* testParameterAttributesInFunctionDeclaration */
class ParametersWithAttributes(
public function __construct(
#[\MyExample\MyAttribute] private string $constructorPropPromTypedParamSingleAttribute,
#[MyAttr([1, 2])]
Type|false
$typedParamSingleAttribute,
#[MyAttribute(1234), MyAttribute(5678)] ?int $nullableTypedParamMultiAttribute,
#[WithoutArgument] #[SingleArgument(0)] $nonTypedParamTwoAttributes,
#[MyAttribute(array("key" => "value"))]
&...$otherParam,
) {}
}
Loading