mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
add phpstan-for-rector config path, consolidate return type extensions - re-use from Symplify (#4973)
* add phpstan-for-rector config path, to separate phpstan and extensions that help Rector with precise types * move type value object to value object * moving * remove KernelGetContainerAfterBootReturnTypeExtension, use one from symplify * remove ContainerGetDynamicMethodReturnTypeExtension to ContainerGetReturnTypeExtension * remove nette extension * add nette-extension * removed delegated rule * delegate implmenets + code sample PHPStan rule to symplify
This commit is contained in:
parent
ca0b4cfdc7
commit
319d6bfca1
4
.github/workflows/rector.yaml
vendored
4
.github/workflows/rector.yaml
vendored
@ -13,8 +13,8 @@ jobs:
|
||||
name: Rector without Dev Dependencies
|
||||
install: composer install --no-progress --ansi --no-dev
|
||||
run: |
|
||||
# needs to remove, add dev dependencies are missing and phpstan.neon includes them
|
||||
rm phpstan.neon
|
||||
# must be removed, as local config is missing dev dependencies
|
||||
rm phpstan-for-rector.neon
|
||||
bin/rector list
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,7 +11,6 @@ rector-recipe.php
|
||||
|
||||
# testing
|
||||
abz
|
||||
/rector-temp-phpstan*.neon
|
||||
|
||||
php-scoper.phar
|
||||
box.phar
|
||||
|
@ -182,6 +182,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
|
||||
// Run Rector only on changed files
|
||||
$parameters->set(Option::ENABLE_CACHE, true);
|
||||
|
||||
// Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-config.neon');
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -48,11 +48,12 @@
|
||||
"nette/forms": "^3.0",
|
||||
"ocramius/package-versions": "^1.9",
|
||||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||
"phpstan/phpstan-nette": "^0.12.12",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"sebastian/diff": "^4.0.4",
|
||||
"symplify/changelog-linker": "^9.0.14",
|
||||
"symplify/easy-coding-standard": "^9.0.14",
|
||||
"symplify/coding-standard": "^9.0.14",
|
||||
"symplify/easy-coding-standard": "^9.0.14",
|
||||
"symplify/easy-testing": "^9.0.14",
|
||||
"symplify/phpstan-extensions": "^9.0.14",
|
||||
"symplify/phpstan-rules": "^9.0.14",
|
||||
|
@ -50,8 +50,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
__DIR__ . '/../src/ValueObject',
|
||||
__DIR__ . '/../src/Bootstrap',
|
||||
__DIR__ . '/../src/PhpParser/Node/CustomNode',
|
||||
// loaded for PHPStan factory
|
||||
__DIR__ . '/../src/PHPStan/Type',
|
||||
]);
|
||||
|
||||
$services->alias(SymfonyApplication::class, ConsoleApplication::class);
|
||||
|
@ -30,9 +30,9 @@ use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Exception\NotImplementedException;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
/**
|
||||
* @see \Rector\BetterPhpDocParser\Tests\PhpDocInfo\PhpDocInfo\PhpDocInfoTest
|
||||
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\AnnotationReader\NodeAnnotationReader;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\AnnotationContentResolver;
|
||||
use Rector\BetterPhpDocParser\ValueObject\AroundSpaces;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Rector\TypeDeclaration\PHPStan\Type\ObjectTypeSpecifier;
|
||||
|
||||
abstract class AbstractPhpDocNodeFactory
|
||||
|
@ -35,8 +35,8 @@ use Rector\NodeCollector\ValueObject\ArrayCallable;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
/**
|
||||
* @rector-doc
|
||||
|
@ -7,6 +7,7 @@ use PHPStan\Analyser\NodeScopeResolver;
|
||||
use PHPStan\Analyser\ScopeFactory;
|
||||
use PHPStan\PhpDoc\TypeNodeResolver;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\FileSystem\FilesFinder;
|
||||
use Rector\Core\Php\TypeAnalyzer;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
@ -16,6 +17,10 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
||||
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
|
||||
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-rector.neon');
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->defaults()
|
||||
@ -27,11 +32,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
->exclude([__DIR__ . '/../src/Contract', __DIR__ . '/../src/PHPStan/TypeExtension']);
|
||||
|
||||
$services->set(TypeAnalyzer::class);
|
||||
|
||||
$services->set(FilesFinder::class);
|
||||
|
||||
$services->set(BetterStandardPrinter::class);
|
||||
|
||||
$services->set(BetterNodeFinder::class);
|
||||
|
||||
$services->set(ReflectionProvider::class)
|
||||
|
@ -1,12 +0,0 @@
|
||||
services:
|
||||
-
|
||||
class: Rector\NodeTypeResolver\PHPStan\TypeExtension\StaticContainerGetDynamicMethodReturnTypeExtension
|
||||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
|
||||
|
||||
-
|
||||
class: Rector\NodeTypeResolver\PHPStan\TypeExtension\KernelGetContainerAfterBootReturnTypeExtension
|
||||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
|
||||
|
||||
-
|
||||
class: Rector\Core\PHPStan\Type\ComponentModelDynamicReturnTypeExtension
|
||||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\DependencyInjection;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PHPStan\Analyser\NodeScopeResolver;
|
||||
use PHPStan\Analyser\ScopeFactory;
|
||||
use PHPStan\Analyser\TypeSpecifier;
|
||||
@ -16,7 +15,8 @@ use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProv
|
||||
use PHPStan\File\FileHelper;
|
||||
use PHPStan\PhpDoc\TypeNodeResolver;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
|
||||
/**
|
||||
* Factory so Symfony app can use services from PHPStan container
|
||||
@ -24,63 +24,28 @@ use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
*/
|
||||
final class PHPStanServicesFactory
|
||||
{
|
||||
/**
|
||||
* @see https://regex101.com/r/CWADBe/2
|
||||
* @var string
|
||||
*/
|
||||
private const BLEEDING_EDGE_REGEX = '#\n\s+-(.*?)bleedingEdge\.neon[\'|"]?#';
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
private $container;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(ParameterProvider $parameterProvider)
|
||||
{
|
||||
$currentWorkingDirectory = getcwd();
|
||||
$smartFileSystem = new SmartFileSystem();
|
||||
$containerFactory = new ContainerFactory(getcwd());
|
||||
|
||||
$containerFactory = new ContainerFactory($currentWorkingDirectory);
|
||||
$additionalConfigFiles = [];
|
||||
|
||||
// possible path collision for Docker
|
||||
$additionalConfigFiles = $this->appendPhpstanPHPUnitExtensionIfExists(
|
||||
$currentWorkingDirectory,
|
||||
$additionalConfigFiles
|
||||
);
|
||||
|
||||
$temporaryPHPStanNeon = null;
|
||||
|
||||
$currentProjectConfigFile = $currentWorkingDirectory . '/phpstan.neon';
|
||||
|
||||
if (file_exists($currentProjectConfigFile)) {
|
||||
$phpstanNeonContent = $smartFileSystem->readFile($currentProjectConfigFile);
|
||||
|
||||
// bleeding edge clean out, see https://github.com/rectorphp/rector/issues/2431
|
||||
if (Strings::match($phpstanNeonContent, self::BLEEDING_EDGE_REGEX)) {
|
||||
// Note: We need a unique file per process if rector runs in parallel
|
||||
$pid = getmypid();
|
||||
$temporaryPHPStanNeon = $currentWorkingDirectory . '/rector-temp-phpstan' . $pid . '.neon';
|
||||
$clearedPhpstanNeonContent = Strings::replace($phpstanNeonContent, self::BLEEDING_EDGE_REGEX, '');
|
||||
$smartFileSystem->dumpFile($temporaryPHPStanNeon, $clearedPhpstanNeonContent);
|
||||
|
||||
$additionalConfigFiles[] = $temporaryPHPStanNeon;
|
||||
} else {
|
||||
$additionalConfigFiles[] = $currentProjectConfigFile;
|
||||
}
|
||||
}
|
||||
|
||||
$additionalConfigFiles[] = __DIR__ . '/../../config/phpstan/type-extensions.neon';
|
||||
$additionalConfigFiles[] = $parameterProvider->provideStringParameter(Option::PHPSTAN_FOR_RECTOR_PATH);
|
||||
$additionalConfigFiles[] = getcwd() . '/vendor/phpstan/phpstan-phpunit/extension.neon';
|
||||
|
||||
// enable type inferring from constructor
|
||||
$additionalConfigFiles[] = __DIR__ . '/../../config/phpstan/better-infer.neon';
|
||||
|
||||
$this->container = $containerFactory->create(sys_get_temp_dir(), $additionalConfigFiles, []);
|
||||
// symplify phpstan extensions
|
||||
$additionalConfigFiles[] = getcwd() . '/vendor/symplify/phpstan-extensions/config/config.neon';
|
||||
|
||||
// clear bleeding edge fallback
|
||||
if ($temporaryPHPStanNeon !== null) {
|
||||
$smartFileSystem->remove($temporaryPHPStanNeon);
|
||||
}
|
||||
$existingAdditionalConfigFiles = array_filter($additionalConfigFiles, 'file_exists');
|
||||
$this->container = $containerFactory->create(sys_get_temp_dir(), $existingAdditionalConfigFiles, []);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,19 +119,4 @@ final class PHPStanServicesFactory
|
||||
{
|
||||
return $this->container->getByType(TypeNodeResolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $additionalConfigFiles
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function appendPhpstanPHPUnitExtensionIfExists(
|
||||
string $currentWorkingDirectory,
|
||||
array $additionalConfigFiles
|
||||
): array {
|
||||
$phpstanPhpunitExtensionConfig = $currentWorkingDirectory . '/vendor/phpstan/phpstan-phpunit/extension.neon';
|
||||
if (file_exists($phpstanPhpunitExtensionConfig) && class_exists('PHPUnit\\Framework\\TestCase')) {
|
||||
$additionalConfigFiles[] = $phpstanPhpunitExtensionConfig;
|
||||
}
|
||||
return $additionalConfigFiles;
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeCorrector\ParentClassLikeTypeCorrector;
|
||||
use Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\TypeDeclaration\PHPStan\Type\ObjectTypeSpecifier;
|
||||
|
||||
final class NodeTypeResolver
|
||||
|
@ -18,9 +18,9 @@ use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use PHPStan\Type\VerbosityLevel;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class TypeFactory
|
||||
{
|
||||
|
@ -13,9 +13,9 @@ use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Rector\TypeDeclaration\TypeNormalizer;
|
||||
|
||||
final class TypeComparator
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\PHPStan\TypeExtension;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Type\DynamicMethodReturnTypeExtension;
|
||||
use PHPStan\Type\ErrorType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
final class KernelGetContainerAfterBootReturnTypeExtension implements DynamicMethodReturnTypeExtension
|
||||
{
|
||||
public function getClass(): string
|
||||
{
|
||||
return Kernel::class;
|
||||
}
|
||||
|
||||
public function isMethodSupported(MethodReflection $methodReflection): bool
|
||||
{
|
||||
return $methodReflection->getName() === 'getContainer';
|
||||
}
|
||||
|
||||
public function getTypeFromMethodCall(
|
||||
MethodReflection $methodReflection,
|
||||
MethodCall $methodCall,
|
||||
Scope $scope
|
||||
): Type {
|
||||
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
|
||||
|
||||
if (! $this->isCalledAfterBoot($scope, $methodCall)) {
|
||||
return $returnType;
|
||||
}
|
||||
|
||||
if ($returnType instanceof UnionType) {
|
||||
foreach ($returnType->getTypes() as $singleType) {
|
||||
if ($singleType instanceof ObjectType) {
|
||||
return $singleType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $returnType;
|
||||
}
|
||||
|
||||
private function isCalledAfterBoot(Scope $scope, MethodCall $methodCall): bool
|
||||
{
|
||||
$kernelBootMethodCall = new MethodCall($methodCall->var, 'boot');
|
||||
|
||||
return ! $scope->getType($kernelBootMethodCall) instanceof ErrorType;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\NodeTypeResolver\PHPStan\TypeExtension;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Type\Constant\ConstantStringType;
|
||||
use PHPStan\Type\DynamicMethodReturnTypeExtension;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
final class StaticContainerGetDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
|
||||
{
|
||||
public function getClass(): string
|
||||
{
|
||||
return ContainerInterface::class;
|
||||
}
|
||||
|
||||
public function isMethodSupported(MethodReflection $methodReflection): bool
|
||||
{
|
||||
return $methodReflection->getName() === 'get';
|
||||
}
|
||||
|
||||
public function getTypeFromMethodCall(
|
||||
MethodReflection $methodReflection,
|
||||
MethodCall $methodCall,
|
||||
Scope $scope
|
||||
): Type {
|
||||
$value = $methodCall->args[0]->value;
|
||||
$valueType = $scope->getType($value);
|
||||
|
||||
// we don't know what it is
|
||||
if ($valueType instanceof MixedType) {
|
||||
return $valueType;
|
||||
}
|
||||
|
||||
if ($valueType instanceof ConstantStringType) {
|
||||
return new ObjectType($valueType->getValue());
|
||||
}
|
||||
|
||||
// unknown, probably variable
|
||||
return new MixedType();
|
||||
}
|
||||
}
|
@ -12,9 +12,9 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class TypeHasher
|
||||
{
|
||||
|
@ -10,8 +10,8 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
|
||||
|
||||
final class DocBlockClassRenamer
|
||||
|
@ -10,9 +10,9 @@ use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
use Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResol
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResolver\Source\ClassWithTrait;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResolver\Source\ParentClass;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResolver\Source\SomeInterface;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
/**
|
||||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\ClassAndInterfaceTypeResolver
|
||||
|
@ -10,7 +10,7 @@ use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTest;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResolver\Source\SomeInterfaceWithParentInterface;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\ClassAndInterfaceTypeResolver\Source\SomeParentInterface;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
/**
|
||||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\ClassAndInterfaceTypeResolver
|
||||
|
@ -14,7 +14,7 @@ use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTe
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\ClassThatExtendsHtml;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\Html;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\SomeChild;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
/**
|
||||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\PropertyTypeResolver
|
||||
|
@ -10,7 +10,7 @@ use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTest;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\TraitTypeResolver\Source\AnotherTrait;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\TraitTypeResolver\Source\TraitWithTrait;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
/**
|
||||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\TraitTypeResolver
|
||||
|
@ -12,7 +12,7 @@ use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTe
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\VariableTypeResolver\Source\AnotherType;
|
||||
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\VariableTypeResolver\Source\ThisClass;
|
||||
use Rector\NodeTypeResolver\Tests\Source\AnotherClass;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
/**
|
||||
* @see \Rector\NodeTypeResolver\NodeTypeResolver\VariableTypeResolver
|
||||
|
@ -16,13 +16,13 @@ use PHPStan\Type\VerbosityLevel;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\PHPStanStaticTypeMapperAwareInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class ObjectTypeMapper implements TypeMapperInterface, PHPStanStaticTypeMapperAwareInterface
|
||||
{
|
||||
|
@ -10,8 +10,8 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VerbosityLevel;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
||||
use Rector\PHPStan\Type\ParentStaticType;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
|
||||
|
||||
final class ParentStaticTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
|
@ -10,8 +10,8 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VerbosityLevel;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
|
||||
final class SelfObjectTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
|
||||
final class TypeUnwrapper
|
||||
{
|
||||
|
@ -8,9 +8,9 @@ use PhpParser\Node;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Contract\Collector\NodeCollectorInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class UseNodesToAddCollector implements NodeCollectorInterface
|
||||
|
@ -17,13 +17,13 @@ use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\NodeRemoval\NodeRemover;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\NodesToAddCollector;
|
||||
use Rector\PostRector\Collector\NodesToRemoveCollector;
|
||||
use Rector\PostRector\Collector\NodesToReplaceCollector;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* This could be part of @see AbstractRector, but decopuling to trait
|
||||
|
@ -14,8 +14,8 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
@ -12,5 +12,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
->autowire()
|
||||
->autoconfigure();
|
||||
|
||||
$services->load('Rector\StaticTypeMapper\\', __DIR__ . '/../src');
|
||||
$services->load('Rector\StaticTypeMapper\\', __DIR__ . '/../src')
|
||||
->exclude([__DIR__ . '/../src/ValueObject']);
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\StaticTypeMapper\PHPStan;
|
||||
namespace Rector\StaticTypeMapper\Naming;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Use_;
|
@ -16,10 +16,10 @@ use PHPStan\Type\StaticType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\ParentStaticType;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
use Rector\TypeDeclaration\PHPStan\Type\ObjectTypeSpecifier;
|
||||
|
||||
final class IdentifierTypeMapper implements PhpDocTypeMapperInterface
|
||||
|
@ -9,9 +9,9 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class FullyQualifiedNodeMapper implements PhpParserNodeMapperInterface
|
||||
{
|
||||
|
@ -11,9 +11,9 @@ use PHPStan\Type\StaticType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PSR4\Collector\RenamedClassesCollector;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class NameNodeMapper implements PhpParserNodeMapperInterface
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ use PHPStan\Type\Type;
|
||||
use Rector\Core\Exception\NotImplementedException;
|
||||
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
|
||||
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
||||
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
|
||||
use Rector\StaticTypeMapper\PHPStan\NameScopeFactory;
|
||||
|
||||
/**
|
||||
* Maps PhpParser <=> PHPStan <=> PHPStan doc <=> string type nodes between all possible formats
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan;
|
||||
namespace Rector\StaticTypeMapper\TypeFactory;
|
||||
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan\Type;
|
||||
namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Use_;
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan\Type;
|
||||
namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node\Name;
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan\Type;
|
||||
namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
|
||||
use PHPStan\Type\StaticType;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan\Type;
|
||||
namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
|
||||
use PHPStan\Type\ObjectType;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStan\Type;
|
||||
namespace Rector\StaticTypeMapper\ValueObject\Type;
|
||||
|
||||
use PHPStan\Type\ObjectType;
|
||||
|
@ -12,8 +12,8 @@ use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use Rector\Core\HttpKernel\RectorKernel;
|
||||
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
||||
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
|
||||
use Rector\StaticTypeMapper\PHPStan\NameScopeFactory;
|
||||
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
|
||||
|
||||
final class PhpDocTypeMapperTest extends AbstractKernelTestCase
|
||||
|
4
phpstan-for-rector.neon
Normal file
4
phpstan-for-rector.neon
Normal file
@ -0,0 +1,4 @@
|
||||
# this config has extensions, that helps PHPStan inside Rector to resolve more precise types
|
||||
includes:
|
||||
- utils/phpstan-extensions/config/phpstan-extensions.neon
|
||||
- vendor/phpstan/phpstan-nette/extension.neon
|
@ -1,5 +1,7 @@
|
||||
includes:
|
||||
- utils/phpstan-extensions/config/phpstan-extensions.neon
|
||||
- utils/phpstan-extensions/config/rector-rules.neon
|
||||
|
||||
# allows symplify error formatter
|
||||
- vendor/symplify/phpstan-extensions/config/config.neon
|
||||
|
||||
@ -395,8 +397,6 @@ parameters:
|
||||
- packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfo.php # 108
|
||||
- rules/coding-style/src/Rector/ClassMethod/YieldClassMethodToArrayClassMethodRector.php # 47
|
||||
- rules/php70/src/EregToPcreTransformer.php # 66
|
||||
- rules/phpstan/src/Type/AliasedObjectType.php # 24
|
||||
- rules/phpstan/src/Type/ShortenedObjectType.php # 18
|
||||
- rules/restoration/src/Rector/Class_/RemoveUselessJustForSakeInterfaceRector.php # 42
|
||||
- rules/type-declaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php # 82
|
||||
- src/PhpParser/Builder/UseBuilder.php # 17
|
||||
|
@ -29,6 +29,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see https://www.reddit.com/r/PHP/comments/aqk01p/is_there_a_situation_in_which_if_countarray_0/
|
||||
* @see https://3v4l.org/UCd1b
|
||||
*
|
||||
* @see \Rector\CodeQuality\Tests\Rector\If_\ExplicitBoolCompareRector\ExplicitBoolCompareRectorTest
|
||||
*/
|
||||
final class ExplicitBoolCompareRector extends AbstractRector
|
||||
|
@ -12,8 +12,8 @@ use PhpParser\Node\Stmt\Nop;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\CodingStyle\ClassNameImport\UsedImportsResolver;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class UseImportsAdder
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use Rector\CodingStyle\ClassNameImport\AliasUsesResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* Prevents adding:
|
||||
|
@ -7,7 +7,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
||||
use PhpParser\Node;
|
||||
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* Prevents adding:
|
||||
|
@ -7,7 +7,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
||||
use PhpParser\Node;
|
||||
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* Prevents adding:
|
||||
|
@ -6,8 +6,8 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* This prevents importing:
|
||||
|
@ -10,7 +10,7 @@ use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class ClassNameImportSkipper
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ use PhpParser\Node\Stmt\UseUse;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class UsedImportsResolver
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace Rector\CodingStyle\Contract\ClassNameImport;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
interface ClassNameImportSkipVoterInterface
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\PhpParser\NodeTraverser\CallableNodeTraverser;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
|
||||
final class DocAliasResolver
|
||||
{
|
||||
|
@ -16,10 +16,10 @@ use Rector\Core\Configuration\Option;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\PSR4\Collector\RenamedClassesCollector;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
|
||||
final class NameImporter
|
||||
|
@ -11,7 +11,7 @@ use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class ThrowAnalyzer
|
||||
{
|
||||
|
@ -7,8 +7,8 @@ namespace Rector\Defluent\NodeAnalyzer;
|
||||
use PhpParser\Node\Expr;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
|
||||
final class ExprStringTypeResolver
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ use Rector\NetteKdyby\Naming\VariableNaming;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
/**
|
||||
* @see \Rector\Defluent\Tests\NodeFactory\FluentChainMethodCallRootExtractor\FluentChainMethodCallRootExtractorTest
|
||||
|
@ -9,7 +9,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\Exception\NotImplementedYetException;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class PropertyTypeManipulator
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class CollectionTypeFactory
|
||||
{
|
||||
|
@ -14,8 +14,8 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToManyTagValueNode;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\PHPStan\NameScopeFactory;
|
||||
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class CollectionTypeResolver
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -13,7 +13,7 @@ use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\Generate
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\JMS\SerializerTypeTagValueNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -9,7 +9,7 @@ use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PHPStan\Type\Generic\GenericObjectType;
|
||||
use Rector\Core\Exception\NotImplementedYetException;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class RepositoryTypeFactory
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Generic\NodeTypeAnalyzer\TypeProvidingExprFromClassResolver;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
abstract class AbstractToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
|
@ -23,8 +23,8 @@ use PHPStan\Type\Type;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class ExpectedNameResolver
|
||||
{
|
||||
|
@ -18,9 +18,9 @@ use Rector\Naming\ValueObject\ExpectedName;
|
||||
use Rector\NetteKdyby\Naming\VariableNaming;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
|
@ -15,7 +15,7 @@ use Rector\NetteCodeQuality\NodeResolver\MethodNamesByInputNamesResolver;
|
||||
use Rector\NodeCollector\NodeCollector\NodeRepository;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class GetComponentMethodCallFormControlTypeResolver implements FormControlTypeResolverInterface, MethodNamesByInputNamesResolverAwareInterface
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Rector\CodingStyle\Naming\ClassNaming;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NetteKdyby\DataProvider\EventAndListenerTreeProvider;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
@ -6,7 +6,7 @@ namespace Rector\NetteToSymfony\Analyzer;
|
||||
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
|
||||
final class NetteControlFactoryInterfaceAnalyzer
|
||||
|
@ -20,7 +20,7 @@ use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Nette\NodeFactory\ActionRenderFactory;
|
||||
use Rector\Nette\TemplatePropertyAssignCollector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
@ -8,8 +8,8 @@ use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\SymfonyRouteTagValueNode;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class ExplicitRouteAnnotationDecorator
|
||||
{
|
||||
|
@ -15,8 +15,8 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\RemovingStatic\StaticTypesInClassResolver;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -13,11 +13,11 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\RemovingStatic\Printer\FactoryClassPrinter;
|
||||
use Rector\RemovingStatic\StaticTypesInClassResolver;
|
||||
use Rector\RemovingStatic\UniqueObjectFactoryFactory;
|
||||
use Rector\RemovingStatic\UniqueObjectOrServiceDetector;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -10,7 +10,7 @@ use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\PhpParser\NodeTraverser\CallableNodeTraverser;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class StaticTypesInClassResolver
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
|
||||
final class ClassRenamer
|
||||
{
|
||||
|
@ -20,8 +20,8 @@ use PHPStan\Type\UnionType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\PropertyNaming;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall;
|
||||
use Rector\Transform\ValueObject\ArrayFuncCallToMethodCall;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
|
@ -12,8 +12,8 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\StaticType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
|
||||
abstract class AbstractChildPopulator
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class ClassMethodReturnTypeOverrideGuard
|
||||
{
|
||||
|
@ -13,9 +13,9 @@ use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class ObjectTypeSpecifier
|
||||
{
|
||||
|
@ -26,10 +26,10 @@ use PHPStan\Type\UnionType;
|
||||
use PHPStan\Type\VoidType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\PHPStan\Type\ParentStaticType;
|
||||
use Rector\PHPStan\Type\SelfObjectType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
|
||||
final class NonInformativeReturnTagRemover
|
||||
{
|
||||
|
@ -13,8 +13,8 @@ use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use Rector\TypeDeclaration\ChildPopulator\ChildParamPopulator;
|
||||
use Rector\TypeDeclaration\TypeInferer\ParamTypeInferer;
|
||||
use Rector\TypeDeclaration\ValueObject\NewType;
|
||||
|
@ -22,8 +22,8 @@ use PHPStan\Type\Type;
|
||||
use Rector\Core\PhpParser\Node\Manipulator\ClassMethodPropertyFetchManipulator;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPStan\Type\AliasedObjectType;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\TypeDeclaration\Contract\TypeInferer\PropertyTypeInfererInterface;
|
||||
use Rector\TypeDeclaration\TypeInferer\AbstractTypeInferer;
|
||||
|
||||
|
@ -16,7 +16,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\PHPStan\Type\FullyQualifiedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\TypeDeclaration\Contract\TypeInferer\PropertyTypeInfererInterface;
|
||||
|
||||
final class DoctrineRelationPropertyTypeInferer implements PropertyTypeInfererInterface
|
||||
|
@ -15,7 +15,7 @@ use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\NodeTypeResolver\PHPStan\TypeHasher;
|
||||
use Rector\PHPStan\TypeFactoryStaticHelper;
|
||||
use Rector\StaticTypeMapper\TypeFactory\TypeFactoryStaticHelper;
|
||||
use Rector\TypeDeclaration\ValueObject\NestedArrayType;
|
||||
|
||||
/**
|
||||
|
@ -142,4 +142,9 @@ final class Option
|
||||
* @var string
|
||||
*/
|
||||
public const FIX = 'fix';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PHPSTAN_FOR_RECTOR_PATH = 'phpstan_for_rector_path';
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use PHPStan\Type\IntersectionType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\PHPStan\Type\ShortenedObjectType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
use ReflectionMethod;
|
||||
|
||||
final class ClassMethodReflectionFactory
|
||||
|
@ -1,6 +1,3 @@
|
||||
includes:
|
||||
- rector-rules.neon
|
||||
|
||||
services:
|
||||
- Rector\PHPStanExtensions\Utils\PHPStanValueResolver
|
||||
|
||||
|
@ -8,5 +8,16 @@ services:
|
||||
tags: [phpstan.rules.rule]
|
||||
|
||||
-
|
||||
class: Rector\PHPStanExtensions\Rule\ConfigurableRectorRule
|
||||
class: Symplify\PHPStanRules\Rules\IfNewTypeThenImplementInterfaceRule
|
||||
tags: [phpstan.rules.rule]
|
||||
arguments:
|
||||
interfacesByNewTypes:
|
||||
Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample: Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
|
||||
# open in Sypmlify 9.0.20 version
|
||||
# -
|
||||
# class: Symplify\PHPStanRules\Rules\IfImplementsInterfaceThenNewTypeRule
|
||||
# tags: [phpstan.rules.rule]
|
||||
# arguments:
|
||||
# interfacesByNewTypes:
|
||||
# Rector\Core\Contract\Rector\ConfigurableRectorInterface: Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\PHPStan\Type;
|
||||
namespace Rector\PHPStanExtensions\ReturnTypeExtension;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PHPStan\Analyser\Scope;
|
@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Rule;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\NodeFinder;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Rules\Rule;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Symplify\PHPStanRules\Naming\SimpleNameResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
|
||||
/**
|
||||
* @see \Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\ConfigurableRectorRuleTest
|
||||
*/
|
||||
final class ConfigurableRectorRule implements Rule
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const ERROR_NO_CONFIGURED_CODE_SAMPLE = 'Configurable rules must have configure code sample';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const ERROR_NOT_IMPLEMENTS_INTERFACE = 'Configurable code sample is used but "%s" interface is not implemented';
|
||||
|
||||
/**
|
||||
* @var SimpleNameResolver
|
||||
*/
|
||||
private $simpleNameResolver;
|
||||
|
||||
public function __construct(SimpleNameResolver $simpleNameResolver)
|
||||
{
|
||||
$this->simpleNameResolver = $simpleNameResolver;
|
||||
}
|
||||
|
||||
public function getNodeType(): string
|
||||
{
|
||||
return Class_::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
* @return string[]
|
||||
*/
|
||||
public function processNode(Node $node, Scope $scope): array
|
||||
{
|
||||
$className = $this->simpleNameResolver->getName($node);
|
||||
if ($className === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_a($className, RectorInterface::class, true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($node->isAbstract()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->hasConfigurableInterface($className)) {
|
||||
if ($this->hasConfiguredCodeSample($node)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [self::ERROR_NO_CONFIGURED_CODE_SAMPLE];
|
||||
}
|
||||
|
||||
if ($this->hasConfiguredCodeSample($node)) {
|
||||
if ($this->hasConfigurableInterface($className)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$errorMessage = sprintf(self::ERROR_NOT_IMPLEMENTS_INTERFACE, ConfigurableRectorInterface::class);
|
||||
return [$errorMessage];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function hasConfiguredCodeSample(Class_ $class): bool
|
||||
{
|
||||
$classMethod = $class->getMethod('getRuleDefinition');
|
||||
|
||||
if ($classMethod === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($classMethod->stmts === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nodeFinder = new NodeFinder();
|
||||
$nodes = $nodeFinder->find($classMethod->stmts, function (Node $node): ?New_ {
|
||||
if (! $node instanceof New_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$className = $node->class;
|
||||
if (! $className instanceof Name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_a($className->toString(), ConfiguredCodeSample::class, true)) {
|
||||
return $node;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return $nodes !== [];
|
||||
}
|
||||
|
||||
private function hasConfigurableInterface(string $className): bool
|
||||
{
|
||||
return is_a($className, ConfigurableRectorInterface::class, true);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule;
|
||||
|
||||
use Iterator;
|
||||
use PHPStan\Rules\Rule;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\PHPStanExtensions\Rule\ConfigurableRectorRule;
|
||||
use Symplify\PHPStanExtensions\Testing\AbstractServiceAwareRuleTestCase;
|
||||
|
||||
final class ConfigurableRectorRuleTest extends AbstractServiceAwareRuleTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
* @param array<string|string[]|int[]> $expectedErrorsWithLines
|
||||
*/
|
||||
public function testRule(string $filePath, array $expectedErrorsWithLines): void
|
||||
{
|
||||
$this->analyse([$filePath], $expectedErrorsWithLines);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Fixture/ImplementsAndHasConfiguredCodeSampleRector.php', []];
|
||||
|
||||
yield [
|
||||
__DIR__ . '/Fixture/ImplementsAndHasNoConfiguredCodeSampleRector.php',
|
||||
[[ConfigurableRectorRule::ERROR_NO_CONFIGURED_CODE_SAMPLE, 14]],
|
||||
];
|
||||
|
||||
$notImplementErrorMessage = sprintf(
|
||||
ConfigurableRectorRule::ERROR_NOT_IMPLEMENTS_INTERFACE,
|
||||
ConfigurableRectorInterface::class
|
||||
);
|
||||
|
||||
yield [
|
||||
__DIR__ . '/Fixture/NotImplementsAndHasConfiguredCodeSampleRector.php',
|
||||
[[$notImplementErrorMessage, 12]],
|
||||
];
|
||||
|
||||
yield [__DIR__ . '/Fixture/NotImplementsAndHasNoConfiguredCodeSampleRector.php', []];
|
||||
yield [__DIR__ . '/Fixture/ImplementsThroughAbstractClassRector.php', []];
|
||||
yield [__DIR__ . '/Fixture/SkipClassNamesWithoutRectorSuffix.php', []];
|
||||
yield [__DIR__ . '/Fixture/SkipAbstractRector.php', []];
|
||||
}
|
||||
|
||||
protected function getRule(): Rule
|
||||
{
|
||||
return $this->getRuleFromConfig(ConfigurableRectorRule::class, __DIR__ . '/config/configured_rule.neon');
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Fixture;
|
||||
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
|
||||
final class ImplementsAndHasConfiguredCodeSampleRector implements ConfigurableRectorInterface, RectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const STATIC_CALLS_TO_FUNCTIONS = 'static_calls_to_functions';
|
||||
|
||||
public function configure(array $configuration): void
|
||||
{
|
||||
// TODO: Implement configure() method.
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns static call to function call.', [
|
||||
new ConfiguredCodeSample(
|
||||
'OldClass::oldMethod("args");',
|
||||
'new_function("args");',
|
||||
[
|
||||
self::STATIC_CALLS_TO_FUNCTIONS => [
|
||||
new StaticCallToFuncCall('OldClass', 'oldMethod', 'new_function'),
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Fixture;
|
||||
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
|
||||
final class ImplementsAndHasNoConfiguredCodeSampleRector implements ConfigurableRectorInterface, RectorInterface
|
||||
{
|
||||
public function configure(array $configuration): void
|
||||
{
|
||||
// TODO: Implement configure() method.
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns static call to function call.', [
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(
|
||||
'OldClass::oldMethod("args");',
|
||||
'new_function("args");'
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Fixture;
|
||||
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Source\AbstractClassImplementsConfigurableInterface;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
|
||||
class ImplementsThroughAbstractClassRector extends AbstractClassImplementsConfigurableInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const STATIC_CALLS_TO_FUNCTIONS = 'static_calls_to_functions';
|
||||
|
||||
public function configure(array $configuration): void
|
||||
{
|
||||
// TODO: Implement configure() method.
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns static call to function call.', [
|
||||
new ConfiguredCodeSample(
|
||||
'OldClass::oldMethod("args");',
|
||||
'new_function("args");',
|
||||
[
|
||||
self::STATIC_CALLS_TO_FUNCTIONS => [
|
||||
new StaticCallToFuncCall('OldClass', 'oldMethod', 'new_function'),
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Fixture;
|
||||
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
|
||||
final class NotImplementsAndHasConfiguredCodeSampleRector implements RectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const STATIC_CALLS_TO_FUNCTIONS = 'static_calls_to_functions';
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns static call to function call.', [
|
||||
new ConfiguredCodeSample(
|
||||
'OldClass::oldMethod("args");',
|
||||
'new_function("args");',
|
||||
[
|
||||
self::STATIC_CALLS_TO_FUNCTIONS => [
|
||||
new StaticCallToFuncCall('OldClass', 'oldMethod', 'new_function'),
|
||||
],
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanExtensions\Tests\Rule\ConfigurableRectorRule\Fixture;
|
||||
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use Rector\Transform\ValueObject\StaticCallToFuncCall;
|
||||
|
||||
final class NotImplementsAndHasNoConfiguredCodeSampleRector
|
||||
{
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Turns static call to function call.', [
|
||||
new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(
|
||||
'OldClass::oldMethod("args");',
|
||||
'new_function("args");'
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user