Skip to content

Incorrect detection of operator in ternary + anonymous function #1782

Closed
@VasekPurchart

Description

@VasekPurchart

I think there is a problem with detection of the : operator in ternary in combination with a function. I found this out while using Squiz.WhiteSpace.OperatorSpacing, but it can be more general.

This case throws error:

<?php

$x = $foo
	? function (): int {
		return 1;
	}
	: $bar;
 4 | ERROR | [x] Expected 1 space before ":"; 0 found (Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore)

while just inverting the condition is ok:

<?php

$x = !$foo
	? $bar
	: function (): int {
		return 1;
	};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions