switchAnalyzer = $switchAnalyzer;
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeComparator = $nodeComparator;
$this->betterStandardPrinter = $betterStandardPrinter;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function isReturnCondsAndExprs(array $condAndExprs) : bool
{
foreach ($condAndExprs as $condAndExpr) {
if ($condAndExpr->equalsMatchKind(MatchKind::RETURN)) {
return \true;
}
}
return \false;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function shouldSkipSwitch(Switch_ $switch, array $condAndExprs, ?Stmt $nextStmt) : bool
{
if ($condAndExprs === []) {
return \true;
}
if (!$this->switchAnalyzer->hasEachCaseBreak($switch)) {
return \true;
}
if ($this->switchAnalyzer->hasDifferentTypeCases($switch->cases, $switch->cond)) {
return \true;
}
if (!$this->switchAnalyzer->hasEachCaseSingleStmt($switch)) {
return \false;
}
if ($this->switchAnalyzer->hasDefaultSingleStmt($switch)) {
return \false;
}
// is followed by return? is considered implicit default
if ($this->isNextStmtReturnWithExpr($switch, $nextStmt)) {
return \false;
}
return !$nextStmt instanceof Throw_;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function haveCondAndExprsMatchPotential(array $condAndExprs) : bool
{
$uniqueCondAndExprKinds = $this->resolveUniqueKindsWithoutThrows($condAndExprs);
if (\count($uniqueCondAndExprKinds) > 1) {
return \false;
}
$assignVariableNames = [];
foreach ($condAndExprs as $condAndExpr) {
$expr = $condAndExpr->getExpr();
if (!$expr instanceof Assign) {
continue;
}
if ($expr->var instanceof ArrayDimFetch) {
$assignVariableNames[] = $this->betterStandardPrinter->print($expr->var);
} else {
$assignVariableNames[] = \get_class($expr->var) . $this->nodeNameResolver->getName($expr->var);
}
}
$assignVariableNames = \array_unique($assignVariableNames);
return \count($assignVariableNames) <= 1;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function hasCondsAndExprDefaultValue(array $condAndExprs) : bool
{
foreach ($condAndExprs as $condAndExpr) {
if ($condAndExpr->getCondExprs() === null) {
return \true;
}
}
return \false;
}
public function hasDefaultValue(Match_ $match) : bool
{
foreach ($match->arms as $matchArm) {
if ($matchArm->conds === null) {
return \true;
}
if ($matchArm->conds === []) {
return \true;
}
}
return \false;
}
/**
* @param CondAndExpr[] $condAndExprs
* @return array