1
- Extended Coding Style Guide Meta Document
2
- =========================================
1
+ # Coding Style Guide Meta Document
3
2
4
- # 1. Summary
3
+ ## 1. Summary
5
4
6
- This document describes the process and discussions that led to the Extended Coding
7
- Style PSR . Its goal is to explain the reasons behind each decision.
5
+ This document describes the process and discussions that led to the Coding
6
+ Style PER . Its goal is to explain the reasons behind each decision.
8
7
9
- # 2. Why Bother?
8
+ ## 2. Why Bother?
10
9
11
- PSR-2 was accepted in 2012 and since then a number of changes have been made to PHP,
12
- most notably recent changes for PHP 7 , which have implications for coding style
13
- guidelines. Whilst PSR-2 is very comprehensive of PHP functionality that existed at
10
+ PSR-12 was accepted in 2019 and since then a number of changes have been made to PHP,
11
+ most notably recent changes for PHP 8 and PHP 8.1 , which have implications for coding style
12
+ guidelines. Whilst PSR-12 is very comprehensive of PHP functionality that existed at
14
13
the time of writing, new functionality is very open to interpretation. PSR-12 seeks
15
14
to provide a set way that both coding style tools can implement, projects can declare
16
15
adherence to and developers can easily relate on between different projects for these
17
16
coding style reducing cognitive friction.
18
17
19
- PSR-2 was created based upon the common practices of the PHP-FIG projects at the time
20
- but ultimately this meant it was a compromise of many of the different projects' guidelines.
21
- The repercussions of projects changing their coding guidelines to align with PSR-2 (Almost
22
- all projects do align with PSR-1, even if it is not explicitly stated) were seen to be too
23
- great (losing git history, huge changesets and breaking existing patches/pull requests).
18
+ PSR-12 was an update for PSR-2 which was created based upon the common practices of the PHP-FIG
19
+ projects at the time but ultimately this meant it was a compromise of many of the different
20
+ projects' guidelines. The repercussions of projects changing their coding guidelines to align
21
+ with PSR-2 (Almost all projects do align with PSR-1, even if it is not explicitly stated) were
22
+ seen to be too great (losing git history, huge changesets and breaking existing patches/pull requests).
24
23
25
24
PSR-2 required adopters to reformat large amounts of existing code which stifled adoption.
26
25
To help alleviate this issue with PSR-12, we have taken a more prescriptive approach and
27
26
defined the standards for new language features as they are released.
28
27
29
- However it is for a lack of wanting to be dictatorial that we will aim to apply PSR-2
28
+ However, it is for a lack of wanting to be dictatorial that we aimed to apply PSR-2
30
29
styling, rationale and stances (Described in Section 4, Approaches) in PSR-12 instead of
31
30
establishing new conventions.
32
31
33
- # 3. Scope
32
+ The same approach is applied to the current PER.
34
33
35
- ## 3.1. Goals
34
+ ## 3. Scope
36
35
37
- This PSR shares the same goals as PSR-2.
36
+ ### 3.1. Goals
37
+
38
+ This PER shares the same goals as PSR-12.
38
39
39
40
> The intent of this guide is to reduce cognitive friction when scanning code from
40
41
> different authors. It does so by enumerating a shared set of rules and expectations
@@ -43,53 +44,52 @@ This PSR shares the same goals as PSR-2.
43
44
> of guidelines to be used among all those projects. Thus, the benefit of this guide is
44
45
> not in the rules themselves, but in the sharing of those rules.
45
46
46
- This PSR is an extension of PSR-2 , and therefore also an extension of PSR-1. The basis of
47
- PSR-12 is PSR-2 and therefore a list of differences is provided below to assist with migration
47
+ This PER is an extension of PSR-12 , and therefore also an extension of PSR-1. The basis of PER is
48
+ PSR-12 and therefore a list of differences is provided below to assist with migration,
48
49
but it should be considered as an independent specification.
49
50
50
- This PSR will include coding style guidelines related to new functionality added to PHP
51
- after the publication of PSR-2; this includes PHP 5.5, PHP 5.6 and PHP 7.0. This PSR will
52
- also include clarifications on the text of PSR-2, as described in the PSR-2 Errata .
51
+ This PER will include coding style guidelines related to new functionality added to PHP
52
+ after the publication of PSR-12. This PER will also include clarifications on the text of
53
+ PSR-12 .
53
54
54
- ## 3.2. Non-Goals
55
+ ### 3.2. Non-Goals
55
56
56
- It is not the intention of this PSR to add entirely new coding style guidelines. PSR-12 will
57
- also not change anything stipulated in PSR-1 and PSR-2 .
57
+ It is not the intention of this PER to add entirely new coding style guidelines. It will
58
+ also not change anything stipulated in PSR-1 and PSR-12 .
58
59
59
- # 4. Approaches
60
+ ## 4. Approaches
60
61
61
- The overarching approach is to attempt to apply existing PSR-2 styling and rationale to
62
+ The overarching approach is to attempt to apply existing PSR-12 styling and rationale to
62
63
new functionality as opposed to establishing new conventions.
63
64
64
- ## 4.1. Strict Types Declarations
65
+ ### 4.1. Strict Types Declarations
65
66
66
- There was a discussion about whether or not strict types should be enforced in the standard
67
+ There was a discussion about whether strict types should be enforced in the standard
67
68
https://github.com/cs-extended/fig-standards/issues/7 . All were in agreement we should only
68
69
use a MUST or MUST NOT statement and avoid the use of a SHOULD statement and nobody wanted
69
70
to say that strict types could not be declared. The discussion was whether it should be
70
- considered a coding style item which should be covered or whether it was out of scope and it
71
+ considered a coding style item which should be covered or whether it was out of scope, and it
71
72
was decided to be out of scope of a coding style guide.
72
73
73
- ## 4.2. Finally and Return Types Declaration Spacing
74
+ ### 4.2. Finally and Return Types Declaration Spacing
74
75
75
- Numerous different options were suggested and they can be seen
76
+ Numerous options were suggested, and they can be seen
76
77
[ here for return type declarations] ( https://gist.github.com/michaelcullum/c025f3870c9ea1dd2668#file-returntypesspacing-php ) or
77
78
[ here for finally blocks] ( https://gist.github.com/michaelcullum/c025f3870c9ea1dd2668#file-finallyblocks-php )
78
- and the current implementation was chosen due to consistency with other parts of the PSR-12
79
- specification that came from PSR-2.
79
+ and the current implementation was chosen due to consistency with other parts of the standard.
80
80
81
- ## 4.3. Enforcing short form for all type keywords
81
+ ### 4.3. Enforcing short form for all type keywords
82
82
83
83
PHP 7.0 introduced [ scalar types declaration] ( http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration )
84
- which does not support long type aliases. Therefore it makes sense to enforce primary short type forms to be used to
84
+ which does not support long type aliases. Therefore, it makes sense to enforce primary short type forms to be used to
85
85
have uniform syntax and prevent possible confusion.
86
86
87
- ## 4.4. Public Survey
87
+ ### 4.4. Public Survey
88
88
89
89
In order to settle things using data, survey was conducted and responses from 142 people
90
90
including 17 project representatives were gathered:
91
91
92
- ### 4.4.1. PHP-FIG Representative Results
92
+ #### 4.4.1. PHP-FIG Representative Results
93
93
94
94
| Representative | Project | Compound namespaces with a depth of two or more MUST not be used | Header statement grouping and ordering | Declare statements must each be on their own line | Declare statements in PHP files containing markup | Declare statements have no spaces: ` declare(strict_types=1); ` | Block declare statement formatting | ` new ` keyword usage, parenthesis required | Return type declaration formatting | Use statement leading slashes disallowed | Block namespace declaration formatting | General operator spacing | Try, Catch, Finally formatting | Anonymous class declaration formatting | Keyword casing, only lower case | Type keywords, short form only |
95
95
| -------------- | ------- | ---------------------------------------------------- | ---------------------------------- | ----------------------------------------- | ------------------------------------------- | -------------------------------------------------------- | ------------------------------- | ------------------------------------- | ------------------------------- | ------------------------------------ | ----------------------------------- | ---------------------- | --------------------------- | ----------------------------------- | --------------------------- | -------------------------- |
@@ -111,7 +111,7 @@ including 17 project representatives were gathered:
111
111
| Chuck Burgess | PEAR | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
112
112
| | ** Totals** : | 13/3| 15/1| 15/1| 13/3| 14/2| 15/1| 14/2| 15/1| 14/2| 14/2| 15/1| 16/0| 15/1| 15/1| 15/1|
113
113
114
- ### 4.4.2. General non-representative voters
114
+ #### 4.4.2. General non-representative voters
115
115
116
116
| Question | For | Against | Percentage For |
117
117
| -------- | --- | ------- | -------------- |
@@ -131,22 +131,22 @@ including 17 project representatives were gathered:
131
131
| Keyword casing, only lower case | 124 | 2 | 98.39% |
132
132
| Type keywords, short form only | 121 | 5 | 95.87% |
133
133
134
- ## 4.5. Multiline Function Arguments Mixed With Multiline Return
134
+ ### 4.5. Multiline Function Arguments Mixed With Multiline Return
135
135
136
136
A potential readability issue [ was raised on the mailing list] ( https://groups.google.com/d/msg/php-fig/ULSL4gqK8GY/cgDELuPOCQAJ ) .
137
137
We reviewed options for changes to the specification that could provide better readability and
138
138
the floated option was to require a blank line after the opening bracket of a function if the
139
- arguments and the return are both multiline. Instead it was pointed out that this specification
140
- _ already_ allows you to decide where you'd like to add blank lines and so we will leave it to
139
+ arguments and the return are both multiline. Instead, it was pointed out that this specification
140
+ _ already_ allows you to decide where you'd like to add blank lines, and so we will leave it to
141
141
the implementors to decide.
142
142
143
- # 5. Changelog from PSR-2
143
+ ## 5. Changelog
144
144
145
- Please note this changelog is not a verbose list of changes from PSR-2 but highlights the most
146
- notable changes. It should be considered a new specification and therefore you should read the
145
+ Please note this changelog is not a verbose list of changes from PSR-12 and further but highlights the most
146
+ notable changes. It should be considered a new specification, and therefore you should read the
147
147
specification for a full understanding of its contents.
148
148
149
- ## 5.1. New Statements
149
+ ### 5.1. New Statements
150
150
151
151
* Lowercase for all keywords - Section 2.5
152
152
* Short form for all type keywords - Section 2.5
@@ -165,7 +165,7 @@ specification for a full understanding of its contents.
165
165
* Ternary operators - Section 6.3
166
166
* Anonymous classes - Section 8
167
167
168
- ## 5.2. Clarifications and Errata
168
+ ### 5.2. Clarifications and Errata
169
169
170
170
* Adjust 'methods' to 'methods and functions' in a number of instances - Throughout
171
171
* Adjust references to classes and interfaces to also include traits - Throughout
@@ -176,36 +176,34 @@ specification for a full understanding of its contents.
176
176
* PSR-2 errata statement about extending multiple interfaces - Section 4
177
177
* Forbid blank lines before/after closing/opening braces for classes - Section 4
178
178
179
- # 6. People
179
+ ## 6. People
180
+
181
+ ### 6.1. Editor:
180
182
181
- ## 6.1. Editor:
182
- * Korvin Szanto
183
+ * Alexander Makarov
183
184
184
- ## 6.2. Sponsor:
185
+ ### 6.2. Sponsor:
185
186
186
- * Chris Tankersley
187
+ *
187
188
188
- ## 6.3. Working Group Members:
189
+ ### 6.3. Working Group Members:
189
190
190
- * Alessandro Lai
191
191
* Alexander Makarov
192
- * Michael Cullum
193
- * Robert Deutz
192
+ *
193
+ *
194
+ *
194
195
195
- ## 6.4. Special Thanks
196
+ ### 6.4. Special Thanks
196
197
197
- * Michael Cullum for drafting the original specification
198
- * Alexandar Makarov for coordinating the draft during PHP-FIG 2.0
199
- * Cees-Jan Kiewiet for moral support
198
+ * Everyone involved in PSR-1, PSR-2, PSR-12.
200
199
201
- # 7. Votes
200
+ ## 7. Votes
202
201
203
- * ** Entrance Vote:** https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/php-fig/P9atZLOcUBM/_jwkvlYKEAAJ
204
- * ** Approval Vote:** https://groups.google.com/forum/#!topic/php-fig/1uaeSMaDGbk
202
+ * ** Entrance Vote:**
203
+ * ** Approval Vote:**
205
204
206
- # 8. Relevant Links
205
+ ## 8. Relevant Links
207
206
208
207
_ ** Note:** Order descending chronologically._
209
208
210
- * [ Inspiration Mailing List Thread] ( https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/php-fig/wh9avopSR9k )
211
- * [ Initial Mailing List PSR Proposal Thread] ( https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/php-fig/MkFacLdfGso )
209
+ *
0 commit comments