Updated Rector to commit 86682e4848dcfaecdb6dac7d07ffcb4cd47e69bf

86682e4848 Less doc, move from NodeRemover from AbstractRector - use directly or remove nodes right at the moment - that creates safer tree (#2741)
This commit is contained in:
Tomas Votruba
2022-08-06 22:58:46 +00:00
parent 089ad6e357
commit b9ad506421
9 changed files with 18 additions and 234 deletions

2
vendor/autoload.php vendored
View File

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

View File

@@ -2131,7 +2131,6 @@ return array(
'Rector\\Nette\\NodeFinder\\ParamFinder' => $vendorDir . '/rector/rector-nette/src/NodeFinder/ParamFinder.php', 'Rector\\Nette\\NodeFinder\\ParamFinder' => $vendorDir . '/rector/rector-nette/src/NodeFinder/ParamFinder.php',
'Rector\\Nette\\Rector\\Assign\\ArrayAccessGetControlToGetComponentMethodCallRector' => $vendorDir . '/rector/rector-nette/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php', 'Rector\\Nette\\Rector\\Assign\\ArrayAccessGetControlToGetComponentMethodCallRector' => $vendorDir . '/rector/rector-nette/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php',
'Rector\\Nette\\Rector\\Assign\\ArrayAccessSetControlToAddComponentMethodCallRector' => $vendorDir . '/rector/rector-nette/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php', 'Rector\\Nette\\Rector\\Assign\\ArrayAccessSetControlToAddComponentMethodCallRector' => $vendorDir . '/rector/rector-nette/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php',
'Rector\\Nette\\Rector\\Assign\\MakeGetComponentAssignAnnotatedRector' => $vendorDir . '/rector/rector-nette/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\MergeTemplateSetFileToTemplateRenderRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/MergeTemplateSetFileToTemplateRenderRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\MergeTemplateSetFileToTemplateRenderRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/MergeTemplateSetFileToTemplateRenderRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\RemoveParentAndNameFromComponentConstructorRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\RemoveParentAndNameFromComponentConstructorRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\RenderMethodParamToTypeDeclarationRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/RenderMethodParamToTypeDeclarationRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\RenderMethodParamToTypeDeclarationRector' => $vendorDir . '/rector/rector-nette/src/Rector/ClassMethod/RenderMethodParamToTypeDeclarationRector.php',

View File

@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit15b3e3f37c257ff0b0f8af72563cf505 class ComposerAutoloaderInitf98aa8c3d8a3ba79b44f6155b57e7db2
{ {
private static $loader; private static $loader;
@@ -22,19 +22,19 @@ class ComposerAutoloaderInit15b3e3f37c257ff0b0f8af72563cf505
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit15b3e3f37c257ff0b0f8af72563cf505', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInitf98aa8c3d8a3ba79b44f6155b57e7db2', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit15b3e3f37c257ff0b0f8af72563cf505', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitf98aa8c3d8a3ba79b44f6155b57e7db2', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2::getInitializer($loader));
$loader->setClassMapAuthoritative(true); $loader->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505::$files; $includeFiles = \Composer\Autoload\ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2::$files;
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire15b3e3f37c257ff0b0f8af72563cf505($fileIdentifier, $file); composerRequiref98aa8c3d8a3ba79b44f6155b57e7db2($fileIdentifier, $file);
} }
return $loader; return $loader;
@@ -46,7 +46,7 @@ class ComposerAutoloaderInit15b3e3f37c257ff0b0f8af72563cf505
* @param string $file * @param string $file
* @return void * @return void
*/ */
function composerRequire15b3e3f37c257ff0b0f8af72563cf505($fileIdentifier, $file) function composerRequiref98aa8c3d8a3ba79b44f6155b57e7db2($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505 class ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2
{ {
public static $files = array ( public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@@ -2438,7 +2438,6 @@ class ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505
'Rector\\Nette\\NodeFinder\\ParamFinder' => __DIR__ . '/..' . '/rector/rector-nette/src/NodeFinder/ParamFinder.php', 'Rector\\Nette\\NodeFinder\\ParamFinder' => __DIR__ . '/..' . '/rector/rector-nette/src/NodeFinder/ParamFinder.php',
'Rector\\Nette\\Rector\\Assign\\ArrayAccessGetControlToGetComponentMethodCallRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php', 'Rector\\Nette\\Rector\\Assign\\ArrayAccessGetControlToGetComponentMethodCallRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php',
'Rector\\Nette\\Rector\\Assign\\ArrayAccessSetControlToAddComponentMethodCallRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php', 'Rector\\Nette\\Rector\\Assign\\ArrayAccessSetControlToAddComponentMethodCallRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php',
'Rector\\Nette\\Rector\\Assign\\MakeGetComponentAssignAnnotatedRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\MergeTemplateSetFileToTemplateRenderRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/MergeTemplateSetFileToTemplateRenderRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\MergeTemplateSetFileToTemplateRenderRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/MergeTemplateSetFileToTemplateRenderRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\RemoveParentAndNameFromComponentConstructorRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\RemoveParentAndNameFromComponentConstructorRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php',
'Rector\\Nette\\Rector\\ClassMethod\\RenderMethodParamToTypeDeclarationRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/RenderMethodParamToTypeDeclarationRector.php', 'Rector\\Nette\\Rector\\ClassMethod\\RenderMethodParamToTypeDeclarationRector' => __DIR__ . '/..' . '/rector/rector-nette/src/Rector/ClassMethod/RenderMethodParamToTypeDeclarationRector.php',
@@ -3389,9 +3388,9 @@ class ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit15b3e3f37c257ff0b0f8af72563cf505::$classMap; $loader->classMap = ComposerStaticInitf98aa8c3d8a3ba79b44f6155b57e7db2::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@@ -2202,12 +2202,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-nette.git", "url": "https:\/\/github.com\/rectorphp\/rector-nette.git",
"reference": "51adb00a964775304fabcb2d701f5b6461cc4027" "reference": "0d929e5672488eee6fb04ac3e0ab087c27f80aa4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-nette\/zipball\/51adb00a964775304fabcb2d701f5b6461cc4027", "url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-nette\/zipball\/0d929e5672488eee6fb04ac3e0ab087c27f80aa4",
"reference": "51adb00a964775304fabcb2d701f5b6461cc4027", "reference": "0d929e5672488eee6fb04ac3e0ab087c27f80aa4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -2240,7 +2240,7 @@
"symplify\/rule-doc-generator": "^11.0", "symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0" "symplify\/vendor-patches": "^11.0"
}, },
"time": "2022-08-06T21:32:25+00:00", "time": "2022-08-06T22:43:20+00:00",
"default-branch": true, "default-branch": true,
"type": "rector-extension", "type": "rector-extension",
"extra": { "extra": {

File diff suppressed because one or more lines are too long

View File

@@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/ */
final class GeneratedConfig 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 ea5a50c'), '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 51adb00'), '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 ea5a50c'), '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 0d929e5'), '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'));
private function __construct() private function __construct()
{ {
} }

View File

@@ -6,12 +6,10 @@ namespace RectorPrefix202208;
use Rector\Config\RectorConfig; use Rector\Config\RectorConfig;
use Rector\Nette\Rector\Assign\ArrayAccessGetControlToGetComponentMethodCallRector; use Rector\Nette\Rector\Assign\ArrayAccessGetControlToGetComponentMethodCallRector;
use Rector\Nette\Rector\Assign\ArrayAccessSetControlToAddComponentMethodCallRector; use Rector\Nette\Rector\Assign\ArrayAccessSetControlToAddComponentMethodCallRector;
use Rector\Nette\Rector\Assign\MakeGetComponentAssignAnnotatedRector;
use Rector\Nette\Rector\ClassMethod\TemplateMagicAssignToExplicitVariableArrayRector; use Rector\Nette\Rector\ClassMethod\TemplateMagicAssignToExplicitVariableArrayRector;
use Rector\Nette\Rector\Identical\SubstrMinusToStringEndsWithRector; use Rector\Nette\Rector\Identical\SubstrMinusToStringEndsWithRector;
return static function (RectorConfig $rectorConfig) : void { return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(TemplateMagicAssignToExplicitVariableArrayRector::class); $rectorConfig->rule(TemplateMagicAssignToExplicitVariableArrayRector::class);
$rectorConfig->rule(MakeGetComponentAssignAnnotatedRector::class);
$rectorConfig->rule(ArrayAccessSetControlToAddComponentMethodCallRector::class); $rectorConfig->rule(ArrayAccessSetControlToAddComponentMethodCallRector::class);
$rectorConfig->rule(ArrayAccessGetControlToGetComponentMethodCallRector::class); $rectorConfig->rule(ArrayAccessGetControlToGetComponentMethodCallRector::class);
$rectorConfig->rule(SubstrMinusToStringEndsWithRector::class); $rectorConfig->rule(SubstrMinusToStringEndsWithRector::class);

View File

@@ -1,212 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Nette\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\BetterPhpDocParser\PhpDocManipulator\VarAnnotationManipulator;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Nette\Tests\Rector\Assign\MakeGetComponentAssignAnnotatedRector\MakeGetComponentAssignAnnotatedRectorTest
*/
final class MakeGetComponentAssignAnnotatedRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\VarAnnotationManipulator
*/
private $varAnnotationManipulator;
public function __construct(VarAnnotationManipulator $varAnnotationManipulator)
{
$this->varAnnotationManipulator = $varAnnotationManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add doc type for magic $control->getComponent(...) assign', [new CodeSample(<<<'CODE_SAMPLE'
use Nette\Application\UI\Control;
final class SomeClass
{
public function run()
{
$externalControl = new ExternalControl();
$anotherControl = $externalControl->getComponent('another');
}
}
final class ExternalControl extends Control
{
public function createComponentAnother(): AnotherControl
{
return new AnotherControl();
}
}
final class AnotherControl extends Control
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Nette\Application\UI\Control;
final class SomeClass
{
public function run()
{
$externalControl = new ExternalControl();
/** @var AnotherControl $anotherControl */
$anotherControl = $externalControl->getComponent('another');
}
}
final class ExternalControl extends Control
{
public function createComponentAnother(): AnotherControl
{
return new AnotherControl();
}
}
final class AnotherControl extends Control
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Assign::class];
}
/**
* @param Assign $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->isGetComponentMethodCallOrArrayDimFetchOnControl($node->expr)) {
return null;
}
if (!$node->var instanceof Variable) {
return null;
}
$variableName = $this->getName($node->var);
if ($variableName === null) {
return null;
}
$nodeVar = $this->nodeTypeResolver->getType($node->var);
if (!$nodeVar instanceof MixedType) {
return null;
}
$controlType = $this->resolveControlType($node);
if (!$controlType instanceof TypeWithClassName) {
return null;
}
$this->varAnnotationManipulator->decorateNodeWithInlineVarType($node, $controlType, $variableName);
return $node;
}
private function isGetComponentMethodCallOrArrayDimFetchOnControl(Expr $expr) : bool
{
if (!$expr instanceof MethodCall) {
return $this->isArrayDimFetchStringOnControlVariable($expr);
}
if (!$this->isObjectType($expr->var, new ObjectType('Nette\\Application\\UI\\Control'))) {
return $this->isArrayDimFetchStringOnControlVariable($expr);
}
if (!$this->isName($expr->name, 'getComponent')) {
return $this->isArrayDimFetchStringOnControlVariable($expr);
}
return \true;
}
private function resolveControlType(Assign $assign) : Type
{
if ($assign->expr instanceof MethodCall) {
/** @var MethodCall $methodCall */
$methodCall = $assign->expr;
return $this->resolveCreateComponentMethodCallReturnType($methodCall);
}
if ($assign->expr instanceof ArrayDimFetch) {
/** @var ArrayDimFetch $arrayDimFetch */
$arrayDimFetch = $assign->expr;
return $this->resolveArrayDimFetchControlType($arrayDimFetch);
}
return new MixedType();
}
private function isArrayDimFetchStringOnControlVariable(Expr $expr) : bool
{
if (!$expr instanceof ArrayDimFetch) {
return \false;
}
if (!$expr->dim instanceof String_) {
return \false;
}
$varStaticType = $this->getType($expr->var);
if (!$varStaticType instanceof TypeWithClassName) {
return \false;
}
$controlObjecType = new ObjectType('Nette\\Application\\UI\\Control');
return $controlObjecType->isSuperTypeOf($varStaticType)->yes();
}
private function resolveCreateComponentMethodCallReturnType(MethodCall $methodCall) : Type
{
$scope = $methodCall->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return new MixedType();
}
if (\count($methodCall->args) !== 1) {
return new MixedType();
}
$firstArgumentValue = $methodCall->args[0]->value;
if (!$firstArgumentValue instanceof String_) {
return new MixedType();
}
return $this->resolveTypeFromShortControlNameAndVariable($firstArgumentValue, $scope, $methodCall->var);
}
private function resolveArrayDimFetchControlType(ArrayDimFetch $arrayDimFetch) : Type
{
$scope = $arrayDimFetch->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
throw new ShouldNotHappenException();
}
if (!$arrayDimFetch->dim instanceof String_) {
return new MixedType();
}
return $this->resolveTypeFromShortControlNameAndVariable($arrayDimFetch->dim, $scope, $arrayDimFetch->var);
}
private function resolveTypeFromShortControlNameAndVariable(String_ $shortControlString, Scope $scope, Expr $expr) : Type
{
$componentName = $this->valueResolver->getValue($shortControlString);
if (!\is_string($componentName)) {
throw new ShouldNotHappenException();
}
$componentName = \ucfirst($componentName);
$methodName = \sprintf('createComponent%s', $componentName);
$calledOnType = $scope->getType($expr);
if (!$calledOnType instanceof TypeWithClassName) {
return new MixedType();
}
if (!$calledOnType->hasMethod($methodName)->yes()) {
return new MixedType();
}
// has method
$methodReflection = $calledOnType->getMethod($methodName, $scope);
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
}
}