mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
d3cab63bcb
[Php74] Skip Nested ternary parenthesized multiline on ParenthesizeNestedTernaryRector (#2902)
20 lines
696 B
PHP
20 lines
696 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Php74\Tokenizer;
|
|
|
|
use PhpParser\Node\Expr\Ternary;
|
|
use Rector\Core\ValueObject\Application\File;
|
|
final class ParenthesizedNestedTernaryAnalyzer
|
|
{
|
|
public function isParenthesized(File $file, Ternary $ternary) : bool
|
|
{
|
|
$oldTokens = $file->getOldTokens();
|
|
$startTokenPos = $ternary->getStartTokenPos();
|
|
$endTokenPos = $ternary->getEndTokenPos();
|
|
$hasOpenParentheses = isset($oldTokens[$startTokenPos]) && $oldTokens[$startTokenPos] === '(';
|
|
$hasCloseParentheses = isset($oldTokens[$endTokenPos]) && $oldTokens[$endTokenPos] === ')';
|
|
return $hasOpenParentheses || $hasCloseParentheses;
|
|
}
|
|
}
|