Skip to content

Commit

Permalink
[CodeQuality][Up_TO_PHP_81] Handle crash indentation on combination L…
Browse files Browse the repository at this point in the history
…evelSetList::UP_TO_PHP_81 with SetList::CODE_QUALITY - take 2 (#2763)
  • Loading branch information
samsonasik authored Aug 15, 2022
1 parent 1f6cea3 commit 03ed036
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rules/Php71/Rector/FuncCall/CountOnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ArrayType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -195,6 +196,11 @@ private function shouldSkip(FuncCall $funcCall, Scope $scope): bool
return true;
}

$nativeType = $scope->getNativeType($funcCall->args[0]->value);
if ($nativeType instanceof ErrorType) {
return true;
}

return $this->variableAnalyzer->isStaticOrGlobal($funcCall->args[0]->value);
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Issues/IndentationCrash/Fixture/crash_indentation2.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Rector\Core\Tests\Issues\IndentationCrash\Fixture;

$s = new Sessions();

$psychiatry = $s->getPtNextSession($patient_id, 3, Util::ROLE_PRESCRIBER);

for ($i = 0; $i < sizeof($psychiatry); $i++) {
$psychiatry[$i]["sufficient_cancellation_notice"] = $s->isSufficientNoticeToCancel($psychiatry[$i]) ? 1 : 0;
}

?>
-----
<?php

namespace Rector\Core\Tests\Issues\IndentationCrash\Fixture;

$s = new Sessions();

$psychiatry = $s->getPtNextSession($patient_id, 3, Util::ROLE_PRESCRIBER);
$psychiatryCount = count($psychiatry);

for ($i = 0; $i < $psychiatryCount; $i++) {
$psychiatry[$i]["sufficient_cancellation_notice"] = $s->isSufficientNoticeToCancel($psychiatry[$i]) ? 1 : 0;
}

?>

0 comments on commit 03ed036

Please sign in to comment.