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

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector\Fixture;

final class SkipSubtype
{
/**
* @return callable-string
*/
public function getCallableString(): string
{
return 'trim';
}

/**
* @return non-empty-lowercase-string
*/
public function getNonEmptyLowercaseString(): string
{
return 'abc';
}

/**
* @return non-empty-uppercase-string
*/
public function getNonEmptyUppercaseString(): string
{
return 'ABC';
}

/**
* @return non-empty-literal-string
*/
public function getNonEmptyLiteralString(): string
{
return '3v4l';
}

/**
* @return decimal-int-string
*/
public function getDecimalIntString(): string
{
return '123';
}

/**
* @return non-decimal-int-string
*/
public function getNonDecimalIntString(): string
{
return '+1';
}
}
37 changes: 37 additions & 0 deletions src/StaticTypeMapper/Mapper/ScalarStringToTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType;
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
Expand Down Expand Up @@ -91,6 +92,42 @@ public function mapScalarStringToType(string $scalarName): Type
return new UnionType([new IntegerType(), new StringType()]);
}

if ($loweredScalarName === 'callable-string') {
return TypeCombinator::intersect(new StringType(), new CallableType());
}

if ($loweredScalarName === 'non-empty-lowercase-string') {
return TypeCombinator::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
new AccessoryLowercaseStringType()
);
}

if ($loweredScalarName === 'non-empty-uppercase-string') {
return TypeCombinator::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
new AccessoryUppercaseStringType()
);
}

if ($loweredScalarName === 'non-empty-literal-string') {
return TypeCombinator::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
new AccessoryLiteralStringType()
);
}

if ($loweredScalarName === 'decimal-int-string') {
return TypeCombinator::intersect(new StringType(), new AccessoryDecimalIntegerStringType());
}

if ($loweredScalarName === 'non-decimal-int-string') {
return TypeCombinator::intersect(new StringType(), new AccessoryDecimalIntegerStringType(true));
}

foreach (self::SCALAR_NAME_BY_TYPE as $objectType => $scalarNames) {
if (! in_array($loweredScalarName, $scalarNames, true)) {
continue;
Expand Down
Loading