Skip to content

Commit

Permalink
Updated Rector to commit b001e38
Browse files Browse the repository at this point in the history
rectorphp/rector-src@b001e38 [TypeDeclaration] Skip ReturnTypeFromStrictTypedCallRector on possible no return (#441)
  • Loading branch information
TomasVotruba committed Jul 16, 2021
1 parent 9d280b5 commit e71a1c1
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpParser\Node\Stmt\Unset_;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeManipulator\AssignManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNestingScope\ParentFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\ReadWrite\Guard\VariableToConstantGuard;
Expand All @@ -34,20 +33,15 @@ final class ReadWritePropertyAnalyzer
* @var \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer
*/
private $readExprAnalyzer;
/**
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @var \Rector\NodeNestingScope\ParentFinder
*/
private $parentFinder;
public function __construct(\Rector\ReadWrite\Guard\VariableToConstantGuard $variableToConstantGuard, \Rector\Core\NodeManipulator\AssignManipulator $assignManipulator, \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer $readExprAnalyzer, \Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNestingScope\ParentFinder $parentFinder)
public function __construct(\Rector\ReadWrite\Guard\VariableToConstantGuard $variableToConstantGuard, \Rector\Core\NodeManipulator\AssignManipulator $assignManipulator, \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer $readExprAnalyzer, \Rector\NodeNestingScope\ParentFinder $parentFinder)
{
$this->variableToConstantGuard = $variableToConstantGuard;
$this->assignManipulator = $assignManipulator;
$this->readExprAnalyzer = $readExprAnalyzer;
$this->betterNodeFinder = $betterNodeFinder;
$this->parentFinder = $parentFinder;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind;
use Rector\TypeDeclaration\NodeAnalyzer\TypeNodeUnwrapper;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
Expand All @@ -41,10 +43,15 @@ final class ReturnTypeFromStrictTypedCallRector extends \Rector\Core\Rector\Abst
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(\Rector\TypeDeclaration\NodeAnalyzer\TypeNodeUnwrapper $typeNodeUnwrapper, \Rector\Core\Reflection\ReflectionResolver $reflectionResolver)
/**
* @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer
*/
private $returnTypeInferer;
public function __construct(\Rector\TypeDeclaration\NodeAnalyzer\TypeNodeUnwrapper $typeNodeUnwrapper, \Rector\Core\Reflection\ReflectionResolver $reflectionResolver, \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer $returnTypeInferer)
{
$this->typeNodeUnwrapper = $typeNodeUnwrapper;
$this->reflectionResolver = $reflectionResolver;
$this->returnTypeInferer = $returnTypeInferer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
Expand Down Expand Up @@ -93,6 +100,9 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
if ($this->isSkipped($node)) {
return null;
}
if ($this->isUnionPossibleReturnsVoid($node)) {
return null;
}
/** @var Return_[] $returns */
$returns = $this->betterNodeFinder->find((array) $node->stmts, function (\PhpParser\Node $n) use($node) {
$currentFunctionLike = $this->betterNodeFinder->findParentType($n, \PhpParser\Node\FunctionLike::class);
Expand Down Expand Up @@ -125,6 +135,21 @@ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
}
return null;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
*/
private function isUnionPossibleReturnsVoid($node) : bool
{
$inferReturnType = $this->returnTypeInferer->inferFunctionLike($node);
if ($inferReturnType instanceof \PHPStan\Type\UnionType) {
foreach ($inferReturnType->getTypes() as $type) {
if ($type instanceof \PHPStan\Type\VoidType) {
return \true;
}
}
}
return \false;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
* @return \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '40fbe10f105f92d3c895750d1c37c977be951e82';
public const PACKAGE_VERSION = 'b001e388ccfb37f8af1f4873c63212a0155f642a';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-16 00:55:31';
public const RELEASE_DATE = '2021-07-16 08:59:37';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210716\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
Expand Down
6 changes: 4 additions & 2 deletions src/NodeFactory/ClassWithPublicPropertiesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
declare (strict_types=1);
namespace Rector\Core\NodeFactory;

use PhpParser\Node;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use RectorPrefix20210716\Symplify\Astral\ValueObject\NodeBuilder\ClassBuilder;
use RectorPrefix20210716\Symplify\Astral\ValueObject\NodeBuilder\NamespaceBuilder;
use RectorPrefix20210716\Symplify\Astral\ValueObject\NodeBuilder\PropertyBuilder;
Expand All @@ -19,8 +20,9 @@ final class ClassWithPublicPropertiesFactory
* @param array<string, array{type: string, nullable?: bool}> $properties
* @param string|null $parent fully qualified name of parent class
* @param string[] $traits list of fully qualified names of traits used in class
* @return \PhpParser\Node\Stmt\Namespace_|\PhpParser\Node\Stmt\Class_
*/
public function createNode(string $fullyQualifiedName, array $properties, ?string $parent = null, array $traits = []) : \PhpParser\Node
public function createNode(string $fullyQualifiedName, array $properties, ?string $parent = null, array $traits = [])
{
$namespaceParts = \explode('\\', \ltrim($fullyQualifiedName, '\\'));
$className = \array_pop($namespaceParts);
Expand Down
11 changes: 2 additions & 9 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function __construct(\PhpParser\NodeFinder $nodeFinder, \Rector\NodeNameR
/**
* @template T of Node
* @param class-string<T> $type
* @return T|null
*/
public function findParentType(\PhpParser\Node $node, string $type) : ?\PhpParser\Node
{
Expand Down Expand Up @@ -114,7 +113,6 @@ public function findInstanceOf($nodes, string $type) : array
* @template T of Node
* @param class-string<T> $type
* @param Node|Node[] $nodes
* @return T|null
*/
public function findFirstInstanceOf($nodes, string $type) : ?\PhpParser\Node
{
Expand Down Expand Up @@ -186,7 +184,6 @@ public function hasInstancesOf($nodes, array $types) : bool
* @template T of Node
* @param class-string<T> $type
* @param Node|Node[] $nodes
* @return T|null
*/
public function findLastInstanceOf($nodes, string $type) : ?\PhpParser\Node
{
Expand Down Expand Up @@ -302,7 +299,6 @@ public function findFirstPrevious(\PhpParser\Node $node, callable $filter) : ?\P
/**
* @template T of Node
* @param array<class-string<T>> $types
* @return T|null
*/
public function findFirstPreviousOfTypes(\PhpParser\Node $mainNode, array $types) : ?\PhpParser\Node
{
Expand Down Expand Up @@ -349,10 +345,9 @@ public function findSameNamedExprs($expr) : array
return [];
}
$variables = $this->findInstancesOf($scopeNode, [\PhpParser\Node\Expr\Variable::class]);
$foundVariables = \array_filter($variables, function (\PhpParser\Node\Expr\Variable $variable) use($exprName) {
return \array_filter($variables, function (\PhpParser\Node\Expr\Variable $variable) use($exprName) {
return $this->nodeNameResolver->isName($variable, $exprName);
});
return $foundVariables;
}
if ($expr instanceof \PhpParser\Node\Stmt\Property) {
$singleProperty = $expr->props[0];
Expand All @@ -366,16 +361,14 @@ public function findSameNamedExprs($expr) : array
return [];
}
$propertyFetches = $this->findInstancesOf($scopeNode, [\PhpParser\Node\Expr\PropertyFetch::class, \PhpParser\Node\Expr\StaticPropertyFetch::class]);
$foundProperties = \array_filter($propertyFetches, function ($propertyFetch) use($exprName) {
return \array_filter($propertyFetches, function ($propertyFetch) use($exprName) {
return $this->nodeNameResolver->isName($propertyFetch->name, $exprName);
});
return $foundProperties;
}
/**
* @template T of Node
* @param Node|Node[] $nodes
* @param class-string<T> $type
* @return T|null
*/
private function findInstanceOfName($nodes, string $type, string $name) : ?\PhpParser\Node
{
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810::getLoader();
return ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810
class ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22
{
private static $loader;

Expand All @@ -22,15 +22,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22', '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\ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitad318f92113d53391e5ede7bc1612b22::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
Expand All @@ -42,19 +42,19 @@ public static function getLoader()
$loader->register(true);

if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitad318f92113d53391e5ede7bc1612b22::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirefee571886dcbe988715fd4bcb5f2a810($fileIdentifier, $file);
composerRequiread318f92113d53391e5ede7bc1612b22($fileIdentifier, $file);
}

return $loader;
}
}

function composerRequirefee571886dcbe988715fd4bcb5f2a810($fileIdentifier, $file)
function composerRequiread318f92113d53391e5ede7bc1612b22($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810
class ComposerStaticInitad318f92113d53391e5ede7bc1612b22
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
Expand Down Expand Up @@ -3837,9 +3837,9 @@ class ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfee571886dcbe988715fd4bcb5f2a810::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitad318f92113d53391e5ede7bc1612b22::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitad318f92113d53391e5ede7bc1612b22::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitad318f92113d53391e5ede7bc1612b22::$classMap;

}, null, ClassLoader::class);
}
Expand Down
10 changes: 5 additions & 5 deletions vendor/scoper-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210716\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810', false) && !interface_exists('ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810', false) && !trait_exists('ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810', false)) {
spl_autoload_call('RectorPrefix20210716\ComposerAutoloaderInitfee571886dcbe988715fd4bcb5f2a810');
if (!class_exists('ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22', false) && !interface_exists('ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22', false) && !trait_exists('ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22', false)) {
spl_autoload_call('RectorPrefix20210716\ComposerAutoloaderInitad318f92113d53391e5ede7bc1612b22');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210716\Doctrine\Inflector\Inflector');
Expand Down Expand Up @@ -3308,9 +3308,9 @@ function print_node() {
return \RectorPrefix20210716\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirefee571886dcbe988715fd4bcb5f2a810')) {
function composerRequirefee571886dcbe988715fd4bcb5f2a810() {
return \RectorPrefix20210716\composerRequirefee571886dcbe988715fd4bcb5f2a810(...func_get_args());
if (!function_exists('composerRequiread318f92113d53391e5ede7bc1612b22')) {
function composerRequiread318f92113d53391e5ede7bc1612b22() {
return \RectorPrefix20210716\composerRequiread318f92113d53391e5ede7bc1612b22(...func_get_args());
}
}
if (!function_exists('parseArgs')) {
Expand Down

0 comments on commit e71a1c1

Please sign in to comment.