Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add override Standard method #216

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Ruleset/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 22 additions & 0 deletions tests/Ruleset/RulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading