Skip to content

[code-quality] Add AttributeNamedArgsRector#8079

Open
DaveLiddament wants to merge 1 commit into
rectorphp:mainfrom
DaveLiddament:add-attribute-named-args-rector
Open

[code-quality] Add AttributeNamedArgsRector#8079
DaveLiddament wants to merge 1 commit into
rectorphp:mainfrom
DaveLiddament:add-attribute-named-args-rector

Conversation

@DaveLiddament

Copy link
Copy Markdown
Contributor

Convert positional arguments on configured attributes into named arguments, taking the names from the attribute constructor signature. Configurable per attribute class via the AttributeNamedArgs value object, with an optional firstNamedPosition threshold to leave leading arguments positional. Skips already-named arguments and bails out when an argument maps to a variadic or missing parameter to avoid producing invalid PHP.

Convert positional arguments on configured attributes into named
arguments, taking the names from the attribute constructor signature.
Configurable per attribute class via the AttributeNamedArgs value
object, with an optional firstNamedPosition threshold to leave leading
arguments positional. Skips already-named arguments and bails out when
an argument maps to a variadic or missing parameter to avoid producing
invalid PHP.
* @param int $firstNamedPosition first positional index to name (0 = name all arguments)
*/
public function __construct(
private string $attributeClass,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add simple class-name validation here?

Ref \Rector\Validation\RectorAssert::className()

@TomasVotruba

Copy link
Copy Markdown
Member

Very nice rule! 👏

We actually have PHPStan rule enforcing this, but still do it manually lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants