Updated Rector to commit 185ee1b473147fd620d3da2c42eb52b1756f2a18

185ee1b473 [DX] Add strict PHPStan rules - step #4 (#1333)
This commit is contained in:
Tomas Votruba 2021-11-28 18:05:13 +00:00
parent b426e4ba33
commit 11660d59a5
39 changed files with 112 additions and 102 deletions

View File

@ -168,7 +168,7 @@ final class PhpDocInfoPrinter
$output = '/**' . $output; $output = '/**' . $output;
} }
// fix missing end // fix missing end
if (\Rector\Core\Util\StringUtils::isMatch($output, self::OPENING_DOCBLOCK_REGEX) && $output && !\Rector\Core\Util\StringUtils::isMatch($output, self::CLOSING_DOCBLOCK_REGEX)) { if (\Rector\Core\Util\StringUtils::isMatch($output, self::OPENING_DOCBLOCK_REGEX) && !\Rector\Core\Util\StringUtils::isMatch($output, self::CLOSING_DOCBLOCK_REGEX)) {
$output .= ' */'; $output .= ' */';
} }
return $output; return $output;
@ -212,7 +212,10 @@ final class PhpDocInfoPrinter
} }
private function printEnd(string $output) : string private function printEnd(string $output) : string
{ {
$lastTokenPosition = $this->getCurrentPhpDocInfo()->getPhpDocNode()->getAttribute(\Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey::LAST_PHP_DOC_TOKEN_POSITION) ?: $this->currentTokenPosition; $lastTokenPosition = $this->getCurrentPhpDocInfo()->getPhpDocNode()->getAttribute(\Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey::LAST_PHP_DOC_TOKEN_POSITION);
if ($lastTokenPosition === null) {
$lastTokenPosition = $this->currentTokenPosition;
}
if ($lastTokenPosition === 0) { if ($lastTokenPosition === 0) {
$lastTokenPosition = 1; $lastTokenPosition = 1;
} }

View File

@ -42,7 +42,7 @@ final class FileHashComputer
$fileLoaders = [new \RectorPrefix20211128\Symfony\Component\DependencyInjection\Loader\GlobFileLoader($containerBuilder, $fileLocator), new \RectorPrefix20211128\Symfony\Component\DependencyInjection\Loader\PhpFileLoader($containerBuilder, $fileLocator)]; $fileLoaders = [new \RectorPrefix20211128\Symfony\Component\DependencyInjection\Loader\GlobFileLoader($containerBuilder, $fileLocator), new \RectorPrefix20211128\Symfony\Component\DependencyInjection\Loader\PhpFileLoader($containerBuilder, $fileLocator)];
$loaderResolver = new \RectorPrefix20211128\Symfony\Component\Config\Loader\LoaderResolver($fileLoaders); $loaderResolver = new \RectorPrefix20211128\Symfony\Component\Config\Loader\LoaderResolver($fileLoaders);
$loader = $loaderResolver->resolve($filePath); $loader = $loaderResolver->resolve($filePath);
if (!$loader) { if ($loader === \false) {
throw new \Rector\Core\Exception\ShouldNotHappenException(); throw new \Rector\Core\Exception\ShouldNotHappenException();
} }
return $loader; return $loader;

View File

@ -78,7 +78,7 @@ final class ConsoleOutputFormatter implements \Rector\ChangesReporting\Contract\
} }
$message = \sprintf('<options=bold>%d) %s</>', ++$i, $relativeFilePath); $message = \sprintf('<options=bold>%d) %s</>', ++$i, $relativeFilePath);
$this->outputStyle->writeln($message); $this->outputStyle->writeln($message);
$this->outputStyle->newLine(); $this->outputStyle->newline();
$this->outputStyle->writeln($fileDiff->getDiffConsoleFormatted()); $this->outputStyle->writeln($fileDiff->getDiffConsoleFormatted());
$rectorsChangelogsLines = $this->createRectorChangelogLines($fileDiff); $rectorsChangelogsLines = $this->createRectorChangelogLines($fileDiff);
if ($fileDiff->getRectorChanges() !== []) { if ($fileDiff->getRectorChanges() !== []) {

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\NodeTypeResolver\NodeTypeResolver; namespace Rector\NodeTypeResolver\NodeTypeResolver;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param; use PhpParser\Node\Param;
use PHPStan\Analyser\Scope; use PHPStan\Analyser\Scope;
@ -15,6 +16,8 @@ use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
/** /**
* @see \Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\VariableTypeResolver\VariableTypeResolverTest * @see \Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\VariableTypeResolver\VariableTypeResolverTest
*
* @implements NodeTypeResolverInterface<Variable>
*/ */
final class VariableTypeResolver implements \Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface final class VariableTypeResolver implements \Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface
{ {
@ -32,7 +35,7 @@ final class VariableTypeResolver implements \Rector\NodeTypeResolver\Contract\No
$this->phpDocInfoFactory = $phpDocInfoFactory; $this->phpDocInfoFactory = $phpDocInfoFactory;
} }
/** /**
* @return array<class-string<Node>> * @return array<class-string<Expr>>
*/ */
public function getNodeClasses() : array public function getNodeClasses() : array
{ {

View File

@ -74,6 +74,9 @@ final class StaticTypeAnalyzer
private function isAlwaysTruableArrayType(\PHPStan\Type\ArrayType $arrayType) : bool private function isAlwaysTruableArrayType(\PHPStan\Type\ArrayType $arrayType) : bool
{ {
$itemType = $arrayType->getItemType(); $itemType = $arrayType->getItemType();
return $itemType instanceof \PHPStan\Type\ConstantScalarType && $itemType->getValue(); if (!$itemType instanceof \PHPStan\Type\ConstantScalarType) {
return \false;
}
return (bool) $itemType->getValue();
} }
} }

View File

@ -57,7 +57,7 @@ final class DynamicSourceLocatorProvider implements \Rector\NodeTypeResolver\Con
{ {
// do not cache for PHPUnit, as in test every fixture is different // do not cache for PHPUnit, as in test every fixture is different
$isPHPUnitRun = \Rector\Testing\PHPUnit\StaticPHPUnitEnvironment::isPHPUnitRun(); $isPHPUnitRun = \Rector\Testing\PHPUnit\StaticPHPUnitEnvironment::isPHPUnitRun();
if ($this->aggregateSourceLocator && !$isPHPUnitRun) { if ($this->aggregateSourceLocator instanceof \PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator && !$isPHPUnitRun) {
return $this->aggregateSourceLocator; return $this->aggregateSourceLocator;
} }
$sourceLocators = []; $sourceLocators = [];

View File

@ -126,10 +126,7 @@ final class ParallelFileProcessor
foreach ($json[\Rector\Parallel\ValueObject\Bridge::FILE_DIFFS] as $jsonError) { foreach ($json[\Rector\Parallel\ValueObject\Bridge::FILE_DIFFS] as $jsonError) {
$fileDiffs[] = \Rector\Core\ValueObject\Reporting\FileDiff::decode($jsonError); $fileDiffs[] = \Rector\Core\ValueObject\Reporting\FileDiff::decode($jsonError);
} }
// @todo why there is a null check? $postFileCallback($json[\Rector\Parallel\ValueObject\Bridge::FILES_COUNT]);
if ($postFileCallback !== null) {
$postFileCallback($json[\Rector\Parallel\ValueObject\Bridge::FILES_COUNT]);
}
$systemErrorsCount += $json[\Rector\Parallel\ValueObject\Bridge::SYSTEM_ERRORS_COUNT]; $systemErrorsCount += $json[\Rector\Parallel\ValueObject\Bridge::SYSTEM_ERRORS_COUNT];
if ($systemErrorsCount >= self::SYSTEM_ERROR_COUNT_LIMIT) { if ($systemErrorsCount >= self::SYSTEM_ERROR_COUNT_LIMIT) {
$reachedInternalErrorsCountLimit = \true; $reachedInternalErrorsCountLimit = \true;

View File

@ -3,15 +3,18 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\ReadWrite\Contract; namespace Rector\ReadWrite\Contract;
use PhpParser\Node; use PhpParser\Node\Expr;
/**
* @template TExpr as Expr
*/
interface ReadNodeAnalyzerInterface interface ReadNodeAnalyzerInterface
{ {
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function supports($node) : bool; public function supports($expr) : bool;
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function isRead($node) : bool; public function isRead($expr) : bool;
} }

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\ReadWrite\ReadNodeAnalyzer; namespace Rector\ReadWrite\ReadNodeAnalyzer;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
@ -11,6 +12,9 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder; use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeNameResolver\NodeNameResolver;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
/**
* @implements ReadNodeAnalyzerInterface<PropertyFetch|StaticPropertyFetch>
*/
final class LocalPropertyFetchReadNodeAnalyzer implements \Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface final class LocalPropertyFetchReadNodeAnalyzer implements \Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface
{ {
/** /**
@ -37,23 +41,23 @@ final class LocalPropertyFetchReadNodeAnalyzer implements \Rector\ReadWrite\Cont
$this->betterNodeFinder = $betterNodeFinder; $this->betterNodeFinder = $betterNodeFinder;
} }
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function supports($node) : bool public function supports($expr) : bool
{ {
return $node instanceof \PhpParser\Node\Expr\PropertyFetch || $node instanceof \PhpParser\Node\Expr\StaticPropertyFetch; return $expr instanceof \PhpParser\Node\Expr\PropertyFetch || $expr instanceof \PhpParser\Node\Expr\StaticPropertyFetch;
} }
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function isRead($node) : bool public function isRead($expr) : bool
{ {
$class = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\Class_::class); $class = $this->betterNodeFinder->findParentType($expr, \PhpParser\Node\Stmt\Class_::class);
if (!$class instanceof \PhpParser\Node\Stmt\Class_) { if (!$class instanceof \PhpParser\Node\Stmt\Class_) {
// assume worse to keep node protected // assume worse to keep node protected
return \true; return \true;
} }
$propertyName = $this->nodeNameResolver->getName($node->name); $propertyName = $this->nodeNameResolver->getName($expr->name);
if ($propertyName === null) { if ($propertyName === null) {
// assume worse to keep node protected // assume worse to keep node protected
return \true; return \true;

View File

@ -3,11 +3,14 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\ReadWrite\ReadNodeAnalyzer; namespace Rector\ReadWrite\ReadNodeAnalyzer;
use PhpParser\Node; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use Rector\NodeNestingScope\ParentScopeFinder; use Rector\NodeNestingScope\ParentScopeFinder;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
use Rector\ReadWrite\NodeFinder\NodeUsageFinder; use Rector\ReadWrite\NodeFinder\NodeUsageFinder;
/**
* @implements ReadNodeAnalyzerInterface<Variable>
*/
final class VariableReadNodeAnalyzer implements \Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface final class VariableReadNodeAnalyzer implements \Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface
{ {
/** /**
@ -29,22 +32,22 @@ final class VariableReadNodeAnalyzer implements \Rector\ReadWrite\Contract\ReadN
$this->justReadExprAnalyzer = $justReadExprAnalyzer; $this->justReadExprAnalyzer = $justReadExprAnalyzer;
} }
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function supports($node) : bool public function supports($expr) : bool
{ {
return $node instanceof \PhpParser\Node\Expr\Variable; return $expr instanceof \PhpParser\Node\Expr\Variable;
} }
/** /**
* @param \PhpParser\Node $node * @param \PhpParser\Node\Expr $expr
*/ */
public function isRead($node) : bool public function isRead($expr) : bool
{ {
$parentScope = $this->parentScopeFinder->find($node); $parentScope = $this->parentScopeFinder->find($expr);
if ($parentScope === null) { if ($parentScope === null) {
return \false; return \false;
} }
$variableUsages = $this->nodeUsageFinder->findVariableUsages((array) $parentScope->stmts, $node); $variableUsages = $this->nodeUsageFinder->findVariableUsages((array) $parentScope->stmts, $expr);
foreach ($variableUsages as $variableUsage) { foreach ($variableUsages as $variableUsage) {
if ($this->justReadExprAnalyzer->isReadContext($variableUsage)) { if ($this->justReadExprAnalyzer->isReadContext($variableUsage)) {
return \true; return \true;

View File

@ -7,10 +7,13 @@ use PhpParser\Node;
use PHPStan\Analyser\NameScope; use PHPStan\Analyser\NameScope;
use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type; use PHPStan\Type\Type;
/**
* @template TTypeNode as TypeNode
*/
interface PhpDocTypeMapperInterface interface PhpDocTypeMapperInterface
{ {
/** /**
* @return class-string<TypeNode> * @return class-string<TTypeNode>
*/ */
public function getNodeType() : string; public function getNodeType() : string;
/** /**

View File

@ -13,7 +13,6 @@ use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\Generic\TemplateTypeMap; use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Type; use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\StaticTypeMapper;
@ -81,13 +80,9 @@ final class NameScopeFactory
foreach ($useNode->uses as $useUse) { foreach ($useNode->uses as $useUse) {
/** @var UseUse $useUse */ /** @var UseUse $useUse */
$aliasName = $useUse->getAlias()->name; $aliasName = $useUse->getAlias()->name;
$useName = $useUse->name->toString();
if (!\is_string($useName)) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
// uses must be lowercase, as PHPStan lowercases it // uses must be lowercase, as PHPStan lowercases it
$lowercasedAliasName = \strtolower($aliasName); $lowercasedAliasName = \strtolower($aliasName);
$useNamesByAlias[$lowercasedAliasName] = $useName; $useNamesByAlias[$lowercasedAliasName] = $useUse->name->toString();
} }
} }
return $useNamesByAlias; return $useNamesByAlias;

View File

@ -25,6 +25,9 @@ use Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType; use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType;
use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType; use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType;
use Rector\TypeDeclaration\PHPStan\Type\ObjectTypeSpecifier; use Rector\TypeDeclaration\PHPStan\Type\ObjectTypeSpecifier;
/**
* @implements PhpDocTypeMapperInterface<IdentifierTypeNode>
*/
final class IdentifierTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface final class IdentifierTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface
{ {
/** /**
@ -55,9 +58,6 @@ final class IdentifierTypeMapper implements \Rector\StaticTypeMapper\Contract\Ph
$this->nodeNameResolver = $nodeNameResolver; $this->nodeNameResolver = $nodeNameResolver;
$this->reflectionProvider = $reflectionProvider; $this->reflectionProvider = $reflectionProvider;
} }
/**
* @return class-string<TypeNode>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode::class; return \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode::class;

View File

@ -12,15 +12,15 @@ use PHPStan\Type\Type;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper; use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
use RectorPrefix20211128\Symfony\Contracts\Service\Attribute\Required; use RectorPrefix20211128\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements PhpDocTypeMapperInterface<IntersectionTypeNode>
*/
final class IntersectionTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface final class IntersectionTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface
{ {
/** /**
* @var \Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper * @var \Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper
*/ */
private $phpDocTypeMapper; private $phpDocTypeMapper;
/**
* @return class-string<TypeNode>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode::class; return \PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode::class;

View File

@ -13,6 +13,9 @@ use PHPStan\Type\NullType;
use PHPStan\Type\Type; use PHPStan\Type\Type;
use PHPStan\Type\UnionType; use PHPStan\Type\UnionType;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
/**
* @implements PhpDocTypeMapperInterface<NullableTypeNode>
*/
final class NullableTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface final class NullableTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface
{ {
/** /**
@ -28,9 +31,6 @@ final class NullableTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpD
$this->identifierTypeMapper = $identifierTypeMapper; $this->identifierTypeMapper = $identifierTypeMapper;
$this->typeNodeResolver = $typeNodeResolver; $this->typeNodeResolver = $typeNodeResolver;
} }
/**
* @return class-string<TypeNode>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PHPStan\PhpDocParser\Ast\Type\NullableTypeNode::class; return \PHPStan\PhpDocParser\Ast\Type\NullableTypeNode::class;

View File

@ -12,6 +12,9 @@ use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper; use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
use RectorPrefix20211128\Symfony\Contracts\Service\Attribute\Required; use RectorPrefix20211128\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements PhpDocTypeMapperInterface<UnionTypeNode>
*/
final class UnionTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface final class UnionTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface
{ {
/** /**
@ -26,9 +29,6 @@ final class UnionTypeMapper implements \Rector\StaticTypeMapper\Contract\PhpDocP
{ {
$this->typeFactory = $typeFactory; $this->typeFactory = $typeFactory;
} }
/**
* @return class-string<TypeNode>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PHPStan\PhpDocParser\Ast\Type\UnionTypeNode::class; return \PHPStan\PhpDocParser\Ast\Type\UnionTypeNode::class;

View File

@ -15,9 +15,6 @@ use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
*/ */
final class ExprNodeMapper implements \Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface final class ExprNodeMapper implements \Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface
{ {
/**
* @return class-string<Node>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PhpParser\Node\Expr::class; return \PhpParser\Node\Expr::class;

View File

@ -33,9 +33,6 @@ final class FullyQualifiedNodeMapper implements \Rector\StaticTypeMapper\Contrac
$this->currentFileProvider = $currentFileProvider; $this->currentFileProvider = $currentFileProvider;
$this->usedImportsResolver = $usedImportsResolver; $this->usedImportsResolver = $usedImportsResolver;
} }
/**
* @return class-string<Node>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PhpParser\Node\Name\FullyQualified::class; return \PhpParser\Node\Name\FullyQualified::class;

View File

@ -21,9 +21,6 @@ final class IdentifierNodeMapper implements \Rector\StaticTypeMapper\Contract\Ph
{ {
$this->scalarStringToTypeMapper = $scalarStringToTypeMapper; $this->scalarStringToTypeMapper = $scalarStringToTypeMapper;
} }
/**
* @return class-string<Node>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PhpParser\Node\Identifier::class; return \PhpParser\Node\Identifier::class;

View File

@ -55,9 +55,6 @@ final class NameNodeMapper implements \Rector\StaticTypeMapper\Contract\PhpParse
$this->betterNodeFinder = $betterNodeFinder; $this->betterNodeFinder = $betterNodeFinder;
$this->nodeNameResolver = $nodeNameResolver; $this->nodeNameResolver = $nodeNameResolver;
} }
/**
* @return class-string<Node>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PhpParser\Node\Name::class; return \PhpParser\Node\Name::class;

View File

@ -13,9 +13,6 @@ use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
*/ */
final class StringNodeMapper implements \Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface final class StringNodeMapper implements \Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface
{ {
/**
* @return class-string<Node>
*/
public function getNodeType() : string public function getNodeType() : string
{ {
return \PhpParser\Node\Scalar\String_::class; return \PhpParser\Node\Scalar\String_::class;

View File

@ -63,7 +63,7 @@ CODE_SAMPLE
*/ */
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node\Expr\FuncCall public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node\Expr\FuncCall
{ {
$isJustSwapped = $node->getAttribute(self::JUST_SWAPPED); $isJustSwapped = (bool) $node->getAttribute(self::JUST_SWAPPED, \false);
if ($isJustSwapped) { if ($isJustSwapped) {
return null; return null;
} }

View File

@ -101,7 +101,7 @@ CODE_SAMPLE
continue; continue;
} }
$classReflection = $this->reflectionProvider->getClass($propertyFetchVarType->getClassName()); $classReflection = $this->reflectionProvider->getClass($propertyFetchVarType->getClassName());
if (!$classReflection->hasProperty($propertyFetchName) || $classReflection->isBuiltIn()) { if (!$classReflection->hasProperty($propertyFetchName) || $classReflection->isBuiltin()) {
$newNodes[] = $this->replaceToPropertyExistsWithNullCheck($issetVar->var, $propertyFetchName, $issetVar); $newNodes[] = $this->replaceToPropertyExistsWithNullCheck($issetVar->var, $propertyFetchName, $issetVar);
} else { } else {
$newNodes[] = $this->createNotIdenticalToNull($issetVar); $newNodes[] = $this->createNotIdenticalToNull($issetVar);

View File

@ -126,7 +126,7 @@ final class UseImportsAdder
private function isCurrentNamespace(string $namespaceName, \PHPStan\Type\ObjectType $objectType) : bool private function isCurrentNamespace(string $namespaceName, \PHPStan\Type\ObjectType $objectType) : bool
{ {
$afterCurrentNamespace = \RectorPrefix20211128\Nette\Utils\Strings::after($objectType->getClassName(), $namespaceName . '\\'); $afterCurrentNamespace = \RectorPrefix20211128\Nette\Utils\Strings::after($objectType->getClassName(), $namespaceName . '\\');
if (!$afterCurrentNamespace) { if ($afterCurrentNamespace === null) {
return \false; return \false;
} }
return \strpos($afterCurrentNamespace, '\\') === \false; return \strpos($afterCurrentNamespace, '\\') === \false;

View File

@ -201,10 +201,13 @@ final class ShortNameResolver
{ {
$shortNamesToFullyQualifiedNames = []; $shortNamesToFullyQualifiedNames = [];
foreach ($shortNames as $shortName) { foreach ($shortNames as $shortName) {
$stmtsMatchedName = $this->useImportNameMatcher->matchNameWithStmts($shortName, $stmts);
if ($reflectionClass instanceof \ReflectionClass) { if ($reflectionClass instanceof \ReflectionClass) {
$fullyQualifiedName = \RectorPrefix20211128\Nette\Utils\Reflection::expandClassName($shortName, $reflectionClass); $fullyQualifiedName = \RectorPrefix20211128\Nette\Utils\Reflection::expandClassName($shortName, $reflectionClass);
} elseif (\is_string($stmtsMatchedName)) {
$fullyQualifiedName = $stmtsMatchedName;
} else { } else {
$fullyQualifiedName = $this->useImportNameMatcher->matchNameWithStmts($shortName, $stmts) ?: $shortName; $fullyQualifiedName = $shortName;
} }
$shortNamesToFullyQualifiedNames[$shortName] = $fullyQualifiedName; $shortNamesToFullyQualifiedNames[$shortName] = $fullyQualifiedName;
} }

View File

@ -41,7 +41,11 @@ final class ClassNaming
$name = $name->toString(); $name = $name->toString();
} }
$name = \trim($name, '\\'); $name = \trim($name, '\\');
return \RectorPrefix20211128\Nette\Utils\Strings::after($name, '\\', -1) ?: $name; $shortName = \RectorPrefix20211128\Nette\Utils\Strings::after($name, '\\', -1);
if (\is_string($shortName)) {
return $shortName;
}
return $name;
} }
public function getNamespace(string $fullyQualifiedName) : ?string public function getNamespace(string $fullyQualifiedName) : ?string
{ {

View File

@ -105,8 +105,8 @@ final class NameImporter
} }
// Importing root namespace classes (like \DateTime) is optional // Importing root namespace classes (like \DateTime) is optional
if (!$this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::IMPORT_SHORT_CLASSES)) { if (!$this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::IMPORT_SHORT_CLASSES)) {
$name = $this->nodeNameResolver->getName($name); $stringName = $this->nodeNameResolver->getName($name);
if ($name !== null && \substr_count($name, '\\') === 0) { if ($stringName !== null && \substr_count($stringName, '\\') === 0) {
return \true; return \true;
} }
} }
@ -153,7 +153,7 @@ final class NameImporter
{ {
$parentNode = $name->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE); $parentNode = $name->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
$fullName = $name->toString(); $fullName = $name->toString();
$autoImportNames = $this->parameterProvider->provideParameter(\Rector\Core\Configuration\Option::AUTO_IMPORT_NAMES); $autoImportNames = $this->parameterProvider->provideBoolParameter(\Rector\Core\Configuration\Option::AUTO_IMPORT_NAMES);
if ($autoImportNames && !$parentNode instanceof \PhpParser\Node && \strpos($fullName, '\\') === \false && $this->reflectionProvider->hasFunction(new \PhpParser\Node\Name($fullName), null)) { if ($autoImportNames && !$parentNode instanceof \PhpParser\Node && \strpos($fullName, '\\') === \false && $this->reflectionProvider->hasFunction(new \PhpParser\Node\Name($fullName), null)) {
return \true; return \true;
} }

View File

@ -77,7 +77,7 @@ CODE_SAMPLE
foreach ($node->parts as $part) { foreach ($node->parts as $part) {
if ($part instanceof \PhpParser\Node\Scalar\EncapsedStringPart) { if ($part instanceof \PhpParser\Node\Scalar\EncapsedStringPart) {
$this->collectEncapsedStringPart($part); $this->collectEncapsedStringPart($part);
} elseif ($part instanceof \PhpParser\Node\Expr) { } else {
$this->collectExpr($part); $this->collectExpr($part);
} }
} }

View File

@ -32,7 +32,7 @@ final class BuiltInMethodAnalyzer
return \false; return \false;
} }
foreach ($classReflection->getInterfaces() as $interfaceReflection) { foreach ($classReflection->getInterfaces() as $interfaceReflection) {
if (!$interfaceReflection->isBuiltIn()) { if (!$interfaceReflection->isBuiltin()) {
continue; continue;
} }
if (!$interfaceReflection->hasMethod($methodName)) { if (!$interfaceReflection->hasMethod($methodName)) {

View File

@ -44,7 +44,7 @@ final class InflectorSingularResolver
public function resolve(string $currentName) : string public function resolve(string $currentName) : string
{ {
$matchBy = \RectorPrefix20211128\Nette\Utils\Strings::match($currentName, self::BY_MIDDLE_REGEX); $matchBy = \RectorPrefix20211128\Nette\Utils\Strings::match($currentName, self::BY_MIDDLE_REGEX);
if ($matchBy) { if ($matchBy !== null) {
return \RectorPrefix20211128\Nette\Utils\Strings::substring($currentName, 0, -\strlen($matchBy['by'])); return \RectorPrefix20211128\Nette\Utils\Strings::substring($currentName, 0, -\strlen($matchBy['by']));
} }
$resolvedValue = $this->resolveSingularizeMap($currentName); $resolvedValue = $this->resolveSingularizeMap($currentName);

View File

@ -56,7 +56,7 @@ CODE_SAMPLE
if ($this->shouldSkip()) { if ($this->shouldSkip()) {
return null; return null;
} }
return $this->isArrayAndDualCheckToAble->processBooleanOr($node, 'Countable', 'is_countable') ?: $node; return $this->isArrayAndDualCheckToAble->processBooleanOr($node, 'Countable', 'is_countable');
} }
public function provideMinPhpVersion() : int public function provideMinPhpVersion() : int
{ {

View File

@ -159,7 +159,7 @@ CODE_SAMPLE
if (!\is_string($variableName)) { if (!\is_string($variableName)) {
return; return;
} }
if (!$methodName) { if (!\is_string($methodName)) {
return; return;
} }
$this->callsByVariable[$variableName][] = $methodName; $this->callsByVariable[$variableName][] = $methodName;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Privatization\NodeAnalyzer; namespace Rector\Privatization\NodeAnalyzer;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
@ -52,7 +53,7 @@ final class PropertyFetchByMethodAnalyzer
{ {
$propertyUsageByMethods = []; $propertyUsageByMethods = [];
foreach ($propertyNames as $propertyName) { foreach ($propertyNames as $propertyName) {
if ($this->isPropertyHasDefaultValue($class, $propertyName)) { if ($this->isPropertyWithDefaultValue($class, $propertyName)) {
continue; continue;
} }
foreach ($class->getMethods() as $classMethod) { foreach ($class->getMethods() as $classMethod) {
@ -79,10 +80,13 @@ final class PropertyFetchByMethodAnalyzer
} }
return $this->isPropertyChangingInMultipleMethodCalls($classMethod, $propertyName); return $this->isPropertyChangingInMultipleMethodCalls($classMethod, $propertyName);
} }
private function isPropertyHasDefaultValue(\PhpParser\Node\Stmt\Class_ $class, string $propertyName) : bool private function isPropertyWithDefaultValue(\PhpParser\Node\Stmt\Class_ $class, string $propertyName) : bool
{ {
$property = $class->getProperty($propertyName); $property = $class->getProperty($propertyName);
return $property instanceof \PhpParser\Node\Stmt\Property && $property->props[0]->default; if (!$property instanceof \PhpParser\Node\Stmt\Property) {
return \false;
}
return $property->props[0]->default instanceof \PhpParser\Node\Expr;
} }
private function isInConstructWithPropertyChanging(\PhpParser\Node\Stmt\ClassMethod $classMethod, string $propertyName) : bool private function isInConstructWithPropertyChanging(\PhpParser\Node\Stmt\ClassMethod $classMethod, string $propertyName) : bool
{ {
@ -124,7 +128,7 @@ final class PropertyFetchByMethodAnalyzer
private function verifyPropertyReadInIf(?bool $isPropertyReadInIf, \PhpParser\Node $node, string $propertyName) : ?bool private function verifyPropertyReadInIf(?bool $isPropertyReadInIf, \PhpParser\Node $node, string $propertyName) : ?bool
{ {
if ($node instanceof \PhpParser\Node\Stmt\If_) { if ($node instanceof \PhpParser\Node\Stmt\If_) {
$isPropertyReadInIf = $this->refactorIf($node, $propertyName); return $this->refactorIf($node, $propertyName);
} }
return $isPropertyReadInIf; return $isPropertyReadInIf;
} }

View File

@ -313,7 +313,7 @@ final class ClassRenamer
$scope = $classLike->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE); $scope = $classLike->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
$classLike->implements = \array_unique($classLike->implements); $classLike->implements = \array_unique($classLike->implements);
foreach ($classLike->implements as $key => $implementName) { foreach ($classLike->implements as $key => $implementName) {
$virtualNode = $implementName->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE); $virtualNode = (bool) $implementName->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE, \false);
if (!$virtualNode) { if (!$virtualNode) {
continue; continue;
} }

View File

@ -16,11 +16,11 @@ final class VersionResolver
/** /**
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '6340d263f40c31eae44c1c5c057eff253c002921'; public const PACKAGE_VERSION = '185ee1b473147fd620d3da2c42eb52b1756f2a18';
/** /**
* @var string * @var string
*/ */
public const RELEASE_DATE = '2021-11-28 18:19:45'; public const RELEASE_DATE = '2021-11-28 18:48:56';
public static function resolvePackageVersion() : string public static function resolvePackageVersion() : string
{ {
$process = new \RectorPrefix20211128\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); $process = new \RectorPrefix20211128\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'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitb0edd70802cd8b0614e2d4b03138e349::getLoader(); return ComposerAutoloaderInit318ac5f3e8b1ab124e631699d7247d22::getLoader();

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitb0edd70802cd8b0614e2d4b03138e349 class ComposerStaticInit318ac5f3e8b1ab124e631699d7247d22
{ {
public static $files = array ( public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3770,9 +3770,9 @@ class ComposerStaticInitb0edd70802cd8b0614e2d4b03138e349
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 = ComposerStaticInitb0edd70802cd8b0614e2d4b03138e349::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit318ac5f3e8b1ab124e631699d7247d22::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb0edd70802cd8b0614e2d4b03138e349::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit318ac5f3e8b1ab124e631699d7247d22::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb0edd70802cd8b0614e2d4b03138e349::$classMap; $loader->classMap = ComposerStaticInit318ac5f3e8b1ab124e631699d7247d22::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211128\AutoloadIncluder'); spl_autoload_call('RectorPrefix20211128\AutoloadIncluder');
} }
if (!class_exists('ComposerAutoloaderInitb0edd70802cd8b0614e2d4b03138e349', false) && !interface_exists('ComposerAutoloaderInitb0edd70802cd8b0614e2d4b03138e349', false) && !trait_exists('ComposerAutoloaderInitb0edd70802cd8b0614e2d4b03138e349', false)) { if (!class_exists('ComposerAutoloaderInit318ac5f3e8b1ab124e631699d7247d22', false) && !interface_exists('ComposerAutoloaderInit318ac5f3e8b1ab124e631699d7247d22', false) && !trait_exists('ComposerAutoloaderInit318ac5f3e8b1ab124e631699d7247d22', false)) {
spl_autoload_call('RectorPrefix20211128\ComposerAutoloaderInitb0edd70802cd8b0614e2d4b03138e349'); spl_autoload_call('RectorPrefix20211128\ComposerAutoloaderInit318ac5f3e8b1ab124e631699d7247d22');
} }
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)) { 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('RectorPrefix20211128\Helmich\TypoScriptParser\Parser\AST\Statement'); spl_autoload_call('RectorPrefix20211128\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211128\print_node(...func_get_args()); return \RectorPrefix20211128\print_node(...func_get_args());
} }
} }
if (!function_exists('composerRequireb0edd70802cd8b0614e2d4b03138e349')) { if (!function_exists('composerRequire318ac5f3e8b1ab124e631699d7247d22')) {
function composerRequireb0edd70802cd8b0614e2d4b03138e349() { function composerRequire318ac5f3e8b1ab124e631699d7247d22() {
return \RectorPrefix20211128\composerRequireb0edd70802cd8b0614e2d4b03138e349(...func_get_args()); return \RectorPrefix20211128\composerRequire318ac5f3e8b1ab124e631699d7247d22(...func_get_args());
} }
} }
if (!function_exists('scanPath')) { if (!function_exists('scanPath')) {