move stubs to composer-autoload (#5890)

* move stubs to composer-autoload

* remove duplicate classes

* apply Rector
This commit is contained in:
Tomas Votruba 2021-03-18 02:10:01 +01:00 committed by GitHub
parent c815334bed
commit 37eb07af6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
83 changed files with 115 additions and 298 deletions

View File

@ -34,9 +34,9 @@
"doctrine/annotations": "^1.12",
"doctrine/inflector": "^2.0",
"jean85/pretty-package-versions": "^1.5.1|^2.0.1",
"nette/robot-loader": "^3.2 <=3.3.1",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.10.4",
"nette/robot-loader": "^3.4",
"phpstan/phpdoc-parser": "^0.4.12",
"phpstan/phpstan": "^0.12.81",
"phpstan/phpstan-phpunit": "^0.12.18",
@ -99,6 +99,7 @@
"Rector\\Utils\\DoctrineAnnotationParserSyncer\\": "utils/doctrine-annotation-parser-syncer/src"
},
"classmap": [
"stubs/Annotations",
"rules-tests/Autodiscovery/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected",
"rules-tests/Autodiscovery/Rector/FileNode/MoveServicesBySuffixToDirectoryRector/Expected",
"rules-tests/CakePHP/Rector/FileWithoutNamespace/ImplicitShortClassNameUseStatementRector/Source",
@ -109,6 +110,9 @@
"rules-tests/Symfony4/Rector/MethodCall/ContainerGetToConstructorInjectionRector/Source"
],
"files": [
"stubs/Symfony/Component/Form/FormTypeInterface.php",
"stubs/Doctrine/Persistence/ObjectManager.php",
"stubs/Doctrine/Common/Persistence/ObjectManager.php",
"vendor/nette/forms/src/Forms/Controls/SubmitButton.php",
"rules-tests/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector/Source/ShortClassOnly.php",
"rules-tests/DeadCode/Rector/MethodCall/RemoveDefaultArgumentValueRector/Source/UserDefined.php",

View File

@ -582,3 +582,5 @@ parameters:
message: '#Cannot cast array<string\>\|string\|null to string#'
paths:
- utils/compiler/src/Command/DowngradePathsCommand.php
- '#Method Rector\\Testing\\Finder\\RectorsFinder\:\:findClassesInDirectoriesByName\(\) should return array<class\-string\> but returns array<int, string\>#'

View File

@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class OpenSourceRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource');
}
protected function provideConfigFilePath(): string
{
return __DIR__ . '/config/projet_open_source.php';
}
}

View File

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\ProjectType;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);
$services = $containerConfigurator->services();
$services->set(RemoveUnusedPublicMethodRector::class);
};

View File

@ -19,6 +19,9 @@ final class MigrateAtToConsecutiveExpectationsRectorTest extends AbstractRectorT
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');

View File

@ -16,6 +16,9 @@ use Rector\PHPUnit\ValueObject\ExpectationMockCollection;
final class ExpectationAnalyzer
{
/**
* @var string[]
*/
private const PROCESSABLE_WILL_STATEMENTS = [
'will',
'willReturn',
@ -74,90 +77,99 @@ final class ExpectationAnalyzer
$atArg = $expectsValue->args[0];
$atValue = $atArg->value;
if ($atValue instanceof LNumber && $expects->var instanceof Variable) {
$expectationMockCollection->add(
new ExpectationMock(
$expects->var,
$method->args,
$atValue->value,
$this->getWill($expr),
$this->getWithArgs($method->var),
$stmt
)
);
if (! $atValue instanceof LNumber) {
continue;
}
if (! $expects->var instanceof Variable) {
continue;
}
$expectationMockCollection->add(
new ExpectationMock(
$expects->var,
$method->args,
$atValue->value,
$this->getWill($expr),
$this->getWithArgs($method->var),
$stmt
)
);
}
return $expectationMockCollection;
}
public function isValidExpectsCall(MethodCall $expr): bool
public function isValidExpectsCall(MethodCall $methodCall): bool
{
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($expr, 'expects')) {
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($methodCall, 'expects')) {
return false;
}
if (count($expr->args) !== 1) {
if (count($methodCall->args) !== 1) {
return false;
}
return true;
}
public function isValidAtCall(MethodCall $expr): bool
public function isValidAtCall(MethodCall $methodCall): bool
{
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($expr, 'at')) {
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($methodCall, 'at')) {
return false;
}
if (count($expr->args) !== 1) {
if (count($methodCall->args) !== 1) {
return false;
}
return true;
}
private function getMethod(MethodCall $expr): MethodCall
private function getMethod(MethodCall $methodCall): MethodCall
{
if ($this->testsNodeAnalyzer->isPHPUnitMethodNames(
$expr,
$methodCall,
self::PROCESSABLE_WILL_STATEMENTS
) && $expr->var instanceof MethodCall) {
return $expr->var;
) && $methodCall->var instanceof MethodCall) {
return $methodCall->var;
}
return $expr;
return $methodCall;
}
private function getWill(MethodCall $expr): ?Expr
private function getWill(MethodCall $methodCall): ?Expr
{
if (! $this->testsNodeAnalyzer->isPHPUnitMethodNames($expr, self::PROCESSABLE_WILL_STATEMENTS)) {
if (! $this->testsNodeAnalyzer->isPHPUnitMethodNames($methodCall, self::PROCESSABLE_WILL_STATEMENTS)) {
return null;
}
return $this->consecutiveAssertionFactory->createWillReturn($expr);
return $this->consecutiveAssertionFactory->createWillReturn($methodCall);
}
private function getExpects(Expr $maybeWith, MethodCall $method): Expr
private function getExpects(Expr $expr, MethodCall $methodCall): Expr
{
if ($this->testsNodeAnalyzer->isPHPUnitMethodName($maybeWith, 'with') && $maybeWith instanceof MethodCall) {
return $maybeWith->var;
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($expr, 'with')) {
return $methodCall->var;
}
return $method->var;
if (! $expr instanceof MethodCall) {
return $methodCall->var;
}
return $expr->var;
}
/**
* @return array<int, Expr|null>
*/
private function getWithArgs(Expr $maybeWith): array
private function getWithArgs(Expr $expr): array
{
if ($this->testsNodeAnalyzer->isPHPUnitMethodName($maybeWith, 'with') && $maybeWith instanceof MethodCall) {
return array_map(static function (Arg $arg) {
return $arg->value;
}, $maybeWith->args);
if (! $this->testsNodeAnalyzer->isPHPUnitMethodName($expr, 'with')) {
return [null];
}
return [null];
if (! $expr instanceof MethodCall) {
return [null];
}
return array_map(static function (Arg $arg): Expr {
return $arg->value;
}, $expr->args);
}
}

View File

@ -5,9 +5,11 @@ namespace Rector\PHPUnit\NodeFactory;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
@ -17,6 +19,9 @@ use Rector\PHPUnit\ValueObject\ExpectationMockCollection;
final class ConsecutiveAssertionFactory
{
/**
* @var array<string, string>
*/
private const REPLACE_WILL_MAP = [
'willReturnMap' => 'returnValueMap',
'willReturnArgument' => 'returnArgument',
@ -29,14 +34,14 @@ final class ConsecutiveAssertionFactory
): MethodCall {
$expectationMocks = $expectationMockCollection->getExpectationMocks();
$var = $expectationMocks[0]->getExpectationVariable();
$variable = $expectationMocks[0]->getExpectationVariable();
$methodArguments = $expectationMocks[0]->getMethodArguments();
$expectationMocks = $this->sortExpectationMocksByIndex($expectationMocks);
if (! $expectationMockCollection->hasReturnValues()) {
return $this->createWithConsecutive(
$this->createMethod($var, $methodArguments),
$this->createMethod($variable, $methodArguments),
$this->createWithArgs($expectationMocks)
);
}
@ -44,7 +49,7 @@ final class ConsecutiveAssertionFactory
if ($expectationMockCollection->hasWithValues()) {
return $this->createWillReturnOnConsecutiveCalls(
$this->createWithConsecutive(
$this->createMethod($var, $methodArguments),
$this->createMethod($variable, $methodArguments),
$this->createWithArgs($expectationMocks)
),
$this->createReturnArgs($expectationMocks)
@ -52,7 +57,7 @@ final class ConsecutiveAssertionFactory
}
return $this->createWillReturnOnConsecutiveCalls(
$this->createMethod($var, $methodArguments),
$this->createMethod($variable, $methodArguments),
$this->createReturnArgs($expectationMocks)
);
}
@ -113,7 +118,7 @@ final class ConsecutiveAssertionFactory
*/
private function createReturnArgs(array $expectationMocks): array
{
return array_map(static function (ExpectationMock $expectationMock) {
return array_map(static function (ExpectationMock $expectationMock): Arg {
return new Arg($expectationMock->getReturn() ?: new ConstFetch(new Name('null')));
}, $expectationMocks);
}
@ -124,11 +129,11 @@ final class ConsecutiveAssertionFactory
*/
private function createWithArgs(array $expectationMocks): array
{
return array_map(static function (ExpectationMock $expectationMock) {
$arrayItems = array_map(static function (?Expr $expr) {
return array_map(static function (ExpectationMock $expectationMock): Arg {
$arrayItems = array_map(static function (?Expr $expr): ArrayItem {
return new ArrayItem($expr ?: new ConstFetch(new Name('null')));
}, $expectationMock->getWithArguments());
return new Arg(new Expr\Array_($arrayItems));
return new Arg(new Array_($arrayItems));
}, $expectationMocks);
}
@ -137,9 +142,9 @@ final class ConsecutiveAssertionFactory
return $this->createMethodCall(new Variable('this'), 'returnSelf', []);
}
private function createWillReturnReference(MethodCall $methodCall): Expr\New_
private function createWillReturnReference(MethodCall $methodCall): New_
{
return new Expr\New_(
return new New_(
new FullyQualified('PHPUnit\Framework\MockObject\Stub\ReturnReference'),
[new Arg($methodCall->args[0]->value)]
);
@ -170,7 +175,7 @@ final class ConsecutiveAssertionFactory
{
usort(
$expectationMocks,
static function (ExpectationMock $expectationMockA, ExpectationMock $expectationMockB) {
static function (ExpectationMock $expectationMockA, ExpectationMock $expectationMockB): int {
return $expectationMockA->getIndex() > $expectationMockB->getIndex() ? 1 : -1;
}
);

View File

@ -11,7 +11,6 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\ExpectationAnalyzer;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\PHPUnit\NodeFactory\ConsecutiveAssertionFactory;
use Rector\PHPUnit\ValueObject\ExpectationMock;
use Rector\PHPUnit\ValueObject\ExpectationMockCollection;
@ -28,11 +27,6 @@ final class MigrateAtToConsecutiveExpectationsRector extends AbstractRector
*/
private $consecutiveAssertionFactory;
/**
* @var TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @var ExpectationAnalyzer
*/
@ -40,11 +34,9 @@ final class MigrateAtToConsecutiveExpectationsRector extends AbstractRector
public function __construct(
ConsecutiveAssertionFactory $consecutiveAssertionFactory,
TestsNodeAnalyzer $testsNodeAnalyzer,
ExpectationAnalyzer $expectationAnalyzer
) {
$this->consecutiveAssertionFactory = $consecutiveAssertionFactory;
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->expectationAnalyzer = $expectationAnalyzer;
}
@ -88,7 +80,7 @@ CODE_SAMPLE
return null;
}
$expressions = array_filter($stmts, function (Stmt $expr) {
$expressions = array_filter($stmts, function (Stmt $expr): bool {
return $expr instanceof Expression && $expr->expr instanceof MethodCall;
});
@ -117,7 +109,7 @@ CODE_SAMPLE
private function fillMissingAtIndexes(
ExpectationMockCollection $expectationMockCollection
): ExpectationMockCollection {
$var = $expectationMockCollection->getExpectationMocks()[0]
$variable = $expectationMockCollection->getExpectationMocks()[0]
->getExpectationVariable();
// 0,1,2,3,4
@ -135,7 +127,7 @@ CODE_SAMPLE
// 0,1,2
if ($expectationMockCollection->getLowestAtIndex() !== 0) {
for ($i = 0; $i < $expectationMockCollection->getLowestAtIndex(); ++$i) {
$expectationMockCollection->add(new ExpectationMock($var, [], $i, null, [], null));
$expectationMockCollection->add(new ExpectationMock($variable, [], $i, null, [], null));
}
}
@ -146,7 +138,7 @@ CODE_SAMPLE
$existingIndexes = array_column($expectationMockCollection->getExpectationMocks(), 'index');
for ($i = 1; $i < $expectationMockCollection->getHighestAtIndex(); ++$i) {
if (! in_array($i, $existingIndexes, true)) {
$expectationMockCollection->add(new ExpectationMock($var, [], $i, null, [], null));
$expectationMockCollection->add(new ExpectationMock($variable, [], $i, null, [], null));
}
}
}
@ -159,15 +151,15 @@ CODE_SAMPLE
return;
}
$endLines = array_map(static function (ExpectationMock $expectationMock) {
$originalExpression = $expectationMock->originalExpression();
return $originalExpression === null ? 0 : $originalExpression->getEndLine();
$endLines = array_map(static function (ExpectationMock $expectationMock): int {
$originalExpression = $expectationMock->getOriginalExpression();
return ! $originalExpression instanceof Expression ? 0 : $originalExpression->getEndLine();
}, $expectationMockCollection->getExpectationMocks());
$max = max($endLines);
foreach ($expectationMockCollection->getExpectationMocks() as $expectationMock) {
$originalExpression = $expectationMock->originalExpression();
if ($originalExpression === null) {
$originalExpression = $expectationMock->getOriginalExpression();
if (! $originalExpression instanceof Expression) {
continue;
}
if ($max > $originalExpression->getEndLine()) {
@ -191,12 +183,7 @@ CODE_SAMPLE
if ($expectationMockCollection->hasMissingAtIndexes()) {
return true;
}
if ($expectationMockCollection->hasMissingReturnValues()) {
return true;
}
return false;
return $expectationMockCollection->hasMissingReturnValues();
}
/**

View File

@ -37,7 +37,7 @@ final class PHPUnitTestCaseClassesProvider
$robotLoader->rebuild();
foreach (array_keys($robotLoader->getIndexedClasses()) as $className) {
$this->phpUnitTestCaseClasses[] = (string) $className;
$this->phpUnitTestCaseClasses[] = $className;
}
return $this->phpUnitTestCaseClasses;

View File

@ -18,7 +18,7 @@ final class ExpectationMock
/**
* @var Arg[]
*/
private $methodArguments;
private $methodArguments = [];
/**
* @var int
@ -28,12 +28,12 @@ final class ExpectationMock
/**
* @var ?Expr
*/
private $return;
private $expr;
/**
* @var array<int, null|Expr>
*/
private $withArguments;
private $withArguments = [];
/**
* @var Expression|null
@ -48,14 +48,14 @@ final class ExpectationMock
Variable $expectationVariable,
array $methodArguments,
int $index,
?Expr $return,
?Expr $expr,
array $withArguments,
?Expression $originalExpression
) {
$this->expectationVariable = $expectationVariable;
$this->methodArguments = $methodArguments;
$this->index = $index;
$this->return = $return;
$this->expr = $expr;
$this->withArguments = $withArguments;
$this->originalExpression = $originalExpression;
}
@ -80,7 +80,7 @@ final class ExpectationMock
public function getReturn(): ?Expr
{
return $this->return;
return $this->expr;
}
/**
@ -91,7 +91,7 @@ final class ExpectationMock
return $this->withArguments;
}
public function originalExpression(): ?Expression
public function getOriginalExpression(): ?Expression
{
return $this->originalExpression;
}

View File

@ -22,7 +22,7 @@ final class ExpectationMockCollection
public function hasExpectationMocks(): bool
{
return count($this->expectationMocks) > 0;
return $this->expectationMocks !== [];
}
public function add(ExpectationMock $expectationMock): void
@ -36,9 +36,9 @@ final class ExpectationMockCollection
return 0;
}
$indexes = array_map(static function (ExpectationMock $expectationMock) {
$indexes = array_map(static function (ExpectationMock $expectationMock): int {
return $expectationMock->getIndex();
}, $this->getExpectationMocks());
}, $this->expectationMocks);
return max($indexes) ?: 0;
}
@ -48,9 +48,9 @@ final class ExpectationMockCollection
return 0;
}
$indexes = array_map(static function (ExpectationMock $expectationMock) {
$indexes = array_map(static function (ExpectationMock $expectationMock): int {
return $expectationMock->getIndex();
}, $this->getExpectationMocks());
}, $this->expectationMocks);
return min($indexes) ?: 0;
}
@ -58,7 +58,7 @@ final class ExpectationMockCollection
{
$highestAtIndex = $this->getHighestAtIndex();
$lowestAtIndex = $this->getLowestAtIndex();
return ($highestAtIndex - $lowestAtIndex + 1) !== count($this->getExpectationMocks());
return ($highestAtIndex - $lowestAtIndex + 1) !== count($this->expectationMocks);
}
public function hasMissingAtIndexes(): bool
@ -66,23 +66,17 @@ final class ExpectationMockCollection
if ($this->getLowestAtIndex() !== 0) {
return true;
}
if ($this->isMissingAtIndexBetweenHighestAndLowest()) {
return true;
}
return false;
return $this->isMissingAtIndexBetweenHighestAndLowest();
}
public function hasWithValues(): bool
{
foreach ($this->getExpectationMocks() as $expectationMock) {
if (
count($expectationMock->getWithArguments()) > 1
|| (
count($expectationMock->getWithArguments()) === 1
&& $expectationMock->getWithArguments()[0] !== null
)) {
foreach ($this->expectationMocks as $expectationMock) {
if (count($expectationMock->getWithArguments()) > 1) {
return true;
}
if (count($expectationMock->getWithArguments()) === 1
&& $expectationMock->getWithArguments()[0] !== null) {
return true;
}
}
@ -92,7 +86,7 @@ final class ExpectationMockCollection
public function hasReturnValues(): bool
{
foreach ($this->getExpectationMocks() as $expectationMock) {
foreach ($this->expectationMocks as $expectationMock) {
if ($expectationMock->getReturn() !== null) {
return true;
}
@ -103,7 +97,7 @@ final class ExpectationMockCollection
public function hasMissingReturnValues(): bool
{
foreach ($this->getExpectationMocks() as $expectationMock) {
foreach ($this->expectationMocks as $expectationMock) {
if ($expectationMock->getReturn() === null) {
return true;
}
@ -115,7 +109,7 @@ final class ExpectationMockCollection
public function isExpectedMethodAlwaysTheSame(): bool
{
$previousMethod = '';
foreach ($this->getExpectationMocks() as $expectationMock) {
foreach ($this->expectationMocks as $expectationMock) {
$methodArgument = $expectationMock->getMethodArguments()[0];
if ($methodArgument !== null && $methodArgument->value instanceof String_) {
if ($previousMethod === '') {

View File

@ -11,7 +11,6 @@ use Rector\Core\PhpParser\Node\CustomNode\FileNode;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\PhpParser\Parser\Parser;
use Rector\Core\PhpParser\Printer\FormatPerservingPrinter;
use Rector\Core\Stubs\StubLoader;
use Rector\Core\ValueObject\Application\ParsedStmtsAndTokens;
use Rector\NodeTypeResolver\FileSystem\CurrentFileInfoProvider;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
@ -50,11 +49,6 @@ final class FileProcessor
*/
private $currentFileInfoProvider;
/**
* @var StubLoader
*/
private $stubLoader;
/**
* @var AffectedFilesCollector
*/
@ -79,7 +73,6 @@ final class FileProcessor
Parser $parser,
PostFileProcessor $postFileProcessor,
RectorNodeTraverser $rectorNodeTraverser,
StubLoader $stubLoader,
TokensByFilePathStorage $tokensByFilePathStorage
) {
$this->formatPerservingPrinter = $formatPerservingPrinter;
@ -88,7 +81,6 @@ final class FileProcessor
$this->rectorNodeTraverser = $rectorNodeTraverser;
$this->nodeScopeAndMetadataDecorator = $nodeScopeAndMetadataDecorator;
$this->currentFileInfoProvider = $currentFileInfoProvider;
$this->stubLoader = $stubLoader;
$this->affectedFilesCollector = $affectedFilesCollector;
$this->postFileProcessor = $postFileProcessor;
$this->tokensByFilePathStorage = $tokensByFilePathStorage;
@ -127,7 +119,6 @@ final class FileProcessor
public function refactor(SmartFileInfo $smartFileInfo): void
{
$this->stubLoader->loadStubs();
$this->currentFileInfoProvider->setCurrentFileInfo($smartFileInfo);
$this->makeSureFileIsParsed($smartFileInfo);

View File

@ -47,6 +47,10 @@ final class AdditionalAutoloader
}
$autoloadPaths = $this->parameterProvider->provideArrayParameter(Option::AUTOLOAD_PATHS);
if ($autoloadPaths === []) {
return;
}
$this->dynamicSourceLocatorDecorator->addPaths($autoloadPaths);
}

View File

@ -14,7 +14,6 @@ use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\ValueObject\MethodName;
use Rector\NodeNameResolver\NodeNameResolver;
@ -28,11 +27,6 @@ final class ClassMethodManipulator
*/
private $betterNodeFinder;
/**
* @var NodeComparator
*/
private $nodeComparator;
/**
* @var NodeTypeResolver
*/
@ -43,23 +37,14 @@ final class ClassMethodManipulator
*/
private $nodeNameResolver;
/**
* @var FuncCallManipulator
*/
private $funcCallManipulator;
public function __construct(
BetterNodeFinder $betterNodeFinder,
FuncCallManipulator $funcCallManipulator,
NodeNameResolver $nodeNameResolver,
NodeTypeResolver $nodeTypeResolver,
NodeComparator $nodeComparator
NodeTypeResolver $nodeTypeResolver
) {
$this->betterNodeFinder = $betterNodeFinder;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->funcCallManipulator = $funcCallManipulator;
$this->nodeComparator = $nodeComparator;
}
public function isNamedConstructor(ClassMethod $classMethod): bool

View File

@ -1,59 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Stubs;
use Nette\Loaders\RobotLoader;
final class StubLoader
{
/**
* @var bool
*/
private $areStubsLoaded = false;
/**
* Load stubs after composer autoload is loaded + rector "process <src>" is loaded,
* so it is loaded only if the classes are really missing
*/
public function loadStubs(): void
{
if ($this->areStubsLoaded) {
return;
}
// these have to be loaded, as doctrine annotation parser only works with included files
$stubDirectories = [
__DIR__ . '/../../stubs/DI/Annotation',
__DIR__ . '/../../stubs/Doctrine/ORM/Mapping',
__DIR__ . '/../../stubs/Gedmo/Mapping/Annotation',
__DIR__ . '/../../stubs/JMS',
__DIR__ . '/../../stubs/Sensio/Bundle/FrameworkExtraBundle/Configuration',
__DIR__ . '/../../stubs/Symfony/Bundle/FrameworkExtraBundle/Configuration',
__DIR__ . '/../../stubs/Symfony/Bridge/Doctrine/Validator/Constraints',
__DIR__ . '/../../stubs/Symfony/Component/Validator',
__DIR__ . '/../../stubs/Symfony/Component/Form',
__DIR__ . '/../../stubs/Symfony/Component/Routing/Annotation',
__DIR__ . '/../../stubs/Tester',
];
// @see https://github.com/rectorphp/rector/issues/1899
$stubDirectories = array_filter($stubDirectories, function (string $stubDirectory): bool {
return file_exists($stubDirectory);
});
// stubs might not exists on composer install, to prevent PHPStorm duplicated confusion
if ($stubDirectories === []) {
return;
}
$robotLoader = new RobotLoader();
$robotLoader->addDirectory(...$stubDirectories);
$robotLoader->setTempDirectory(sys_get_temp_dir() . '/rector/stubs');
$robotLoader->register();
$robotLoader->rebuild();
$this->areStubsLoaded = true;
}
}

View File

@ -10,7 +10,5 @@ if (interface_exists('Doctrine\Common\Persistence\ObjectManager')) {
interface ObjectManager
{
public function getRepository(): \Doctrine\ORM\EntityRepository
{
}
public function getRepository(): \Doctrine\ORM\EntityRepository;
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Symfony\Component\Console\Helper;
if (class_exists('Symfony\Component\Console\Helper')) {
return;
}
class HelperSet
{
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Symfony\Component\DependencyInjection;
if (class_exists('Symfony\Component\DependencyInjection\ContainerBuilder')) {
return;
}
class ContainerBuilder
{
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Symfony\Contracts\EventDispatcher;
if (interface_exists('Symfony\Contracts\EventDispatcher\EventDispatcherInterface')) {
return;
}
interface EventDispatcherInterface
{
}

View File

@ -1,14 +0,0 @@
<?php
declare(strict_types=1);
namespace Symfony\Component\OptionsResolver;
if (class_exists('Symfony\Component\OptionsResolver\OptionsResolver')) {
return;
}
class OptionsResolver
{
}

View File

@ -3,7 +3,6 @@
declare(strict_types=1);
use Rector\Core\Stubs\PHPStanStubLoader;
use Rector\Core\Stubs\StubLoader;
use Tracy\Debugger;
require_once __DIR__ . '/../vendor/autoload.php';
@ -14,9 +13,6 @@ error_reporting(E_ALL ^ E_DEPRECATED);
// performance boost
gc_disable();
$stubLoader = new StubLoader();
$stubLoader->loadStubs();
$phpStanStubLoader = new PHPStanStubLoader();
$phpStanStubLoader->loadStubs();