This commit is contained in:
Tomas Votruba 2018-04-14 20:24:45 +02:00
parent 2443d6b1cb
commit 58a826bc6e

View File

@ -24,24 +24,24 @@ final class BetterStandardPrinter extends Standard
}
/**
* Do not add () on Expressions
* Do not add "()" on Expressions
* @see https://github.com/rectorphp/rector/pull/401#discussion_r181487199
*/
protected function pExpr_Yield(Yield_ $yieldNode)
protected function pExpr_Yield(Yield_ $yieldNode): string
{
if ($yieldNode->value === null) {
return 'yield';
} else {
$parentNode = $yieldNode->getAttribute(Attribute::PARENT_NODE);
$yieldContent = 'yield '
. ($yieldNode->key !== null ? $this->p($yieldNode->key) . ' => ' : '')
. $this->p($yieldNode->value);
if (! $parentNode instanceof Expression) {
return $yieldContent;
}
return '(' . $yieldContent . ')';
}
$parentNode = $yieldNode->getAttribute(Attribute::PARENT_NODE);
$shouldAddBrackets = $parentNode instanceof Expression;
return sprintf(
'%syield %s%s%s',
$shouldAddBrackets ? '(' : '',
$yieldNode->key !== null ? $this->p($yieldNode->key) . ' => ' : '',
$this->p($yieldNode->value),
$shouldAddBrackets ? ')' : ''
);
}
}