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,57 @@
<?php

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

final class IntOrNumericString
{
private function getAssetSize(): int
{
return 1000;
}

public function getTotalFilesize($assets)
{
if (empty($assets)) {
return 0;
}

$size = $this->getAssetSize($assets);

if ($size) {
$size = (string) $size;
}

return $size;
}
}

?>
-----
<?php

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

final class IntOrNumericString
{
private function getAssetSize(): int
{
return 1000;
}

public function getTotalFilesize($assets): int|string
{
if (empty($assets)) {
return 0;
}

$size = $this->getAssetSize($assets);

if ($size) {
$size = (string) $size;
}

return $size;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\PhpDocParser\Ast\Node as AstNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
Expand Down Expand Up @@ -91,6 +92,11 @@ function (AstNode $astNode): int|IdentifierTypeNode {
*/
public function mapToPhpParserNode(Type $type, string $typeKind): ?Node
{
// accessory string types, e.g. "numeric-string&non-falsy-string", are just "string"
if ($type->isString()->yes()) {
return new Identifier('string');
}

if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::INTERSECTION_TYPES)) {
return null;
}
Expand Down
Loading