Skip to content

Commit

Permalink
apply modernized Rector config
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 27, 2024
1 parent bb3bd24 commit e5958c8
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 74 deletions.
50 changes: 22 additions & 28 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,33 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
PHPUnitSetList::PHPUNIT_100,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_81,
SetList::CODING_STYLE,
SetList::TYPE_DECLARATION,
SetList::NAMING,
SetList::PRIVATIZATION,
SetList::EARLY_RETURN,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);

$rectorConfig->paths([
return RectorConfig::configure()
->withPhpSets()
->withPreparedSets(
codeQuality: true,
deadCode: true,
codingStyle: true,
typeDeclarations: true,
privatization: true,
naming: true,
earlyReturn: true
)
->withPaths([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->importNames();

$rectorConfig->skip([
])
->withRootFiles()
->withImportNames(removeUnusedImports: true)
->withSkip([
'*/Source/*',
'*/Fixture/*',
]);

$rectorConfig->ruleWithConfiguration(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class, [
'Symfony\Component\Console\*',
'Rector\Contract\Rector\ConfigurableRectorInterface',
]);
};
//
// $rectorConfig->ruleWithConfiguration(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class, [
// 'Symfony\Component\Console\*',
// 'Rector\Contract\Rector\ConfigurableRectorInterface',
// ]);
//};
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
/**
* @implements Collector<ClassMethod, array{class-string, string, string, int}|null>
*/
final class PublicClassMethodParamTypesCollector implements Collector
final readonly class PublicClassMethodParamTypesCollector implements Collector
{
public function __construct(
private readonly ApiDocStmtAnalyzer $apiDocStmtAnalyzer,
private readonly PublicClassMethodMatcher $publicClassMethodMatcher,
private readonly CollectorMetadataPrinter $collectorMetadataPrinter
private ApiDocStmtAnalyzer $apiDocStmtAnalyzer,
private PublicClassMethodMatcher $publicClassMethodMatcher,
private CollectorMetadataPrinter $collectorMetadataPrinter
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Collector/MethodCall/MethodCallArgTypesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
/**
* @implements Collector<MethodCall, array<string>|null>
*/
final class MethodCallArgTypesCollector implements Collector
final readonly class MethodCallArgTypesCollector implements Collector
{
public function __construct(
private readonly ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
private readonly CollectorMetadataPrinter $collectorMetadataPrinter,
private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
private CollectorMetadataPrinter $collectorMetadataPrinter,
) {
}

Expand Down
5 changes: 2 additions & 3 deletions src/Collector/MethodCallableNode/MethodCallableCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\TypePerfect\Collector\MethodCallableNode;

use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Collectors\Collector;
use PHPStan\Node\MethodCallableNode;
Expand All @@ -19,10 +18,10 @@
*
* @see https://github.com/phpstan/phpstan-src/blob/511c1e435fb43b8eb0ac310e6aa3230147963790/src/Analyser/NodeScopeResolver.php#L1936
*/
final class MethodCallableCollector implements Collector
final readonly class MethodCallableCollector implements Collector
{
public function __construct(
private readonly ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/NodeFinder/ClassMethodNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use PHPStan\Reflection\ClassReflection;
use Rector\TypePerfect\Reflection\ReflectionParser;

final class ClassMethodNodeFinder
final readonly class ClassMethodNodeFinder
{
public function __construct(
private readonly ReflectionParser $reflectionParser,
private ReflectionParser $reflectionParser,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/NodeFinder/MethodCallNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
use Rector\TypePerfect\Reflection\ReflectionParser;
use Webmozart\Assert\Assert;

final class MethodCallNodeFinder
final readonly class MethodCallNodeFinder
{
private readonly NodeFinder $nodeFinder;
private NodeFinder $nodeFinder;

public function __construct(
private readonly ReflectionParser $reflectionParser,
private readonly NodeComparator $nodeComparator,
private ReflectionParser $reflectionParser,
private NodeComparator $nodeComparator,
) {
$this->nodeFinder = new NodeFinder();
}
Expand Down
4 changes: 2 additions & 2 deletions src/NodeFinder/ReturnNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use PhpParser\NodeTraverser;
use Rector\TypePerfect\NodeTraverser\SimpleCallableNodeTraverser;

final class ReturnNodeFinder
final readonly class ReturnNodeFinder
{
public function __construct(
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Printer/CollectorMetadataPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
use PHPStan\Type\VerbosityLevel;
use Rector\TypePerfect\Enum\Types\ResolvedTypes;

final class CollectorMetadataPrinter
final readonly class CollectorMetadataPrinter
{
private readonly Standard $printerStandard;
private Standard $printerStandard;

public function __construct()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Printer/NodeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use PhpParser\Node;
use PhpParser\PrettyPrinter\Standard;

final class NodeComparator
final readonly class NodeComparator
{
public function __construct(
private readonly Standard $standard
private Standard $standard
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Rules/ForbiddenParamTypeRemovalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* @see \Rector\TypePerfect\Tests\Rules\ForbiddenParamTypeRemovalRule\ForbiddenParamTypeRemovalRuleTest
* @implements Rule<ClassMethod>
*/
final class ForbiddenParamTypeRemovalRule implements Rule
final readonly class ForbiddenParamTypeRemovalRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Removing parent param type is forbidden';

public function __construct(
private readonly MethodNodeAnalyser $methodNodeAnalyser
private MethodNodeAnalyser $methodNodeAnalyser
) {
}

Expand Down
11 changes: 5 additions & 6 deletions src/Rules/NarrowPrivateClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use Rector\TypePerfect\Configuration;
Expand All @@ -32,17 +31,17 @@
* @see \Rector\TypePerfect\Tests\Rules\CheckTypehintCallerTypeRule\CheckTypehintCallerTypeRuleTest
* @implements Rule<MethodCall>
*/
final class NarrowPrivateClassMethodParamTypeRule implements Rule
final readonly class NarrowPrivateClassMethodParamTypeRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Parameter %d should use "%s" type as the only type passed to this method';

public function __construct(
private readonly Configuration $configuration,
private readonly MethodCallNodeFinder $methodCallNodeFinder,
private readonly ClassMethodNodeFinder $classMethodNodeFinder
private Configuration $configuration,
private MethodCallNodeFinder $methodCallNodeFinder,
private ClassMethodNodeFinder $classMethodNodeFinder
) {
}

Expand Down Expand Up @@ -116,7 +115,7 @@ private function validateArgVsParamTypes(array $args, MethodCall $methodCall, Sc
}

$paramRuleError = $this->validateParam($param, $position, $arg->value, $scope);
if ($paramRuleError === null) {
if (! $paramRuleError instanceof RuleError) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Rules/NarrowPublicClassMethodParamTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
*
* @implements Rule<CollectedDataNode>
*/
final class NarrowPublicClassMethodParamTypeRule implements Rule
final readonly class NarrowPublicClassMethodParamTypeRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Parameters should have "%s" types as the only types passed to this method';

public function __construct(
private readonly Configuration $configuration
private Configuration $configuration
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Rules/NoMixedMethodCallerRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
* @see \Rector\TypePerfect\Tests\Rules\NoMixedMethodCallerRule\NoMixedMethodCallerRuleTest
* @implements Rule<MethodCall>
*/
final class NoMixedMethodCallerRule implements Rule
final readonly class NoMixedMethodCallerRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Mixed variable in a `%s->...()` can skip important errors. Make sure the type is known';

public function __construct(
private readonly Standard $printerStandard,
private readonly Configuration $configuration,
private Standard $printerStandard,
private Configuration $configuration,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Rules/NoMixedPropertyFetcherRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* @see \Rector\TypePerfect\Tests\Rules\NoMixedPropertyFetcherRule\NoMixedPropertyFetcherRuleTest
* @implements Rule<PropertyFetch>
*/
final class NoMixedPropertyFetcherRule implements Rule
final readonly class NoMixedPropertyFetcherRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Mixed property fetch in a "%s->..." can skip important errors. Make sure the type is known';

public function __construct(
private readonly Standard $standard,
private Standard $standard,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Rules/NoReturnFalseInNonBoolClassMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
/**
* @implements Rule<ClassMethod>
*/
final class NoReturnFalseInNonBoolClassMethodRule implements Rule
final readonly class NoReturnFalseInNonBoolClassMethodRule implements Rule
{
/**
* @api
* @var string
*/
public const ERROR_MESSAGE = 'Returning false in non return bool class method. Use null with type|null instead or add bool return type';

private readonly NodeFinder $nodeFinder;
private NodeFinder $nodeFinder;

public function __construct(
private readonly Configuration $configuration,
private Configuration $configuration,
) {
$this->nodeFinder = new NodeFinder();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/RequireSpecificReturnTypeOverAbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
*
* @implements Rule<ClassMethod>
*/
final class RequireSpecificReturnTypeOverAbstractRule implements Rule
final readonly class RequireSpecificReturnTypeOverAbstractRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Provide more specific return type "%s" over abstract one';

public function __construct(
private readonly ReturnNodeFinder $returnNodeFinder,
private readonly MethodNodeAnalyser $methodNodeAnalyser,
private ReturnNodeFinder $returnNodeFinder,
private MethodNodeAnalyser $methodNodeAnalyser,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/MethodCallReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Rector\TypePerfect\ValueObject;

final class MethodCallReference
final readonly class MethodCallReference
{
public function __construct(
private readonly string $class,
private readonly string $method
private string $class,
private string $method
) {
}

Expand Down

0 comments on commit e5958c8

Please sign in to comment.