From 7c132392af7ad195715f0b1dd072fd216fb10e5f Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 27 Apr 2024 09:45:43 +0200 Subject: [PATCH] Add override Standard method (#216) --- src/Ruleset/Ruleset.php | 12 ++++++++++++ tests/Ruleset/RulesetTest.php | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) 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();