Skip to content

Commit

Permalink
[Php81] Handle crash insensitive function name on NullToStrictStringF…
Browse files Browse the repository at this point in the history
…uncCallArgRector (#2953)

* [Php81] Handle crash insensitive function name on NullToStrictStringFuncCallArgRector

* Fixed 🎉

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Sep 24, 2022
1 parent 54cc8e7 commit 429c9c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function mapToPhpParserNode(Type $type, string $typeKind): ?Node
return $this->mapNullabledType($nullabledType, $typeKind);
}

/**
/**
* @param TypeKind::* $typeKind
*/
private function mapNullabledType(Type $nullabledType, string $typeKind): ?Node
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class CaseInsensitiveFunctionName
{
public function run($var)
{
return strToLower($var);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class CaseInsensitiveFunctionName
{
public function run($var)
{
return strToLower((string) $var);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private function resolveOriginalPositions(FuncCall $funcCall): array
$funcCall,
$scope
);
$functionName = $this->nodeNameResolver->getName($funcCall);
$functionName = $functionReflection->getName();
$argNames = self::ARG_POSITION_NAME_NULL_TO_STRICT_STRING[$functionName];
$positions = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function matchStrictScalarExpr(Expr $expr): ?Type
if ($expr instanceof FuncCall) {
$returnType = $this->resolveFuncCallType($expr);

if ($returnType === null) {
if (! $returnType instanceof Type) {
return null;
}

Expand Down Expand Up @@ -84,11 +84,7 @@ private function isScalarType(Type $type): bool
return true;
}

if ($type instanceof BooleanType) {
return true;
}

return false;
return $type instanceof BooleanType;
}

private function resolveTypeFromScalar(Scalar $scalar): Type|null
Expand Down

0 comments on commit 429c9c0

Please sign in to comment.