-
Notifications
You must be signed in to change notification settings - Fork 28
Add the PER-CS 3.0 to 3.1 migration guide #153
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
Open
rodrigoprimo
wants to merge
3
commits into
php-fig:master
Choose a base branch
from
rodrigoprimo:add-migration-guide-3.1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Migrating from PER-CS v3.0 to PER-CS v3.1 ### | ||
|
|
||
| ## Summary | ||
|
|
||
| This document describes the changes and additions on a section by section | ||
| basis between PER-CS v3.1 and PER-CS v3.0. | ||
|
|
||
| It is derived in part from [a GitHub-generated diff](https://github.com/php-fig/per-coding-style/compare/3.0.0...3.1.0#files_bucket) | ||
| and focuses on the changes on a section-by-section basis as its focus is to be more readable. | ||
|
|
||
| This document intends to provide a summary of these changes that can | ||
| then be used to drive action lists for toolset producers to support PER-CS v3.1. | ||
|
|
||
| This document is non-normative. The published [3.1 PER-CS](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md) specification | ||
| is the canonical source for the PER-CS formatting expectations. | ||
|
|
||
| ## [Section 4.7 - Method and Function Calls](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#47-method-and-function-calls) | ||
|
|
||
| The `clone()` function SHOULD always be called with parenthesis, even when the optional `$withProperties` argument is not provided. For example: | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $b = clone($a); | ||
| $b = clone($a, [ | ||
| 'foo' => 'bar', | ||
| ]); | ||
| ``` | ||
|
|
||
| ## [Section 5.2 - Switch, Case, and Match](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#52-switch-case-match) | ||
|
|
||
| The formatting rules for `switch` and `case` have been expanded and clarified: | ||
|
|
||
| * A `case` body MUST NOT be wrapped in `{}`. | ||
| * Every non-empty `case` MUST end with a terminating statement (`break`, `return`, or similar), even if it is the last one in the `switch` block. | ||
| * If a `case` condition is complex enough to warrant being multi-line, it MUST be wrapped in parentheses, with the opening parenthesis on the same line as the `case` keyword and a final line containing only the closing parenthesis and colon. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| switch (true) { | ||
| case ( | ||
| $a === 10 | ||
| && $b === 20 | ||
| ): | ||
| doSomething(); | ||
| break; | ||
| } | ||
| ``` | ||
|
|
||
| ## [Section 6.2 - Binary operators](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#62-binary-operators) | ||
|
|
||
| The pipe operator `|>` is now listed among the binary operators and, like the others, MUST be preceded and followed by at least one space. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $result = $input |> trim(...) |> strtoupper(...); | ||
| ``` | ||
|
|
||
| ## [Section 6.4 - Operator placement](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#64-operators-placement) | ||
|
|
||
| When a chain of pipe operators is split across multiple lines, the `|>` operator MUST be at the beginning of each line, and all lines but the first MUST be indented, following the same rule as other chained operators. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $result = '<foo>' | ||
| |> strtoupper(...) | ||
| |> htmlspecialchars(...); | ||
| ``` | ||
|
|
||
| ## [Section 7 - Closures](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#7-closures) | ||
|
|
||
| If a closure contains no statements, then the body MUST be abbreviated as `{}` and placed on the same line as the previous symbol, separated by a space. If possible, empty-body closures SHOULD be replaced with arrow functions. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $noOpFunction = function () {}; | ||
|
|
||
| // SHOULD be preferred where possible: | ||
| $noOpFunction = fn() => null; | ||
| ``` | ||
|
|
||
| ## [Section 8 - Anonymous Classes](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#8-anonymous-classes) | ||
|
|
||
| Formatting guidelines for attributes on anonymous classes are now included. If an anonymous class has attributes, they MUST be placed starting on the next line after the `new` keyword, indented once, and otherwise follow the same rules as other attributes specified in section 12. The remaining anonymous class declaration after the final attribute MUST start on a new line and keep the same indentation as the attributes: | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| $example = new | ||
| #[Attribute] | ||
| class { | ||
| // ... | ||
| }; | ||
| ``` | ||
|
|
||
| ## [Section 9 - Enumerations](https://github.com/php-fig/per-coding-style/blob/3.1.0/spec.md#9-enumerations) | ||
|
|
||
| Non-public enum methods were already required to use `private` instead of `protected`, as enums do not support inheritance. This rule was extended to also apply to constants. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| enum Size | ||
| { | ||
| case Small; | ||
| case Medium; | ||
| case Large; | ||
|
|
||
| private const Huge = self::Large; | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.