Updated Rector to commit b8fec6418f6bab31d807fc9eef4167aa74277847

b8fec6418f cleanup
This commit is contained in:
Tomas Votruba 2022-08-07 23:37:28 +00:00
parent 24d364b692
commit ba5ca07800
20 changed files with 75 additions and 165 deletions

View File

@ -17,8 +17,8 @@ use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\NodeAnalyzer\BinaryOpAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\FuncCallAndExpr;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Nette\ValueObject\FuncCallAndExpr;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

View File

@ -8,15 +8,10 @@ use PHPStan\Reflection\ClassReflection;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\MethodName;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use RectorPrefix202208\Symplify\Astral\Naming\SimpleNameResolver;
final class ControllerRenderMethodAnalyzer
{
/**
* @readonly
* @var \Symplify\Astral\Naming\SimpleNameResolver
*/
private $simpleNameResolver;
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
@ -32,9 +27,8 @@ final class ControllerRenderMethodAnalyzer
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(SimpleNameResolver $simpleNameResolver, PhpAttributeAnalyzer $phpAttributeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver)
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver)
{
$this->simpleNameResolver = $simpleNameResolver;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->reflectionResolver = $reflectionResolver;
@ -59,7 +53,13 @@ final class ControllerRenderMethodAnalyzer
if (!$classMethod->isPublic()) {
return \false;
}
return $this->simpleNameResolver->isNames($classMethod->name, ['render*', 'handle*', 'action*']);
$classMethodName = $classMethod->name->toString();
foreach (['render', 'handle', 'action'] as $methodPrefix) {
if (\strncmp($classMethodName, $methodPrefix, \strlen($methodPrefix)) === 0) {
return \true;
}
}
return \false;
}
private function isSymfonyRenderMethod(ClassReflection $classReflection, ClassMethod $classMethod) : bool
{
@ -69,7 +69,11 @@ final class ControllerRenderMethodAnalyzer
if (!$classMethod->isPublic()) {
return \false;
}
if ($this->simpleNameResolver->isNames($classMethod->name, ['__invoke', '*action'])) {
$classMethodName = $classMethod->name->toString();
if ($classMethodName === MethodName::INVOKE) {
return \true;
}
if (\substr_compare($classMethodName, 'action', -\strlen('action')) === 0) {
return \true;
}
if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, 'Symfony\\Component\\Routing\\Annotation\\Route')) {

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'cbe6271e16370118408bdea5fe6b8ea6eebe8f18';
public const PACKAGE_VERSION = 'b8fec6418f6bab31d807fc9eef4167aa74277847';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-08-07 16:33:35';
public const RELEASE_DATE = '2022-08-08 01:32:10';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad::getLoader();
return ComposerAutoloaderInit88e5a2405ced7239cbcada0a44df6c5c::getLoader();

View File

@ -1020,7 +1020,6 @@ return array(
'RectorPrefix202208\\Symplify\\Astral\\Contract\\NodeValueResolver\\NodeValueResolverInterface' => $vendorDir . '/symplify/astral/src/Contract/NodeValueResolver/NodeValueResolverInterface.php',
'RectorPrefix202208\\Symplify\\Astral\\Exception\\ShouldNotHappenException' => $vendorDir . '/symplify/astral/src/Exception/ShouldNotHappenException.php',
'RectorPrefix202208\\Symplify\\Astral\\Naming\\SimpleNameResolver' => $vendorDir . '/symplify/astral/src/Naming/SimpleNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeAnalyzer\\NetteTypeAnalyzer' => $vendorDir . '/symplify/astral/src/NodeAnalyzer/NetteTypeAnalyzer.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\ArgNodeNameResolver' => $vendorDir . '/symplify/astral/src/NodeNameResolver/ArgNodeNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\AttributeNodeNameResolver' => $vendorDir . '/symplify/astral/src/NodeNameResolver/AttributeNodeNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\ClassLikeNodeNameResolver' => $vendorDir . '/symplify/astral/src/NodeNameResolver/ClassLikeNodeNameResolver.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad
class ComposerAutoloaderInit88e5a2405ced7239cbcada0a44df6c5c
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit88e5a2405ced7239cbcada0a44df6c5c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit88e5a2405ced7239cbcada0a44df6c5c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire0d29dc308111287df9dcca8f6a3cdaad($fileIdentifier, $file);
composerRequire88e5a2405ced7239cbcada0a44df6c5c($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit0d29dc308111287df9dcca8f6a3cdaad
* @param string $file
* @return void
*/
function composerRequire0d29dc308111287df9dcca8f6a3cdaad($fileIdentifier, $file)
function composerRequire88e5a2405ced7239cbcada0a44df6c5c($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 ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad
class ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -1326,7 +1326,6 @@ class ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad
'RectorPrefix202208\\Symplify\\Astral\\Contract\\NodeValueResolver\\NodeValueResolverInterface' => __DIR__ . '/..' . '/symplify/astral/src/Contract/NodeValueResolver/NodeValueResolverInterface.php',
'RectorPrefix202208\\Symplify\\Astral\\Exception\\ShouldNotHappenException' => __DIR__ . '/..' . '/symplify/astral/src/Exception/ShouldNotHappenException.php',
'RectorPrefix202208\\Symplify\\Astral\\Naming\\SimpleNameResolver' => __DIR__ . '/..' . '/symplify/astral/src/Naming/SimpleNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeAnalyzer\\NetteTypeAnalyzer' => __DIR__ . '/..' . '/symplify/astral/src/NodeAnalyzer/NetteTypeAnalyzer.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\ArgNodeNameResolver' => __DIR__ . '/..' . '/symplify/astral/src/NodeNameResolver/ArgNodeNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\AttributeNodeNameResolver' => __DIR__ . '/..' . '/symplify/astral/src/NodeNameResolver/AttributeNodeNameResolver.php',
'RectorPrefix202208\\Symplify\\Astral\\NodeNameResolver\\ClassLikeNodeNameResolver' => __DIR__ . '/..' . '/symplify/astral/src/NodeNameResolver/ClassLikeNodeNameResolver.php',
@ -3321,9 +3320,9 @@ class ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0d29dc308111287df9dcca8f6a3cdaad::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit88e5a2405ced7239cbcada0a44df6c5c::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2339,12 +2339,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "8e8149656ac7c675c9b156cf965abb9925cfdbfa"
"reference": "f88fb132d5a7b27482c33d5e3b668f1f4f02d951"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/8e8149656ac7c675c9b156cf965abb9925cfdbfa",
"reference": "8e8149656ac7c675c9b156cf965abb9925cfdbfa",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/f88fb132d5a7b27482c33d5e3b668f1f4f02d951",
"reference": "f88fb132d5a7b27482c33d5e3b668f1f4f02d951",
"shasum": ""
},
"require": {
@ -2373,7 +2373,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-08-06T19:26:16+00:00",
"time": "2022-08-07T16:18:47+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -3253,12 +3253,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symplify\/astral.git",
"reference": "93943dee164859b80bc86acb2f786dcabcd34816"
"reference": "169b669a5ad25f12f00ed750e66580d9bf04606e"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symplify\/astral\/zipball\/93943dee164859b80bc86acb2f786dcabcd34816",
"reference": "93943dee164859b80bc86acb2f786dcabcd34816",
"url": "https:\/\/api.github.com\/repos\/symplify\/astral\/zipball\/169b669a5ad25f12f00ed750e66580d9bf04606e",
"reference": "169b669a5ad25f12f00ed750e66580d9bf04606e",
"shasum": ""
},
"require": {
@ -3298,7 +3298,7 @@
"phpunit\/phpunit": "^9.5.21",
"symplify\/easy-testing": "^11.1"
},
"time": "2022-08-04T20:17:32+00:00",
"time": "2022-08-07T22:51:20+00:00",
"default-branch": true,
"type": "phpstan-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ec96616'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3e935b4'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7ee4e58'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0e86e69'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 987bdb4'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c8bf10'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ad7cfce'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d876ff2'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8e81496'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ec96616'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3e935b4'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7ee4e58'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0e86e69'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 987bdb4'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9c8bf10'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ad7cfce'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d876ff2'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main f88fb13'));
private function __construct()
{
}

View File

@ -0,0 +1,11 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202208;
use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([SymfonySetList::SYMFONY_27, SymfonyLevelSetList::UP_TO_SYMFONY_26]);
};

View File

@ -7,5 +7,5 @@ use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([SymfonySetList::SYMFONY_28, SymfonyLevelSetList::UP_TO_SYMFONY_26]);
$rectorConfig->sets([SymfonySetList::SYMFONY_28, SymfonyLevelSetList::UP_TO_SYMFONY_27]);
};

View File

@ -0,0 +1,10 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202208;
use Rector\Config\RectorConfig;
use Rector\Symfony\Rector\MethodCall\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector::class);
};

View File

@ -13,7 +13,6 @@ use Rector\Symfony\Rector\ClassMethod\FormTypeGetParentRector;
use Rector\Symfony\Rector\ClassMethod\GetRequestRector;
use Rector\Symfony\Rector\ClassMethod\RemoveDefaultGetBlockPrefixRector;
use Rector\Symfony\Rector\MethodCall\CascadeValidationFormBuilderRector;
use Rector\Symfony\Rector\MethodCall\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector;
use Rector\Symfony\Rector\MethodCall\ChangeStringCollectionOptionToConstantRector;
use Rector\Symfony\Rector\MethodCall\FormTypeInstanceToClassConstRector;
use Rector\Symfony\Rector\MethodCall\OptionNameRector;
@ -35,7 +34,6 @@ return static function (RectorConfig $rectorConfig) : void {
RemoveDefaultGetBlockPrefixRector::class,
// forms - collection
ChangeStringCollectionOptionToConstantRector::class,
ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector::class,
]);
$rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [new RenameClassConstFetch('Symfony\\Component\\Form\\FormEvents', 'PRE_BIND', 'PRE_SUBMIT'), new RenameClassConstFetch('Symfony\\Component\\Form\\FormEvents', 'BIND', 'SUBMIT'), new RenameClassConstFetch('Symfony\\Component\\Form\\FormEvents', 'POST_BIND', 'POST_SUBMIT'), new RenameClassConstFetch('Symfony\\Component\\Form\\Extension\\Core\\DataTransformer', 'ROUND_HALFEVEN', 'ROUND_HALF_EVEN'), new RenameClassConstFetch('Symfony\\Component\\Form\\Extension\\Core\\DataTransformer', 'ROUND_HALFUP', 'ROUND_HALF_UP'), new RenameClassConstFetch('Symfony\\Component\\Form\\Extension\\Core\\DataTransformer', 'ROUND_HALFDOWN', 'ROUND_HALF_DOWN')]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [

View File

@ -14,6 +14,10 @@ final class SymfonyLevelSetList implements SetListInterface
* @var string
*/
public const UP_TO_SYMFONY_26 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-26.php';
/**
* @var string
*/
public const UP_TO_SYMFONY_27 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-27.php';
/**
* @var string
*/

View File

@ -18,6 +18,10 @@ final class SymfonySetList implements SetListInterface
* @var string
*/
public const SYMFONY_26 = __DIR__ . '/../../config/sets/symfony/symfony26.php';
/**
* @var string
*/
public const SYMFONY_27 = __DIR__ . '/../../config/sets/symfony/symfony27.php';
/**
* @var string
*/

View File

@ -19,7 +19,6 @@ services:
- Symplify\PackageBuilder\Php\TypeChecker
- Symplify\SmartFileSystem\SmartFileSystem
- Symplify\Astral\NodeAnalyzer\NetteTypeAnalyzer
- Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser
- Symplify\Astral\TypeAnalyzer\ContainsTypeAnalyser

View File

@ -7,10 +7,7 @@ use RectorPrefix202208\Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use RectorPrefix202208\Symplify\Astral\Contract\NodeNameResolverInterface;
/**
* @see \Symplify\Astral\Tests\Naming\SimpleNameResolverTest
@ -59,18 +56,6 @@ final class SimpleNameResolver
}
return null;
}
/**
* @param string[] $desiredNames
*/
public function isNames(Node $node, array $desiredNames) : bool
{
foreach ($desiredNames as $desiredName) {
if ($this->isName($node, $desiredName)) {
return \true;
}
}
return \false;
}
/**
* @param string|\PhpParser\Node $node
*/
@ -85,6 +70,9 @@ final class SimpleNameResolver
}
return $name === $desiredName;
}
/**
* @api
*/
public function areNamesEqual(Node $firstNode, Node $secondNode) : bool
{
$firstName = $this->getName($firstNode);
@ -93,33 +81,6 @@ final class SimpleNameResolver
}
return $this->isName($secondNode, $firstName);
}
public function resolveShortNameFromNode(ClassLike $classLike) : ?string
{
$className = $this->getName($classLike);
if ($className === null) {
return null;
}
// anonymous class return null name
if (Strings::match($className, self::ANONYMOUS_CLASS_REGEX)) {
return null;
}
return $this->resolveShortName($className);
}
public function getClassNameFromScope(Scope $scope) : ?string
{
if ($scope->isInTrait()) {
$traitReflection = $scope->getTraitReflection();
if (!$traitReflection instanceof ClassReflection) {
return null;
}
return $traitReflection->getName();
}
$classReflection = $scope->getClassReflection();
if (!$classReflection instanceof ClassReflection) {
return null;
}
return $classReflection->getName();
}
/**
* @api
*/
@ -131,11 +92,4 @@ final class SimpleNameResolver
}
return (bool) Strings::match($name, $desiredNameRegex);
}
public function resolveShortName(string $className) : string
{
if (\strpos($className, '\\') === \false) {
return $className;
}
return (string) Strings::after($className, '\\', -1);
}
}

View File

@ -1,75 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202208\Symplify\Astral\NodeAnalyzer;
use RectorPrefix202208\Latte\Engine;
use RectorPrefix202208\Nette\Application\UI\Template;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use PHPStan\Analyser\Scope;
use RectorPrefix202208\Symplify\Astral\Naming\SimpleNameResolver;
use RectorPrefix202208\Symplify\Astral\TypeAnalyzer\ContainsTypeAnalyser;
/**
* @api
*/
final class NetteTypeAnalyzer
{
/**
* @var array<class-string<Engine|Template>>
*/
private const TEMPLATE_TYPES = ['RectorPrefix202208\\Latte\\Engine', 'RectorPrefix202208\\Nette\\Application\\UI\\Template', 'RectorPrefix202208\\Nette\\Application\\UI\\ITemplate', 'RectorPrefix202208\\Nette\\Bridges\\ApplicationLatte\\Template', 'RectorPrefix202208\\Nette\\Bridges\\ApplicationLatte\\DefaultTemplate'];
/**
* @var \Symplify\Astral\Naming\SimpleNameResolver
*/
private $simpleNameResolver;
/**
* @var \Symplify\Astral\TypeAnalyzer\ContainsTypeAnalyser
*/
private $containsTypeAnalyser;
public function __construct(SimpleNameResolver $simpleNameResolver, ContainsTypeAnalyser $containsTypeAnalyser)
{
$this->simpleNameResolver = $simpleNameResolver;
$this->containsTypeAnalyser = $containsTypeAnalyser;
}
/**
* E.g. $this->template->key
*/
public function isTemplateMagicPropertyType(Expr $expr, Scope $scope) : bool
{
if (!$expr instanceof PropertyFetch) {
return \false;
}
if (!$expr->var instanceof PropertyFetch) {
return \false;
}
return $this->isTemplateType($expr->var, $scope);
}
/**
* E.g. $this->template
*/
public function isTemplateType(Expr $expr, Scope $scope) : bool
{
return $this->containsTypeAnalyser->containsExprTypes($expr, $scope, self::TEMPLATE_TYPES);
}
/**
* This type has getComponent() method
*/
public function isInsideComponentContainer(Scope $scope) : bool
{
$className = $this->simpleNameResolver->getClassNameFromScope($scope);
if ($className === null) {
return \false;
}
// this type has getComponent() method
return \is_a($className, 'RectorPrefix202208\\Nette\\ComponentModel\\Container', \true);
}
public function isInsideControl(Scope $scope) : bool
{
$className = $this->simpleNameResolver->getClassNameFromScope($scope);
if ($className === null) {
return \false;
}
return \is_a($className, 'RectorPrefix202208\\Nette\\Application\\UI\\Control', \true);
}
}

View File

@ -10,6 +10,9 @@ use PHPStan\Type\IntersectionType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
/**
* @api
*/
final class ContainsTypeAnalyser
{
/**