Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamStringTypeFromSprintfUseRector\Fixture;

class SkipPossibleInt
{
public function error_handler_errortype($errno): string
{
return match ($errno) {
\E_USER_ERROR, \E_ERROR, \E_COMPILE_ERROR, \E_RECOVERABLE_ERROR => 'Fatal error',
\E_PARSE => 'Parse error',
\E_USER_WARNING, \E_WARNING, \E_COMPILE_WARNING => 'Warning',
\E_USER_NOTICE, \E_NOTICE => 'Notice',
\E_USER_DEPRECATED, \E_DEPRECATED => 'Deprecated',
default => sprintf('Unknown (%s)', $errno),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamStringTypeFromSprintfUseRector\Fixture;

class SkipWithEmptyCheck
{
public function columnExpr($columnExpr, string $default): string
{
// $columnExpr can be anything empty: false | null | '' | 0 | '0' | []
if (empty($columnExpr)) {
return $default;
}

return sprintf("hello %s", $columnExpr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\MixedType;
use PHPStan\Type\UnionType;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpParser\Node\BetterNodeFinder;
Expand Down Expand Up @@ -47,8 +49,6 @@ public function matchMask(ClassMethod|Function_ $functionLike, string $variableN
/** @var Arg $messageArg */
$messageArg = array_shift($args);

$type = $this->nodeTypeResolver->getType($messageArg->value);

$messageValue = $this->valueResolver->getValue($messageArg->value);
if (! is_string($messageValue)) {
continue;
Expand All @@ -75,6 +75,11 @@ public function matchMask(ClassMethod|Function_ $functionLike, string $variableN
continue;
}

$type = $this->nodeTypeResolver->getNativeType($arg->value);
if ($type instanceof MixedType && $type->getSubtractedType() instanceof UnionType) {
continue;
}

return true;
}
}
Expand Down