Skip to content

Commit 0c37a47

Browse files
authored
[Config] Make with php set used, cleanup phpstan config (#6274)
* [Config] Make with php set used * level is always natural * cleanup phpstan
1 parent ad30cfb commit 0c37a47

File tree

3 files changed

+85
-36
lines changed

3 files changed

+85
-36
lines changed

phpstan.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ parameters:
111111
- src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php
112112
- rules/EarlyReturn/Rector/If_/ChangeNestedIfsToEarlyReturnRector.php
113113
- rules/Php70/EregToPcreTransformer.php
114-
- rules/DeadCode/NodeManipulator/LivingCodeManipulator.php
115-
- rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php
116-
- src/PhpParser/NodeTransformer.php
117114

118115
# mapper re-use
119116
- '#Parameter \#1 \$type of method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ObjectWithoutClassTypeMapper\:\:mapToPhpParserNode\(\) expects PHPStan\\Type\\ObjectWithoutClassType, PHPStan\\Type\\Accessory\\Has(Property|Method)Type given#'
@@ -302,3 +299,6 @@ parameters:
302299

303300
# known values
304301
- '#Method Rector\\Util\\PhpVersionFactory\:\:createIntVersion\(\) should return 50200\|50300\|50400\|50500\|50600\|70000\|70100\|70200\|70300\|70400\|80000\|80100\|80200\|80300\|80400\|100000 but returns int#'
302+
303+
# soon to be used
304+
- '#Property Rector\\Configuration\\RectorConfigBuilder\:\:\$isWithPhpSetsUsed is never read, only written#'

rector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
66
use Rector\Config\RectorConfig;
77
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
8+
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
89
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
910

1011
return RectorConfig::configure()
@@ -54,4 +55,6 @@
5455
__DIR__ . '/src/Configuration/RectorConfigBuilder.php',
5556
__DIR__ . '/src/Console/Notifier.php',
5657
],
58+
59+
RemoveUnusedPrivatePropertyRector::class => [__DIR__ . '/src/Configuration/RectorConfigBuilder.php'],
5760
]);

src/Configuration/RectorConfigBuilder.php

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ final class RectorConfigBuilder
153153
*/
154154
private array $groupLoadedSets = [];
155155

156+
/**
157+
* @api soon to be used
158+
*/
159+
private ?bool $isWithPhpSetsUsed = null;
160+
156161
public function __invoke(RectorConfig $rectorConfig): void
157162
{
158163
// @experimental 2024-06
@@ -489,6 +494,8 @@ public function withPhpSets(
489494
bool $php53 = false,
490495
bool $php84 = false, // place on later as BC break when used in php 7.x without named arg
491496
): self {
497+
$this->isWithPhpSetsUsed = true;
498+
492499
$pickedArguments = array_filter(func_get_args());
493500
if ($pickedArguments !== []) {
494501
Notifier::notifyWithPhpSetsNotSuitableForPHP80();
@@ -513,24 +520,51 @@ public function withPhpSets(
513520
}
514521

515522
if ($php53) {
516-
$targetPhpVersion = PhpVersion::PHP_53;
517-
} elseif ($php54) {
518-
$targetPhpVersion = PhpVersion::PHP_54;
519-
} elseif ($php55) {
520-
$targetPhpVersion = PhpVersion::PHP_55;
521-
} elseif ($php56) {
522-
$targetPhpVersion = PhpVersion::PHP_56;
523-
} elseif ($php70) {
524-
$targetPhpVersion = PhpVersion::PHP_70;
525-
} elseif ($php71) {
526-
$targetPhpVersion = PhpVersion::PHP_71;
527-
} elseif ($php72) {
528-
$targetPhpVersion = PhpVersion::PHP_72;
529-
} elseif ($php73) {
530-
$targetPhpVersion = PhpVersion::PHP_73;
531-
} elseif ($php74) {
532-
$targetPhpVersion = PhpVersion::PHP_74;
533-
} elseif ($php80) {
523+
$this->withPhp53Sets();
524+
return $this;
525+
}
526+
527+
if ($php54) {
528+
$this->withPhp54Sets();
529+
return $this;
530+
}
531+
532+
if ($php55) {
533+
$this->withPhp55Sets();
534+
return $this;
535+
}
536+
537+
if ($php56) {
538+
$this->withPhp56Sets();
539+
return $this;
540+
}
541+
542+
if ($php70) {
543+
$this->withPhp70Sets();
544+
return $this;
545+
}
546+
547+
if ($php71) {
548+
$this->withPhp71Sets();
549+
return $this;
550+
}
551+
552+
if ($php72) {
553+
$this->withPhp72Sets();
554+
return $this;
555+
}
556+
557+
if ($php73) {
558+
$this->withPhp73Sets();
559+
return $this;
560+
}
561+
562+
if ($php74) {
563+
$this->withPhp74Sets();
564+
return $this;
565+
}
566+
567+
if ($php80) {
534568
$targetPhpVersion = PhpVersion::PHP_80;
535569
} elseif ($php81) {
536570
$targetPhpVersion = PhpVersion::PHP_81;
@@ -556,62 +590,80 @@ public function withPhpSets(
556590
*/
557591
public function withPhp53Sets(): self
558592
{
593+
$this->isWithPhpSetsUsed = true;
594+
559595
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_53));
560596

561597
return $this;
562598
}
563599

564600
public function withPhp54Sets(): self
565601
{
602+
$this->isWithPhpSetsUsed = true;
603+
566604
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_54));
567605

568606
return $this;
569607
}
570608

571609
public function withPhp55Sets(): self
572610
{
611+
$this->isWithPhpSetsUsed = true;
612+
573613
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_55));
574614

575615
return $this;
576616
}
577617

578618
public function withPhp56Sets(): self
579619
{
620+
$this->isWithPhpSetsUsed = true;
621+
580622
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_56));
581623

582624
return $this;
583625
}
584626

585627
public function withPhp70Sets(): self
586628
{
629+
$this->isWithPhpSetsUsed = true;
630+
587631
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_70));
588632

589633
return $this;
590634
}
591635

592636
public function withPhp71Sets(): self
593637
{
638+
$this->isWithPhpSetsUsed = true;
639+
594640
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_71));
595641

596642
return $this;
597643
}
598644

599645
public function withPhp72Sets(): self
600646
{
647+
$this->isWithPhpSetsUsed = true;
648+
601649
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_72));
602650

603651
return $this;
604652
}
605653

606654
public function withPhp73Sets(): self
607655
{
656+
$this->isWithPhpSetsUsed = true;
657+
608658
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_73));
609659

610660
return $this;
611661
}
612662

613663
public function withPhp74Sets(): self
614664
{
665+
$this->isWithPhpSetsUsed = true;
666+
615667
$this->sets = array_merge($this->sets, PhpLevelSetResolver::resolveFromPhpVersion(PhpVersion::PHP_74));
616668

617669
return $this;
@@ -876,13 +928,11 @@ public function withSymfonyContainerPhp(string $symfonyContainerPhpFile): self
876928
*/
877929
public function withDeadCodeLevel(int $level): self
878930
{
931+
Assert::natural($level);
932+
879933
$this->isDeadCodeLevelUsed = true;
880934

881-
$levelRules = LevelRulesResolver::resolve(
882-
$level,
883-
DeadCodeLevel::RULES,
884-
'RectorConfig::withDeadCodeLevel()'
885-
);
935+
$levelRules = LevelRulesResolver::resolve($level, DeadCodeLevel::RULES, __METHOD__);
886936

887937
$this->rules = array_merge($this->rules, $levelRules);
888938

@@ -895,13 +945,11 @@ public function withDeadCodeLevel(int $level): self
895945
*/
896946
public function withTypeCoverageLevel(int $level): self
897947
{
948+
Assert::natural($level);
949+
898950
$this->isTypeCoverageLevelUsed = true;
899951

900-
$levelRules = LevelRulesResolver::resolve(
901-
$level,
902-
TypeDeclarationLevel::RULES,
903-
'RectorConfig::withTypeCoverageLevel()'
904-
);
952+
$levelRules = LevelRulesResolver::resolve($level, TypeDeclarationLevel::RULES, __METHOD__);
905953

906954
$this->rules = array_merge($this->rules, $levelRules);
907955

@@ -914,13 +962,11 @@ public function withTypeCoverageLevel(int $level): self
914962
*/
915963
public function withCodeQualityLevel(int $level): self
916964
{
965+
Assert::natural($level);
966+
917967
$this->isCodeQualityLevelUsed = true;
918968

919-
$levelRules = LevelRulesResolver::resolve(
920-
$level,
921-
CodeQualityLevel::RULES,
922-
'RectorConfig::withCodeQualityLevel()'
923-
);
969+
$levelRules = LevelRulesResolver::resolve($level, CodeQualityLevel::RULES, __METHOD__);
924970

925971
$this->rules = array_merge($this->rules, $levelRules);
926972

0 commit comments

Comments
 (0)