Skip to content

Commit a0c9d6d

Browse files
authored
feat: allow to enable @per* rulesets with ruleset builder (#204)
1 parent 8aedba7 commit a0c9d6d

File tree

4 files changed

+126
-116
lines changed

4 files changed

+126
-116
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
->setRiskyAllowed(true)
1010
->setRules(
1111
RuleSetFactory::create()
12+
->per(2, true)
1213
->phpCsFixer(true)
1314
->php(8.0, true)
1415
->pedrotroller(true)

doc/rule-set-factory.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ return PhpCsFixer\Config::create()
1111
->setRules(RuleSetFactory::create()
1212
->symfony() // Activate the @Symfony ruleset
1313
->phpCsFixer() // Activate the @PhpCsFixer ruleset
14-
->php(5.6, true) // Activate php 5.6 risky rules
14+
->php(8.2, true) // Activate php 8.2 risky rules
1515
->pedrotroller(true) // Activate my own ruleset (with risky rules)
1616
->enable('ordered_imports') // Add an other rule
1717
->disable('yoda_style') // Disable a rule
@@ -26,6 +26,10 @@ return PhpCsFixer\Config::create()
2626

2727
## Methods
2828

29+
### `->per([int|float $version = null, [bool $risky = false]])`
30+
31+
Activate the `@PER` (`@PER-CS1.0`, `@PER-CS1.0:risky`, `@PER-CS2.0`, `@PER-CS2.0:risky`, ...) rule.
32+
2933
### `->psr0()`
3034

3135
Activate the `@psr0` rule.

spec/PedroTroller/CS/Fixer/RuleSetFactorySpec.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,46 @@
1010

1111
final class RuleSetFactorySpec extends ObjectBehavior
1212
{
13+
function let()
14+
{
15+
$this->beConstructedThrough('create');
16+
}
17+
1318
function it_is_initializable()
1419
{
1520
$this->shouldHaveType(RuleSetFactory::class);
1621
}
1722

23+
function it_adds_a_per_set()
24+
{
25+
$this->per()->getRules()->shouldReturn(['@PER' => true]);
26+
}
27+
28+
function it_adds_a_per_risky_set()
29+
{
30+
$this->per(risky: true)->getRules()->shouldReturn(['@PER:risky' => true]);
31+
}
32+
33+
function it_adds_a_per1_0_set()
34+
{
35+
$this->per(1)->getRules()->shouldReturn(['@PER-CS1.0' => true]);
36+
}
37+
38+
function it_adds_a_per1_0_risky_set()
39+
{
40+
$this->per(1, true)->getRules()->shouldReturn(['@PER-CS1.0:risky' => true]);
41+
}
42+
43+
function it_adds_a_per2_0_set()
44+
{
45+
$this->per(2)->getRules()->shouldReturn(['@PER-CS2.0' => true]);
46+
}
47+
48+
function it_adds_a_per2_0_risky_set()
49+
{
50+
$this->per(2, true)->getRules()->shouldReturn(['@PER-CS2.0:risky' => true]);
51+
}
52+
1853
function it_adds_a_psr0_set()
1954
{
2055
$this->psr0()->getRules()->shouldReturn(['@psr0' => true]);
@@ -144,15 +179,6 @@ function it_adds_a_php_version_support()
144179
]);
145180
}
146181

147-
function it_can_also_parse_versions_as_string()
148-
{
149-
$this->php('5.6.2')->getRules()->shouldReturn([
150-
'@PHP54Migration' => true,
151-
'array_syntax' => ['syntax' => 'short'],
152-
'list_syntax' => ['syntax' => 'long'],
153-
]);
154-
}
155-
156182
function it_adds_a_phpunit_version_support()
157183
{
158184
$this->phpUnit(2.0, false)->getRules()->shouldReturn([]);
@@ -310,8 +336,6 @@ function it_adds_my_own_fixer_set()
310336
$rules[$fixer->getName()] = true;
311337
}
312338

313-
ksort($rules);
314-
315339
$this->pedrotroller(true)->getRules()->shouldReturn($rules);
316340
}
317341

@@ -327,8 +351,6 @@ function it_adds_my_own_fixer_set_except_privates()
327351
$rules[$fixer->getName()] = true;
328352
}
329353

330-
ksort($rules);
331-
332354
$this->pedrotroller(false)->getRules()->shouldReturn($rules);
333355
}
334356

0 commit comments

Comments
 (0)