Skip to content

Commit 7b6fe23

Browse files
committed
[dx] add withTypeCoverageDocblockLevel()fs
1 parent f8c1d78 commit 7b6fe23

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

config/set/type-declaration-docblocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
* @experimental * 2025-09, experimental hidden set for type declaration in docblocks
99
*/
1010
return static function (RectorConfig $rectorConfig): void {
11-
$rectorConfig->rules(\Rector\Config\Level\TypeDeclarationDocblockLevel::RULES);
11+
$rectorConfig->rules(\Rector\Config\Level\TypeDeclarationDocblocksLevel::RULES);
1212
};

src/Config/Level/TypeDeclarationDocblockLevel.php renamed to src/Config/Level/TypeDeclarationDocblocksLevel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockGetterReturnArrayFromPropertyDocblockVarRector;
2121
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector;
2222

23-
final class TypeDeclarationDocblockLevel
23+
final class TypeDeclarationDocblocksLevel
2424
{
2525
/**
2626
* @var array<class-string<RectorInterface>>

src/Configuration/RectorConfigBuilder.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Rector\Config\Level\CodeQualityLevel;
1212
use Rector\Config\Level\CodingStyleLevel;
1313
use Rector\Config\Level\DeadCodeLevel;
14+
use Rector\Config\Level\TypeDeclarationDocblocksLevel;
1415
use Rector\Config\Level\TypeDeclarationLevel;
1516
use Rector\Config\RectorConfig;
1617
use Rector\Config\RegisteredService;
@@ -742,6 +743,7 @@ public function withPreparedSets(
742743
bool $codeQuality = false,
743744
bool $codingStyle = false,
744745
bool $typeDeclarations = false,
746+
bool $typeDeclarationDocblocks = false,
745747
bool $privatization = false,
746748
bool $naming = false,
747749
bool $instanceOf = false,
@@ -761,6 +763,7 @@ public function withPreparedSets(
761763
SetList::CODE_QUALITY => $codeQuality,
762764
SetList::CODING_STYLE => $codingStyle,
763765
SetList::TYPE_DECLARATION => $typeDeclarations,
766+
SetList::TYPE_DECLARATION_DOCBLOCKS => $typeDeclarationDocblocks,
764767
SetList::PRIVATIZATION => $privatization,
765768
SetList::NAMING => $naming,
766769
SetList::INSTANCEOF => $instanceOf,
@@ -1019,6 +1022,33 @@ public function withTypeCoverageLevel(int $level): self
10191022
return $this;
10201023
}
10211024

1025+
/**
1026+
* Raise your type coverage docblock from the safest type rules
1027+
* to more affecting ones, one level at a time
1028+
*/
1029+
public function withTypeCoverageDocblockLevel(int $level): self
1030+
{
1031+
Assert::natural($level);
1032+
1033+
$levelRules = LevelRulesResolver::resolve($level, TypeDeclarationDocblocksLevel::RULES, __METHOD__);
1034+
1035+
// too high
1036+
$levelRulesCount = count($levelRules);
1037+
if ($levelRulesCount + self::MAX_LEVEL_GAP < $level) {
1038+
$this->levelOverflows[] = new LevelOverflow(
1039+
__METHOD__,
1040+
$level,
1041+
$levelRulesCount,
1042+
'TypeDeclarationDocblocksLevel',
1043+
'TYPE_DECLARATION_DOCBLOCKS'
1044+
);
1045+
}
1046+
1047+
$this->rules = array_merge($this->rules, $levelRules);
1048+
1049+
return $this;
1050+
}
1051+
10221052
/**
10231053
* Raise your dead-code coverage from the safest rules
10241054
* to more affecting ones, one level at a time

0 commit comments

Comments
 (0)