coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Enforce ternary symbol placement

Open spaceemotion opened this issue 5 years ago • 2 comments

I was wondering if there is a sniff that can enforce placement of the ? and : symbols.

Given the following snippet:

$class = array_key_exists($foo, 'bar') ?
    $foo['bar']['class'] :
    Default::class;

I would like to enforce them being placed in front of each line (only in multi-line statements):

$class = array_key_exists($foo, 'bar')
    ? $foo['bar']['class']
    : Default::class;

spaceemotion avatar Aug 10 '20 08:08 spaceemotion

Such rule can be generalized for any operator.

$message .= $spaces
	. $line
	. ($key === $lastLine ? '' : PHP_EOL);
$number = $n1
	+ $n2
	+ $n3;

mabar avatar Jul 22 '21 02:07 mabar