Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DX] Improve configuration objects + allow Symfony 6 #1430

Merged
merged 5 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"rector/rector-phpunit": "^0.11.23",
"rector/rector-symfony": "^0.11.43",
"sebastian/diff": "^4.0.4",
"ssch/typo3-rector": "^0.11.31",
"symfony/console": "^5.4|^6.0",
"ssch/typo3-rector": "dev-main",
"symfony/console": "^6.0",
"symfony/contracts": "^2.5|^3.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/finder": "^5.4|^6.0",
"symfony/process": "^5.4|^6.0",
"symfony/string": "^5.4|^6.0",
"symfony/finder": "^6.0",
"symfony/process": "^6.0",
"symfony/string": "^6.0",
"symfony/yaml": "^5.4|^6.0",
"symplify/astral": "^10.0.2",
"symplify/autowire-array-parameter": "^10.0.2",
Expand All @@ -58,10 +58,11 @@
"symplify/vendor-patches": "^10.0.2",
"tracy/tracy": "^2.8",
"webmozart/assert": "^1.10",
"helmich/typo3-typoscript-parser": "dev-master#0ccb3a6 as 2.3.1"
"helmich/typo3-typoscript-parser": "dev-master#0ccb3a6"
},
"require-dev": {
"brianium/paratest": "^6.3",
"friendsofphp/php-cs-fixer": "dev-master as 3.3",
"nategood/httpful": "^0.3.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-nette": "^1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/NodeCollector/ValueObject/ArrayCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\NodeCollector\ValueObject;

use PhpParser\Node\Expr;
use Rector\Core\Validation\RectorAssert;

final class ArrayCallable
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $class,
private readonly string $method
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\NodeCollector\ValueObject;

use PhpParser\Node\Expr;
use Rector\Core\Validation\RectorAssert;

final class ArrayCallableDynamicMethod
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $class,
private readonly Expr $method
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public function refactor(Node $node): MethodCall | StaticCall | ClassMethod
public function configure(array $configuration): void
{
$replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? $configuration;
Assert::isArray($replacedArguments);
Assert::allIsAOf($replacedArguments, ReplaceArgumentDefaultValue::class);

$this->replacedArguments = $replacedArguments;
}
}
2 changes: 2 additions & 0 deletions rules/Arguments/ValueObject/ArgumentAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Core\Validation\RectorAssert;

final class ArgumentAdder
{
Expand All @@ -21,6 +22,7 @@ public function __construct(
private readonly Type | null $argumentType = null,
private readonly ?string $scope = null
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
3 changes: 3 additions & 0 deletions rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\Type\ObjectType;
use Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface;
use Rector\Core\Validation\RectorAssert;

final class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueInterface
{
Expand All @@ -15,6 +16,7 @@ final class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueIn
final public const ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*';

/**
* @param int<0, max> $position
* @param mixed $valueBefore
* @param mixed $valueAfter
*/
Expand All @@ -25,6 +27,7 @@ public function __construct(
private $valueBefore,
private $valueAfter
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Privatization\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class ReplaceStringWithClassConstant
{
Expand All @@ -18,6 +19,7 @@ public function __construct(
private readonly string $classWithConstants,
private readonly bool $caseInsensitive = false
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
2 changes: 2 additions & 0 deletions rules/Removing/ValueObject/ArgumentRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Removing\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class ArgumentRemover
{
Expand All @@ -17,6 +18,7 @@ public function __construct(
private readonly int $position,
private $value
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
2 changes: 2 additions & 0 deletions rules/Renaming/ValueObject/MethodCallRename.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Renaming\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;
use Rector\Renaming\Contract\MethodCallRenameInterface;

final class MethodCallRename implements MethodCallRenameInterface
Expand All @@ -14,6 +15,7 @@ public function __construct(
private readonly string $oldMethod,
private readonly string $newMethod
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
2 changes: 2 additions & 0 deletions rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Renaming\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;
use Rector\Renaming\Contract\MethodCallRenameInterface;

final class MethodCallRenameWithArrayKey implements MethodCallRenameInterface
Expand All @@ -18,6 +19,7 @@ public function __construct(
private readonly string $newMethod,
private $arrayKey
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
2 changes: 2 additions & 0 deletions rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Transform\ValueObject;

use Rector\Core\Validation\RectorAssert;
use Rector\Transform\Contract\ValueObject\ArgumentFuncCallToMethodCallInterface;

final class ArgumentFuncCallToMethodCall implements ArgumentFuncCallToMethodCallInterface
Expand All @@ -14,6 +15,7 @@ public function __construct(
private readonly ?string $methodIfArgs = null,
private readonly ?string $methodIfNoArgs = null
) {
RectorAssert::className($class);
}

public function getFunction(): string
Expand Down
2 changes: 2 additions & 0 deletions rules/Transform/ValueObject/PropertyAssignToMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Transform\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class PropertyAssignToMethodCall
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $oldPropertyName,
private readonly string $newMethodName
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Transform\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class ReplaceParentCallByPropertyCall
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $method,
private readonly string $property
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
2 changes: 2 additions & 0 deletions rules/Transform/ValueObject/SingleToManyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Transform\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class SingleToManyMethod
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $singleMethodName,
private readonly string $manyMethodName
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
2 changes: 2 additions & 0 deletions rules/Transform/ValueObject/StaticCallToFuncCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Transform\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class StaticCallToFuncCall
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $method,
private readonly string $function
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
3 changes: 3 additions & 0 deletions rules/Transform/ValueObject/StaticCallToNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace Rector\Transform\ValueObject;

use Rector\Core\Validation\RectorAssert;

final class StaticCallToNew
{
public function __construct(
private readonly string $class,
private readonly string $method
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
3 changes: 3 additions & 0 deletions rules/Transform/ValueObject/StringToClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace Rector\Transform\ValueObject;

use Rector\Core\Validation\RectorAssert;

final class StringToClassConstant
{
public function __construct(
private readonly string $string,
private readonly string $class,
private readonly string $constant
) {
RectorAssert::className($class);
}

public function getString(): string
Expand Down
3 changes: 3 additions & 0 deletions rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

final class AddParamTypeDeclaration
{
/**
* @param int<0, max> $position
*/
public function __construct(
private readonly string $className,
private readonly string $methodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\TypeDeclaration\ValueObject;

use PHPStan\Type\Type;
use Rector\Core\Validation\RectorAssert;

final class AddPropertyTypeDeclaration
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $propertyName,
private readonly Type $type
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Core\Validation\RectorAssert;

final class AddReturnTypeDeclaration
{
Expand All @@ -14,6 +15,7 @@ public function __construct(
private readonly string $method,
private readonly Type $returnType
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
2 changes: 2 additions & 0 deletions rules/Visibility/ValueObject/ChangeConstantVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Visibility\ValueObject;

use PHPStan\Type\ObjectType;
use Rector\Core\Validation\RectorAssert;

final class ChangeConstantVisibility
{
Expand All @@ -13,6 +14,7 @@ public function __construct(
private readonly string $constant,
private readonly int $visibility
) {
RectorAssert::className($class);
}

public function getObjectType(): ObjectType
Expand Down
3 changes: 3 additions & 0 deletions rules/Visibility/ValueObject/ChangeMethodVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace Rector\Visibility\ValueObject;

use Rector\Core\Validation\RectorAssert;

final class ChangeMethodVisibility
{
public function __construct(
private readonly string $class,
private readonly string $method,
private readonly int $visibility
) {
RectorAssert::className($class);
}

public function getClass(): string
Expand Down
5 changes: 0 additions & 5 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\ChangesReporting\Collector\RectorChangeCollector;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
use Rector\Core\Configuration\CurrentNodeProvider;
Expand Down Expand Up @@ -93,8 +92,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn

protected NodeRemover $nodeRemover;

protected RectorChangeCollector $rectorChangeCollector;

protected NodeComparator $nodeComparator;

protected NodesToRemoveCollector $nodesToRemoveCollector;
Expand Down Expand Up @@ -134,7 +131,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
public function autowire(
NodesToRemoveCollector $nodesToRemoveCollector,
NodesToAddCollector $nodesToAddCollector,
RectorChangeCollector $rectorChangeCollector,
NodeRemover $nodeRemover,
RemovedAndAddedFilesCollector $removedAndAddedFilesCollector,
BetterStandardPrinter $betterStandardPrinter,
Expand All @@ -161,7 +157,6 @@ public function autowire(
): void {
$this->nodesToRemoveCollector = $nodesToRemoveCollector;
$this->nodesToAddCollector = $nodesToAddCollector;
$this->rectorChangeCollector = $rectorChangeCollector;
$this->nodeRemover = $nodeRemover;
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
$this->betterStandardPrinter = $betterStandardPrinter;
Expand Down