Skip to content

PEAR.Functions.FunctionCallSignature enforces spaces when no arguments if required spaces is not 0 #1512

Closed
@jrfnl

Description

@jrfnl

The PEAR.Functions.FunctionCallSignature allows to configure how many spaces are required after the open parenthesis and before the close parenthesis through the $requiredSpacesAfterOpen and $requiredSpacesBeforeClose properties.

For a single line function call without parameters, the behaviour is inconsistent however when these properties are set to something other than 0.

	<rule ref="PEAR.Functions.FunctionCallSignature">
		<properties>
			<property name="requiredSpacesAfterOpen" value="1"/>
			<property name="requiredSpacesBeforeClose" value="1"/>
		</properties>
	</rule>

Current behaviour:

  • If there are no tokens between the parenthesis, it bows out of the processSingleLineCall() method.
  • If there is only a whitespace token between the parenthesis, but this contains more than one space, it will report this and the auto-fixer will correct it to the expected 1 space.
  • If there is a whitespace token between the parenthesis with only one space, it will stay silent.

Expected behaviour:

  • Either always remove the whitespace between the parenthesis if there are no parameters
  • Or always correct it to the expected nr of spaces

Example code:

ms_cookie_constants(); // Is ignored.
ms_cookie_constants( ); // Is ignored as has one space.
ms_cookie_constants(      ); // Gets corrected to one space.

I'd be happy to send in a PR to make the behaviour consistent, but would want to know which of the expected behaviours is desired.

Related: WordPress/WordPress-Coding-Standards#970

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions