Skip to content

Commit

Permalink
[Php74] Skip Nested ternary parenthesized multiline on ParenthesizeNe…
Browse files Browse the repository at this point in the history
…stedTernaryRector (#2902)
  • Loading branch information
samsonasik committed Sep 3, 2022
1 parent a39844e commit d3cab63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\Php74\Rector\Ternary\ParenthesizeNestedTernaryRector\Fixture;

function SkipNestedTernaryParenthesizedMultiline()
{
is_dir('app')
? 'app'
: (is_dir('vendor/app')
? 'vendor/app'
: 'vendor/alternative');
}
6 changes: 5 additions & 1 deletion rules/Php74/Tokenizer/ParenthesizedNestedTernaryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public function isParenthesized(File $file, Ternary $ternary): bool
{
$oldTokens = $file->getOldTokens();
$startTokenPos = $ternary->getStartTokenPos();
$endTokenPos = $ternary->getEndTokenPos();

return isset($oldTokens[$startTokenPos]) && $oldTokens[$startTokenPos] === '(';
$hasOpenParentheses = isset($oldTokens[$startTokenPos]) && $oldTokens[$startTokenPos] === '(';
$hasCloseParentheses = isset($oldTokens[$endTokenPos]) && $oldTokens[$endTokenPos] === ')';

return $hasOpenParentheses || $hasCloseParentheses;
}
}

0 comments on commit d3cab63

Please sign in to comment.