Skip to content

Commit 3829eab

Browse files
committed
Update PER to v1.1
1 parent 23f2154 commit 3829eab

16 files changed

+238
-8
lines changed

doc/list.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,14 @@ List of Available Rules
947947
| Default value: ``'start_plus_one'``
948948
949949

950-
Part of rule sets `@PHP73Migration <./ruleSets/PHP73Migration.rst>`_ `@PHP74Migration <./ruleSets/PHP74Migration.rst>`_ `@PHP80Migration <./ruleSets/PHP80Migration.rst>`_ `@PHP81Migration <./ruleSets/PHP81Migration.rst>`_
950+
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PHP73Migration <./ruleSets/PHP73Migration.rst>`_ `@PHP74Migration <./ruleSets/PHP74Migration.rst>`_ `@PHP80Migration <./ruleSets/PHP80Migration.rst>`_ `@PHP81Migration <./ruleSets/PHP81Migration.rst>`_
951951

952952
`Source PhpCsFixer\\Fixer\\Whitespace\\HeredocIndentationFixer <./../src/Fixer/Whitespace/HeredocIndentationFixer.php>`_
953953
- `heredoc_to_nowdoc <./rules/string_notation/heredoc_to_nowdoc.rst>`_
954954

955955
Convert ``heredoc`` to ``nowdoc`` where possible.
956956

957-
Part of rule set `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_
957+
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_
958958

959959
`Source PhpCsFixer\\Fixer\\StringNotation\\HeredocToNowdocFixer <./../src/Fixer/StringNotation/HeredocToNowdocFixer.php>`_
960960
- `implode_call <./rules/function_notation/implode_call.rst>`_

doc/ruleSets/PER.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Rules
88
-----
99

1010
- `@PSR12 <./PSR12.rst>`_
11+
- `heredoc_to_nowdoc <./../rules/string_notation/heredoc_to_nowdoc.rst>`_
12+
- `heredoc_indentation <./../rules/whitespace/heredoc_indentation.rst>`_

doc/rules/string_notation/heredoc_to_nowdoc.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ Example #1
2222
Rule sets
2323
---------
2424

25-
The rule is part of the following rule set:
25+
The rule is part of the following rule sets:
26+
27+
@PER
28+
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``heredoc_to_nowdoc`` rule.
2629

2730
@PhpCsFixer
2831
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``heredoc_to_nowdoc`` rule.

doc/rules/whitespace/heredoc_indentation.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Rule sets
7979

8080
The rule is part of the following rule sets:
8181

82+
@PER
83+
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config.
84+
8285
@PHP73Migration
8386
Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config.
8487

src/RuleSet/Sets/PERRiskySet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @internal
2121
*
22-
* Last updated to PER Coding Style v1.0.0.
22+
* Last updated to PER Coding Style v1.1.0.
2323
*/
2424
final class PERRiskySet extends AbstractRuleSetDescription
2525
{

src/RuleSet/Sets/PERSet.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@
1919
/**
2020
* @internal
2121
*
22-
* Last updated to PER Coding Style v1.0.0.
22+
* Last updated to PER Coding Style v1.1.0.
2323
*/
2424
final class PERSet extends AbstractRuleSetDescription
2525
{
2626
public function getRules(): array
2727
{
2828
return [
2929
'@PSR12' => true,
30+
'heredoc_indentation' => true,
31+
'heredoc_to_nowdoc' => true,
32+
'method_chaining_indentation' => true,
33+
'no_singleline_whitespace_before_semicolons' => true,
34+
'no_trailing_comma_in_list_call' => true,
35+
'no_trailing_comma_in_singleline_array' => true,
36+
'no_trailing_comma_in_singleline_function_call' => true,
37+
'trailing_comma_in_multiline' => [
38+
'after_heredoc' => true,
39+
'elements' => ['arrays', 'arguments', 'parameters', 'match'],
40+
],
3041
];
3142
}
3243

tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ final class TrailingCommaInMultilineFixerTest extends AbstractFixerTestCase
3333
*
3434
* @dataProvider provideInvalidConfigurationCases
3535
*
36-
* @param mixed $exceptionMessega
36+
* @param mixed $exceptionMessage
3737
* @param mixed $configuration
3838
*/
39-
public function testInvalidConfiguration($exceptionMessega, $configuration): void
39+
public function testInvalidConfiguration($exceptionMessage, $configuration): void
4040
{
4141
$this->expectException(InvalidForEnvFixerConfigurationException::class);
42-
$this->expectExceptionMessage($exceptionMessega);
42+
$this->expectExceptionMessage($exceptionMessage);
4343

4444
$this->fixer->configure($configuration);
4545
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--TEST--
2+
Integration of @PER.
3+
--RULESET--
4+
{"@PER": true}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
abstract class PER
4+
{
5+
static
6+
protected string $keywords;
7+
8+
static public
9+
abstract function keywords();
10+
11+
public function heredocAndNowdoc()
12+
{
13+
$notAllowed = <<<COUNTEREXAMPLE
14+
Wrong indentation.
15+
Also, should be nowdoc.
16+
COUNTEREXAMPLE;
17+
}
18+
19+
public function shortClosures()
20+
{
21+
$identity =fn(int $x) :int=>$x ;
22+
23+
$sum = fn (int $x, int $y): int =>
24+
$x + $y
25+
;
26+
}
27+
28+
public function trailingCommas()
29+
{
30+
$min = min(3, M_PI,);
31+
$min = min(
32+
3,
33+
M_PI
34+
);
35+
36+
[$foo, $bar,] = ['foo', 'bar',];
37+
[
38+
$foo,
39+
$bar
40+
] = [
41+
'foo',
42+
'bar'
43+
];
44+
45+
list($foo, $bar,) = array('foo', 'bar',);
46+
list(
47+
$foo,
48+
$bar
49+
) = array(
50+
'foo',
51+
'bar'
52+
);
53+
}
54+
55+
public function chaining()
56+
{
57+
$this->foo()
58+
->bar()->baz();
59+
}
60+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
abstract class PER
4+
{
5+
protected static string $keywords;
6+
7+
abstract public static function keywords();
8+
9+
public function heredocAndNowdoc()
10+
{
11+
$notAllowed = <<<'COUNTEREXAMPLE'
12+
Wrong indentation.
13+
Also, should be nowdoc.
14+
COUNTEREXAMPLE;
15+
}
16+
17+
public function shortClosures()
18+
{
19+
$identity = fn (int $x): int => $x;
20+
21+
$sum = fn (int $x, int $y): int
22+
=> $x + $y;
23+
}
24+
25+
public function trailingCommas()
26+
{
27+
$min = min(3, M_PI);
28+
$min = min(
29+
3,
30+
M_PI,
31+
);
32+
33+
[$foo, $bar] = ['foo', 'bar'];
34+
[
35+
$foo,
36+
$bar,
37+
] = [
38+
'foo',
39+
'bar',
40+
];
41+
42+
list($foo, $bar) = array('foo', 'bar');
43+
list(
44+
$foo,
45+
$bar,
46+
) = array(
47+
'foo',
48+
'bar',
49+
);
50+
}
51+
52+
public function chaining()
53+
{
54+
$this
55+
->foo()
56+
->bar()
57+
->baz();
58+
}
59+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--TEST--
2+
Integration of @PER [PHP 8.0 version].
3+
--RULESET--
4+
{"@PER": true}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
class PER80
4+
{
5+
public function trailingCommas(
6+
int|float $num
7+
) {
8+
$match = match ($num) {
9+
3 => 'three',
10+
M_PI => 'pi',
11+
default => 'other'
12+
};
13+
14+
$sum = fn (int $x,
15+
int $y
16+
) => $x + $y;
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
class PER80
4+
{
5+
public function trailingCommas(
6+
int|float $num,
7+
) {
8+
$match = match ($num) {
9+
3 => 'three',
10+
M_PI => 'pi',
11+
default => 'other',
12+
};
13+
14+
$sum = fn (
15+
int $x,
16+
int $y,
17+
) => $x + $y;
18+
}
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--TEST--
2+
Integration of @PER [PHP 8.1 version].
3+
--RULESET--
4+
{"@PER": true}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class PER80
4+
{
5+
readonly public \DateTime $keywords;
6+
7+
public function firstClassCallables()
8+
{
9+
foo( ... );
10+
}
11+
}
12+
13+
enum Suit :string{
14+
case Hearts = 'H';case Diamonds = 'D';
15+
case Spades = 'S';case Clubs = 'C';
16+
17+
protected function foo(): void
18+
{
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
class PER80
4+
{
5+
public readonly \DateTime $keywords;
6+
7+
public function firstClassCallables()
8+
{
9+
foo(...);
10+
}
11+
}
12+
13+
enum Suit: string
14+
{
15+
case Hearts = 'H';
16+
case Diamonds = 'D';
17+
case Spades = 'S';
18+
case Clubs = 'C';
19+
20+
private function foo(): void
21+
{
22+
}
23+
}

0 commit comments

Comments
 (0)