diff --git a/src/Ruleset/Ruleset.php b/src/Ruleset/Ruleset.php index d825626e..4164d440 100644 --- a/src/Ruleset/Ruleset.php +++ b/src/Ruleset/Ruleset.php @@ -96,4 +96,16 @@ public function addStandard(StandardInterface $standard): self return $this; } + + /** + * @return $this + */ + public function overrideStandard(StandardInterface $standard): self + { + foreach ($standard->getRules() as $rule) { + $this->overrideRule($rule); + } + + return $this; + } } diff --git a/tests/Ruleset/RulesetTest.php b/tests/Ruleset/RulesetTest.php index 93a16a70..8ffc7949 100644 --- a/tests/Ruleset/RulesetTest.php +++ b/tests/Ruleset/RulesetTest.php @@ -44,6 +44,28 @@ public function testAddAndRemoveRule(): void static::assertCount(1, $ruleset->getRules()); } + public function testAddStandard(): void + { + $ruleset = new Ruleset(); + $rule1 = new SingleQuoteRule(true); + $rule2 = new SingleQuoteRule(false); + + $standard1 = self::createStub(StandardInterface::class); + $standard1->method('getRules')->willReturn([$rule1]); + + $standard2 = self::createStub(StandardInterface::class); + $standard2->method('getRules')->willReturn([$rule2]); + + $ruleset->addStandard($standard1); + static::assertCount(1, $ruleset->getRules()); + + $ruleset->addStandard($standard2); + static::assertCount(2, $ruleset->getRules()); + + $ruleset->overrideStandard($standard2); + static::assertSame([$rule2], $ruleset->getRules()); + } + public function testAllowNonFixableRules(): void { $ruleset = new Ruleset();