Skip to content

Commit

Permalink
[CodeQuality][TypeDeclaration] Add string append support on ReturnTyp…
Browse files Browse the repository at this point in the history
…eFromStrictScalarReturnExprRector (#4657)

* [CodeQuality] Add string append support on ReturnTypeFromStrictScalarReturnExprRector

* Fixed 🎉
  • Loading branch information
samsonasik committed Aug 6, 2023
1 parent 9097d76 commit 625fccc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\Fixture;

class StringAppendVariable
{
public function resolve(array $data)
{
$content = '';

foreach ($data as $value) {
$content .= $value;
}

return $content;
}
}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector\Fixture;

class StringAppendVariable
{
public function resolve(array $data): string
{
$content = '';

foreach ($data as $value) {
$content .= $value;
}

return $content;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public function matchStrictScalarExpr(Expr $expr, Scope $scope): ?Type
return $this->resolveFuncCallType($expr, $scope);
}

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

return null;
}

private function resolveCastType(Cast $cast): ?Type
{
$type = $this->nodeTypeResolver->getType($cast);
$type = $this->nodeTypeResolver->getNativeType($cast);
if ($this->isScalarType($type)) {
return $type;
}
Expand Down

0 comments on commit 625fccc

Please sign in to comment.