Updated Rector to commit 8027c7fd8c

8027c7fd8c [DX] Remove MoveInterfacesToContractNamespaceDirectoryRector as breaky, use PHPStan rule instead (#1835)
This commit is contained in:
Tomas Votruba 2022-02-18 10:00:13 +00:00
parent 2493da671a
commit 22a76df7b3
9 changed files with 160 additions and 564 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Autodiscovery\NodeAnalyzer;
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
final class NetteComponentFactoryInterfaceAnalyzer
{
/**
* @readonly
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
*/
private $returnTypeInferer;
public function __construct(\Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer $returnTypeInferer)
{
$this->returnTypeInferer = $returnTypeInferer;
}
/**
* @see https://doc.nette.org/en/3.0/components#toc-components-with-dependencies
*/
public function isComponentFactoryInterface(\PhpParser\Node\Stmt\Interface_ $interface) : bool
{
foreach ($interface->getMethods() as $classMethod) {
$returnType = $this->returnTypeInferer->inferFunctionLike($classMethod);
if (!$returnType instanceof \PHPStan\Type\TypeWithClassName) {
return \false;
}
$controlOrForm = new \PHPStan\Type\UnionType([new \PHPStan\Type\ObjectType('Nette\\Application\\UI\\Control'), new \PHPStan\Type\ObjectType('Nette\\Application\\UI\\Form')]);
if ($returnType instanceof \Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType) {
$returnType = new \PHPStan\Type\ObjectType($returnType->getFullyQualifiedName());
}
if ($controlOrForm->isSuperTypeOf($returnType)->yes()) {
return \true;
}
}
return \false;
}
}

View File

@ -1,81 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Autodiscovery\Rector\Interface_;
use PhpParser\Node;
use PhpParser\Node\Stmt\Interface_;
use Rector\Autodiscovery\NodeAnalyzer\NetteComponentFactoryInterfaceAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\FileSystemRector\ValueObject\AddedFileWithNodes;
use Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
*
* @see \Rector\Tests\Autodiscovery\Rector\Interface_\MoveInterfacesToContractNamespaceDirectoryRector\MoveInterfacesToContractNamespaceDirectoryRectorTest
*/
final class MoveInterfacesToContractNamespaceDirectoryRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @readonly
* @var \Rector\Autodiscovery\NodeAnalyzer\NetteComponentFactoryInterfaceAnalyzer
*/
private $netteComponentFactoryInterfaceAnalyzer;
/**
* @readonly
* @var \Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory
*/
private $addedFileWithNodesFactory;
public function __construct(\Rector\Autodiscovery\NodeAnalyzer\NetteComponentFactoryInterfaceAnalyzer $netteComponentFactoryInterfaceAnalyzer, \Rector\FileSystemRector\ValueObjectFactory\AddedFileWithNodesFactory $addedFileWithNodesFactory)
{
$this->netteComponentFactoryInterfaceAnalyzer = $netteComponentFactoryInterfaceAnalyzer;
$this->addedFileWithNodesFactory = $addedFileWithNodesFactory;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Move interface to "Contract" namespace', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
// file: app/Exception/Rule.php
namespace App\Exception;
interface Rule
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
// file: app/Contract/Rule.php
namespace App\Contract;
interface Rule
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\Interface_::class];
}
/**
* @param Interface_ $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->netteComponentFactoryInterfaceAnalyzer->isComponentFactoryInterface($node)) {
return null;
}
$addedFileWithNodes = $this->addedFileWithNodesFactory->createWithDesiredGroup($this->file->getSmartFileInfo(), $this->file, 'Contract');
if (!$addedFileWithNodes instanceof \Rector\FileSystemRector\ValueObject\AddedFileWithNodes) {
return null;
}
$this->removedAndAddedFilesCollector->removeFile($this->file->getSmartFileInfo());
$this->removedAndAddedFilesCollector->addAddedFile($addedFileWithNodes);
return null;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'a4eff1e0adc5dec582adeeeff55512f6805e0f43';
public const PACKAGE_VERSION = '8027c7fd8caeefa12fc8a66ebf6d88180b634019';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-18 10:22:26';
public const RELEASE_DATE = '2022-02-18 09:54:00';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220218\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac::getLoader();
return ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a::getLoader();

View File

@ -1373,9 +1373,7 @@ return array(
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => $baseDir . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => $baseDir . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
'Rector\\Autodiscovery\\Configuration\\CategoryNamespaceProvider' => $baseDir . '/rules/Autodiscovery/Configuration/CategoryNamespaceProvider.php',
'Rector\\Autodiscovery\\NodeAnalyzer\\NetteComponentFactoryInterfaceAnalyzer' => $baseDir . '/rules/Autodiscovery/NodeAnalyzer/NetteComponentFactoryInterfaceAnalyzer.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveEntitiesToEntityDirectoryRector' => $baseDir . '/rules/Autodiscovery/Rector/Class_/MoveEntitiesToEntityDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Interface_\\MoveInterfacesToContractNamespaceDirectoryRector' => $baseDir . '/rules/Autodiscovery/Rector/Interface_/MoveInterfacesToContractNamespaceDirectoryRector.php',
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => $baseDir . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => $baseDir . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',
'Rector\\BetterPhpDocParser\\Comment\\CommentsMerger' => $baseDir . '/packages/BetterPhpDocParser/Comment/CommentsMerger.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac
class ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit453b3766006e61b34a51164510e3ae3a::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit453b3766006e61b34a51164510e3ae3a::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire3d41aaead61a4e9379fe1a73755481ac($fileIdentifier, $file);
composerRequire453b3766006e61b34a51164510e3ae3a($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac
* @param string $file
* @return void
*/
function composerRequire3d41aaead61a4e9379fe1a73755481ac($fileIdentifier, $file)
function composerRequire453b3766006e61b34a51164510e3ae3a($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac
class ComposerStaticInit453b3766006e61b34a51164510e3ae3a
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -1762,9 +1762,7 @@ class ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac
'Rector\\Arguments\\ValueObject\\ReplaceFuncCallArgumentDefaultValue' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/ReplaceFuncCallArgumentDefaultValue.php',
'Rector\\Arguments\\ValueObject\\SwapFuncCallArguments' => __DIR__ . '/../..' . '/rules/Arguments/ValueObject/SwapFuncCallArguments.php',
'Rector\\Autodiscovery\\Configuration\\CategoryNamespaceProvider' => __DIR__ . '/../..' . '/rules/Autodiscovery/Configuration/CategoryNamespaceProvider.php',
'Rector\\Autodiscovery\\NodeAnalyzer\\NetteComponentFactoryInterfaceAnalyzer' => __DIR__ . '/../..' . '/rules/Autodiscovery/NodeAnalyzer/NetteComponentFactoryInterfaceAnalyzer.php',
'Rector\\Autodiscovery\\Rector\\Class_\\MoveEntitiesToEntityDirectoryRector' => __DIR__ . '/../..' . '/rules/Autodiscovery/Rector/Class_/MoveEntitiesToEntityDirectoryRector.php',
'Rector\\Autodiscovery\\Rector\\Interface_\\MoveInterfacesToContractNamespaceDirectoryRector' => __DIR__ . '/../..' . '/rules/Autodiscovery/Rector/Interface_/MoveInterfacesToContractNamespaceDirectoryRector.php',
'Rector\\BetterPhpDocParser\\Annotation\\AnnotationNaming' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Annotation/AnnotationNaming.php',
'Rector\\BetterPhpDocParser\\Attributes\\AttributeMirrorer' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Attributes/AttributeMirrorer.php',
'Rector\\BetterPhpDocParser\\Comment\\CommentsMerger' => __DIR__ . '/../..' . '/packages/BetterPhpDocParser/Comment/CommentsMerger.php',
@ -3869,9 +3867,9 @@ class ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3d41aaead61a4e9379fe1a73755481ac::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit453b3766006e61b34a51164510e3ae3a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit453b3766006e61b34a51164510e3ae3a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit453b3766006e61b34a51164510e3ae3a::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220218\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false) && !interface_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false) && !trait_exists('ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit3d41aaead61a4e9379fe1a73755481ac');
if (!class_exists('ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a', false) && !interface_exists('ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a', false) && !trait_exists('ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a', false)) {
spl_autoload_call('RectorPrefix20220218\ComposerAutoloaderInit453b3766006e61b34a51164510e3ae3a');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220218\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220218\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire3d41aaead61a4e9379fe1a73755481ac')) {
function composerRequire3d41aaead61a4e9379fe1a73755481ac() {
return \RectorPrefix20220218\composerRequire3d41aaead61a4e9379fe1a73755481ac(...func_get_args());
if (!function_exists('composerRequire453b3766006e61b34a51164510e3ae3a')) {
function composerRequire453b3766006e61b34a51164510e3ae3a() {
return \RectorPrefix20220218\composerRequire453b3766006e61b34a51164510e3ae3a(...func_get_args());
}
}
if (!function_exists('scanPath')) {