Skip to content

Commit

Permalink
[TypeDeclaration] Use $type->isScalar()->yes() on AlwaysStrictScalarE…
Browse files Browse the repository at this point in the history
…xprAnalyzer (#4920)
  • Loading branch information
samsonasik committed Sep 6, 2023
1 parent c4ea636 commit 0d2cdf0
Showing 1 changed file with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function matchStrictScalarExpr(Expr $expr, Scope $scope): ?Type
}

$exprType = $this->nodeTypeResolver->getNativeType($expr);
if ($this->isScalarType($exprType)) {
if ($exprType->isScalar()->yes()) {
return $exprType;
}

Expand All @@ -79,31 +79,13 @@ public function matchStrictScalarExpr(Expr $expr, Scope $scope): ?Type
private function resolveCastType(Cast $cast): ?Type
{
$type = $this->nodeTypeResolver->getNativeType($cast);
if ($this->isScalarType($type)) {
if ($type->isScalar()->yes()) {
return $type;
}

return null;
}

private function isScalarType(Type $type): bool
{
if ($type->isString()->yes()) {
return true;
}

if ($type->isFloat()->yes()) {
return true;
}

if ($type->isInteger()->yes()) {
return true;
}

return $type->isBoolean()
->yes();
}

private function resolveTypeFromScalar(Scalar $scalar): Type|null
{
if ($scalar instanceof Encapsed) {
Expand Down Expand Up @@ -155,10 +137,10 @@ private function resolveFuncCallType(FuncCall $funcCall, Scope $scope): ?Type
);

$returnType = $parametersAcceptor->getReturnType();
if (! $this->isScalarType($returnType)) {
return null;
if ($returnType->isScalar()->yes()) {
return $returnType;
}

return $returnType;
return null;
}
}

0 comments on commit 0d2cdf0

Please sign in to comment.