Skip to content

Commit

Permalink
Update PER to v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Aug 9, 2022
1 parent 23f2154 commit b02db11
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 16 deletions.
16 changes: 8 additions & 8 deletions doc/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,14 @@ List of Available Rules
| Default value: ``'start_plus_one'``

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

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

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

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

`Source PhpCsFixer\\Fixer\\StringNotation\\HeredocToNowdocFixer <./../src/Fixer/StringNotation/HeredocToNowdocFixer.php>`_
- `implode_call <./rules/function_notation/implode_call.rst>`_
Expand Down Expand Up @@ -1127,7 +1127,7 @@ List of Available Rules

Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.

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

`Source PhpCsFixer\\Fixer\\Whitespace\\MethodChainingIndentationFixer <./../src/Fixer/Whitespace/MethodChainingIndentationFixer.php>`_
- `modernize_strpos <./rules/alias/modernize_strpos.rst>`_
Expand Down Expand Up @@ -1525,7 +1525,7 @@ List of Available Rules

Single-line whitespace before closing semicolon are prohibited.

Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_

`Source PhpCsFixer\\Fixer\\Semicolon\\NoSinglelineWhitespaceBeforeSemicolonsFixer <./../src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php>`_
- `no_spaces_after_function_name <./rules/function_notation/no_spaces_after_function_name.rst>`_
Expand Down Expand Up @@ -1598,21 +1598,21 @@ List of Available Rules

Remove trailing commas in list function calls.

Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_

`Source PhpCsFixer\\Fixer\\ControlStructure\\NoTrailingCommaInListCallFixer <./../src/Fixer/ControlStructure/NoTrailingCommaInListCallFixer.php>`_
- `no_trailing_comma_in_singleline_array <./rules/array_notation/no_trailing_comma_in_singleline_array.rst>`_

PHP single-line arrays should not have trailing comma.

Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_

`Source PhpCsFixer\\Fixer\\ArrayNotation\\NoTrailingCommaInSinglelineArrayFixer <./../src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php>`_
- `no_trailing_comma_in_singleline_function_call <./rules/function_notation/no_trailing_comma_in_singleline_function_call.rst>`_

When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument.

Part of rule sets `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_

`Source PhpCsFixer\\Fixer\\FunctionNotation\\NoTrailingCommaInSinglelineFunctionCallFixer <./../src/Fixer/FunctionNotation/NoTrailingCommaInSinglelineFunctionCallFixer.php>`_
- `no_trailing_whitespace <./rules/whitespace/no_trailing_whitespace.rst>`_
Expand Down Expand Up @@ -2942,7 +2942,7 @@ List of Available Rules
| Default value: ``['arrays']``

Part of rule sets `@PHP73Migration <./ruleSets/PHP73Migration.rst>`_ `@PHP74Migration <./ruleSets/PHP74Migration.rst>`_ `@PHP80Migration <./ruleSets/PHP80Migration.rst>`_ `@PHP81Migration <./ruleSets/PHP81Migration.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_
Part of rule sets `@PER <./ruleSets/PER.rst>`_ `@PHP73Migration <./ruleSets/PHP73Migration.rst>`_ `@PHP74Migration <./ruleSets/PHP74Migration.rst>`_ `@PHP80Migration <./ruleSets/PHP80Migration.rst>`_ `@PHP81Migration <./ruleSets/PHP81Migration.rst>`_ `@PhpCsFixer <./ruleSets/PhpCsFixer.rst>`_ `@Symfony <./ruleSets/Symfony.rst>`_

`Source PhpCsFixer\\Fixer\\ControlStructure\\TrailingCommaInMultilineFixer <./../src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php>`_
- `trim_array_spaces <./rules/array_notation/trim_array_spaces.rst>`_
Expand Down
10 changes: 10 additions & 0 deletions doc/ruleSets/PER.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ Rules
-----

- `@PSR12 <./PSR12.rst>`_
- `heredoc_indentation <./../rules/whitespace/heredoc_indentation.rst>`_
- `heredoc_to_nowdoc <./../rules/string_notation/heredoc_to_nowdoc.rst>`_
- `method_chaining_indentation <./../rules/whitespace/method_chaining_indentation.rst>`_
- `no_singleline_whitespace_before_semicolons <./../rules/semicolon/no_singleline_whitespace_before_semicolons.rst>`_
- `no_trailing_comma_in_list_call <./../rules/control_structure/no_trailing_comma_in_list_call.rst>`_
- `no_trailing_comma_in_singleline_array <./../rules/array_notation/no_trailing_comma_in_singleline_array.rst>`_
- `no_trailing_comma_in_singleline_function_call <./../rules/function_notation/no_trailing_comma_in_singleline_function_call.rst>`_
- `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_
config:
``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``no_trailing_comma_in_singleline_array`` rule.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``no_trailing_comma_in_list_call`` rule.

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

Expand Down
5 changes: 5 additions & 0 deletions doc/rules/control_structure/trailing_comma_in_multiline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``trailing_comma_in_multiline`` rule with the config below:

``['after_heredoc' => true, 'elements' => ['arguments', 'arrays', 'match', 'parameters']]``

@PHP73Migration
Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``trailing_comma_in_multiline`` rule with the config below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``no_trailing_comma_in_singleline_function_call`` rule.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``no_singleline_whitespace_before_semicolons`` rule.

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

Expand Down
5 changes: 4 additions & 1 deletion doc/rules/string_notation/heredoc_to_nowdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Example #1
Rule sets
---------

The rule is part of the following rule set:
The rule is part of the following rule sets:

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

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``heredoc_to_nowdoc`` rule.
3 changes: 3 additions & 0 deletions doc/rules/whitespace/heredoc_indentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ Rule sets

The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config.

@PHP73Migration
Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config.

Expand Down
5 changes: 4 additions & 1 deletion doc/rules/whitespace/method_chaining_indentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ Example #1
Rule sets
---------

The rule is part of the following rule set:
The rule is part of the following rule sets:

@PER
Using the `@PER <./../../ruleSets/PER.rst>`_ rule set will enable the ``method_chaining_indentation`` rule.

@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``method_chaining_indentation`` rule.
2 changes: 1 addition & 1 deletion src/RuleSet/Sets/PERRiskySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* @internal
*
* Last updated to PER Coding Style v1.0.0.
* Last updated to PER Coding Style v1.1.0.
*/
final class PERRiskySet extends AbstractRuleSetDescription
{
Expand Down
13 changes: 12 additions & 1 deletion src/RuleSet/Sets/PERSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,25 @@
/**
* @internal
*
* Last updated to PER Coding Style v1.0.0.
* Last updated to PER Coding Style v1.1.0.
*/
final class PERSet extends AbstractRuleSetDescription
{
public function getRules(): array
{
return [
'@PSR12' => true,
'heredoc_indentation' => true,
'heredoc_to_nowdoc' => true,
'method_chaining_indentation' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline_function_call' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arguments', 'arrays', 'match', 'parameters'],
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ final class TrailingCommaInMultilineFixerTest extends AbstractFixerTestCase
*
* @dataProvider provideInvalidConfigurationCases
*
* @param mixed $exceptionMessega
* @param mixed $exceptionMessage
* @param mixed $configuration
*/
public function testInvalidConfiguration($exceptionMessega, $configuration): void
public function testInvalidConfiguration($exceptionMessage, $configuration): void
{
$this->expectException(InvalidForEnvFixerConfigurationException::class);
$this->expectExceptionMessage($exceptionMessega);
$this->expectExceptionMessage($exceptionMessage);

$this->fixer->configure($configuration);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/Integration/set/@PER.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--TEST--
Integration of @PER.
--RULESET--
{"@PER": true}
60 changes: 60 additions & 0 deletions tests/Fixtures/Integration/set/@PER.test-in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

abstract class PER
{
static
protected string $keywords;

static public
abstract function keywords();

public function heredocAndNowdoc()
{
$notAllowed = <<<COUNTEREXAMPLE
Wrong indentation.
Also, should be nowdoc.
COUNTEREXAMPLE;
}

public function shortClosures()
{
$identity =fn(int $x) :int=>$x ;

$sum = fn (int $x, int $y): int =>
$x + $y
;
}

public function trailingCommas()
{
$min = min(3, M_PI,);
$min = min(
3,
M_PI
);

[$foo, $bar,] = ['foo', 'bar',];
[
$foo,
$bar
] = [
'foo',
'bar'
];

list($foo, $bar,) = array('foo', 'bar',);
list(
$foo,
$bar
) = array(
'foo',
'bar'
);
}

public function chaining()
{
$this->foo()
->bar()->baz();
}
}
59 changes: 59 additions & 0 deletions tests/Fixtures/Integration/set/@PER.test-out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

abstract class PER
{
protected static string $keywords;

abstract public static function keywords();

public function heredocAndNowdoc()
{
$notAllowed = <<<'COUNTEREXAMPLE'
Wrong indentation.
Also, should be nowdoc.
COUNTEREXAMPLE;
}

public function shortClosures()
{
$identity = fn (int $x): int => $x;

$sum = fn (int $x, int $y): int
=> $x + $y;
}

public function trailingCommas()
{
$min = min(3, M_PI);
$min = min(
3,
M_PI,
);

[$foo, $bar] = ['foo', 'bar'];
[
$foo,
$bar,
] = [
'foo',
'bar',
];

list($foo, $bar) = array('foo', 'bar');
list(
$foo,
$bar,
) = array(
'foo',
'bar',
);
}

public function chaining()
{
$this
->foo()
->bar()
->baz();
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/Integration/set/@PER_php80.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--TEST--
Integration of @PER [PHP 8.0 version].
--RULESET--
{"@PER": true}
18 changes: 18 additions & 0 deletions tests/Fixtures/Integration/set/@PER_php80.test-in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class PER80
{
public function trailingCommas(
int|float $num
) {
$match = match ($num) {
3 => 'three',
M_PI => 'pi',
default => 'other'
};

$sum = fn (int $x,
int $y
) => $x + $y;
}
}
19 changes: 19 additions & 0 deletions tests/Fixtures/Integration/set/@PER_php80.test-out.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class PER80
{
public function trailingCommas(
int|float $num,
) {
$match = match ($num) {
3 => 'three',
M_PI => 'pi',
default => 'other',
};

$sum = fn (
int $x,
int $y,
) => $x + $y;
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/Integration/set/@PER_php81.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--TEST--
Integration of @PER [PHP 8.1 version].
--RULESET--
{"@PER": true}
Loading

0 comments on commit b02db11

Please sign in to comment.