Skip to content

Handling of list() language construct #9

@jrfnl

Description

@jrfnl

Repost from squizlabs/PHP_CodeSniffer#1699:

Proposal: add list() to the Tokens::$functionNameTokens property

While list is a language construct, for the purpose of formatting, it is normally treated as if it were a function call, similar to how isset() or empty() are treated.

To that end, I propose adding list to the Tokens::$functionNameTokens property.

There are two sniffs within PHPCS whose behaviour will change if this proposal is accepted:

  • Generic.Functions.FunctionCallArgumentSpacing
  • PEAR.Functions.FunctionCallSignature (and by extension PSR2.Methods.FunctionCallSignature)

For the Generic.Functions.FunctionCallArgumentSpacing, it would mean that a slight adjustment is needed to account for the possibility of an empty element, like in list($drink, , $power) = $info; which would otherwise trigger a no space allowed before comma error.

I'd be happy to create a PR to handle this if there is support for this proposal.

Opinions ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions