for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Imanghafoori\LaravelMicroscope\Refactors;
class NestedIf
{
public static function merge($tokens, $cond1EndIndex, $cond2StartIndex, $if2BodyEndIndex)
$newTokens = [];
foreach ($tokens as $i => $oldToken) {
if ($i == $cond1EndIndex) {
$newTokens[] = [T_WHITESPACE, ' '];
$newTokens[] = [T_BOOLEAN_AND, '&&'];
continue;
}
if ($i > $cond1EndIndex && $i <= $cond2StartIndex) {
if ($i == $if2BodyEndIndex || ($i == $if2BodyEndIndex + 1 && $oldToken == ';')) {
$newTokens[] = $oldToken;
return $newTokens;