Skip to content

Commit e2ce475

Browse files
committed
avoid duplicate registration
1 parent f3f9c1a commit e2ce475

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

config/set/type-declaration-docblocks.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
declare(strict_types=1);
44

5+
use Rector\Config\Level\TypeDeclarationDocblocksLevel;
56
use Rector\Config\RectorConfig;
67

78
/**
89
* @experimental * 2025-09, experimental hidden set for type declaration in docblocks
910
*/
1011
return static function (RectorConfig $rectorConfig): void {
11-
$rectorConfig->rules(\Rector\Config\Level\TypeDeclarationDocblocksLevel::RULES);
12+
$rectorConfig->rules(TypeDeclarationDocblocksLevel::RULES);
1213
};

src/Configuration/RectorConfigBuilder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ final class RectorConfigBuilder
142142
*/
143143
private ?bool $isTypeCoverageLevelUsed = null;
144144

145+
private ?bool $isTypeCoverageDocblockLevelUsed = null;
146+
145147
private ?bool $isDeadCodeLevelUsed = null;
146148

147149
private ?bool $isCodeQualityLevelUsed = null;
@@ -225,6 +227,17 @@ public function __invoke(RectorConfig $rectorConfig): void
225227
));
226228
}
227229

230+
if (in_array(
231+
SetList::TYPE_DECLARATION_DOCBLOCKS,
232+
$uniqueSets,
233+
true
234+
) && $this->isTypeCoverageDocblockLevelUsed === true) {
235+
throw new InvalidConfigurationException(sprintf(
236+
'Your config already enables type declarations set.%sRemove "->withTypeCoverageDocblockLevel()" as it only duplicates it, or remove type declaration set.',
237+
PHP_EOL
238+
));
239+
}
240+
228241
if (in_array(SetList::DEAD_CODE, $uniqueSets, true) && $this->isDeadCodeLevelUsed === true) {
229242
throw new InvalidConfigurationException(sprintf(
230243
'Your config already enables dead code set.%sRemove "->withDeadCodeLevel()" as it only duplicates it, or remove dead code set.',
@@ -1030,6 +1043,8 @@ public function withTypeCoverageDocblockLevel(int $level): self
10301043
{
10311044
Assert::natural($level);
10321045

1046+
$this->isTypeCoverageDocblockLevelUsed = true;
1047+
10331048
$levelRules = LevelRulesResolver::resolve($level, TypeDeclarationDocblocksLevel::RULES, __METHOD__);
10341049

10351050
// too high

0 commit comments

Comments
 (0)