[Strict] Skip possible result object or int on BooleanInIfConditionRuleFixerRector (#2016)

This commit is contained in:
Abdul Malik Ikhsan 2022-04-07 15:28:48 +07:00 committed by GitHub
parent 8f9abbd8b7
commit 4dd71f8f31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,41 @@
<?php
/**
* FUTURE NOTE: Dont add namespace to this Fixture:
*
* Skip Result Object or int only reproducible when on non-namespaced class
* and collection of class is on single file
*/
class ForwardCompatibilityResult {
}
class QueryBuilder {
/**
* Executes this query using the bound parameters and their types.
*
* @return ForwardCompatibilityResult|int
*
* @throws Exception
*/
public function execute()
{
if ($this->type === self::SELECT) {
return new ForwardCompatibilityResult();
}
return 1;
}
}
class SkipResultObject
{
public function insert(): bool {
$queryBuilder = new QueryBuilder();
if ($queryBuilder->execute()) {
return false;
}
throw new \RuntimeException('...');
}
}

View File

@ -113,13 +113,17 @@ final class ExactCompareFactory
$compareExprs[] = $this->createNotIdenticalFalsyCompare($unionedType, $expr, $treatAsNotEmpty);
}
/** @var Expr $truthyExpr */
/** @var ?Expr $truthyExpr */
$truthyExpr = array_shift($compareExprs);
foreach ($compareExprs as $compareExpr) {
if (! $compareExpr instanceof Expr) {
return null;
}
if (! $truthyExpr instanceof Expr) {
return null;
}
/** @var Expr $compareExpr */
$truthyExpr = new BooleanOr($truthyExpr, $compareExpr);
}