Skip to content

Commit

Permalink
Remove propperty to add collector, add them directly or as a construc…
Browse files Browse the repository at this point in the history
…tor dependency (#4131)

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Jun 9, 2023
1 parent 2d13bc9 commit 390730a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 198 deletions.
4 changes: 0 additions & 4 deletions easy-ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use PHPStan\PhpDocParser\Parser\TypeParser;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
Expand All @@ -29,15 +28,13 @@
use Rector\Testing\PHPUnit\AbstractTestCase;
use Rector\TypeDeclaration\Contract\PHPStan\TypeWithClassTypeSpecifierInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symplify\EasyCI\Config\EasyCIConfig;

return static function (EasyCIConfig $easyCiConfig): void {
$easyCiConfig->typesToSkip([
AttributeDecoratorInterface::class,
ArrayItemNode::class,
PhpDocNodeDecoratorInterface::class,
Command::class,
Application::class,
RectorInterface::class,
TypeToCallReflectionResolverInterface::class,
Expand All @@ -51,7 +48,6 @@
NodeTypeResolverInterface::class,
ReadNodeAnalyzerInterface::class,
SetListInterface::class,
TypeParser::class,
RectorBetterReflectionSourceLocatorFactory::class,
AbstractTestCase::class,
PHPStanServicesFactory::class,
Expand Down
4 changes: 0 additions & 4 deletions packages/PostRector/Application/PostFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\PostRector\Rector\ClassRenamingPostRector;
use Rector\PostRector\Rector\NameImportingPostRector;
use Rector\PostRector\Rector\PropertyAddingPostRector;
use Rector\PostRector\Rector\UnusedImportRemovingPostRector;
use Rector\PostRector\Rector\UseAddingPostRector;
use Rector\Skipper\Skipper\Skipper;
Expand All @@ -32,13 +31,10 @@ public function __construct(
// set order here
UseAddingPostRector $useAddingPostRector,
NameImportingPostRector $nameImportingPostRector,
PropertyAddingPostRector $propertyAddingPostRector,
ClassRenamingPostRector $classRenamingPostRector,
UnusedImportRemovingPostRector $unusedImportRemovingPostRector,
) {
$this->postRectors = [
// priority: 900
$propertyAddingPostRector,
// priority: 650
$classRenamingPostRector,
// priority: 600
Expand Down
48 changes: 0 additions & 48 deletions packages/PostRector/Collector/PropertyToAddCollector.php

This file was deleted.

80 changes: 0 additions & 80 deletions packages/PostRector/Rector/PropertyAddingPostRector.php

This file was deleted.

3 changes: 2 additions & 1 deletion packages/PostRector/ValueObject/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Rector\PostRector\ValueObject;

use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\Type;

final class PropertyMetadata
{
public function __construct(
private readonly string $name,
private readonly ?Type $type,
private readonly int $flags
private readonly int $flags = Class_::MODIFIER_PRIVATE,
) {
}

Expand Down
15 changes: 1 addition & 14 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ parameters:
# broken in PHPStan https://github.com/rectorphp/rector/runs/1305002460#step:5:56
- packages/Testing/PHPUnit/*.php

# demo rule
- tests/Issues/AliasedImportDouble/Rector/ClassMethod/AddAliasImportRector.php

# complex printer
- '*tests/Rector/MethodCall/RenameMethodRector/**/SomeClass.php'
# tests files
Expand All @@ -54,8 +51,6 @@ parameters:
- '*tests/*/Source/*'
- '*tests/*/Source*'
- '*tests/*/Fixture*'
# part of composer
- '*/tests/Rector/Psr4/MultipleClassFileToPsr4ClassesRector/Expected/Just*ExceptionWithoutNamespace.php'

# tests
- tests/DependencyInjection/config
Expand Down Expand Up @@ -264,11 +259,6 @@ parameters:
# impossible to validate json string is a class-string
- '#Parameter \#1 \$rectorClass of class Rector\\ChangesReporting\\ValueObject\\RectorWithLineChange constructor expects class\-string<Rector\\Core\\Contract\\Rector\\RectorInterface\>\|Rector\\Core\\Contract\\Rector\\RectorInterface, string given#'

-
message: '#Only booleans are allowed in an if condition, array\|null given#'
paths:
- rules/Naming/Naming/PropertyNaming.php

# mapper re-use
- '#Parameter \#1 \$type of method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ObjectWithoutClassTypeMapper\:\:mapToPhpParserNode\(\) expects PHPStan\\Type\\ObjectWithoutClassType, PHPStan\\Type\\Accessory\\Has(Property|Method)Type given#'

Expand Down Expand Up @@ -329,7 +319,6 @@ parameters:
# for config class reflection
- src/Bootstrap/ExtensionConfigResolver.php
- src/DependencyInjection/CompilerPass/AutowireArrayParameterCompilerPass.php
- src/DependencyInjection/Skipper/ParameterSkipper.php
- src/DependencyInjection/DefinitionFinder.php

-
Expand Down Expand Up @@ -713,8 +702,6 @@ parameters:
- '#Call to deprecated method findParentByTypes#'
- '#Instantiation of deprecated class Rector\\Core\\DependencyInjection\\CompilerPass\\AutowireArrayParameterCompilerPass#'

# handle later
- '#Fetching class constant class of deprecated class Rector\\(.*?)#'
- '#has typehint with deprecated class Rector\\PostRector\\Collector\\PropertyToAddCollector#'
- '#Cognitive complexity for "Rector\\Transform\\Rector\\StaticCall\\StaticCallToMethodCallRector\:\:refactorWithScope\(\)" is 14, keep it under 11#'

- '#Function "class_exists\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,8 @@ private function filterOutExistingProperties(
continue;
}

$propertyMetadata = new PropertyMetadata(
$propertyToComplete,
new ObjectType($className),
Class_::MODIFIER_PRIVATE
);
$propertyMetadata = new PropertyMetadata($propertyToComplete, new ObjectType($className));

$hasClassContextProperty = $this->propertyPresenceChecker->hasClassContextProperty(
$class,
$propertyMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\ClassDependencyManipulator;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\Naming\Naming\PropertyNaming;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PostRector\Collector\PropertyToAddCollector;
use Rector\PostRector\ValueObject\PropertyMetadata;
use Rector\Transform\NodeFactory\PropertyFetchFactory;
use Rector\Transform\NodeTypeAnalyzer\TypeProvidingExprFromClassResolver;
Expand All @@ -28,7 +28,7 @@ public function __construct(
private readonly NodeNameResolver $nodeNameResolver,
private readonly NodeFactory $nodeFactory,
private readonly PropertyFetchFactory $propertyFetchFactory,
private readonly PropertyToAddCollector $propertyToAddCollector
private readonly ClassDependencyManipulator $classDependencyManipulator,
) {
}

Expand All @@ -52,8 +52,10 @@ public function matchTypeProvidingExpr(
}

$propertyName = $this->propertyNaming->fqnToVariableName($objectType);
$propertyMetadata = new PropertyMetadata($propertyName, $objectType, Class_::MODIFIER_PRIVATE);
$this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
$this->classDependencyManipulator->addConstructorDependency(
$class,
new PropertyMetadata($propertyName, $objectType)
);

return $this->propertyFetchFactory->createFromType($objectType);
}
Expand Down
Loading

0 comments on commit 390730a

Please sign in to comment.