Skip to content

Commit af462c8

Browse files
authored
Merge pull request #56 from Crell/formatting-cleanup
Assorted formatting and wording cleanup.
2 parents a78a842 + 7b098dc commit af462c8

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

spec.md

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Short form of type keywords MUST be used i.e. `bool` instead of `boolean`,
131131
### 2.6 Trailing commas
132132

133133
Numerous PHP constructs allow a sequence of values to be separated by a comma,
134-
and the final item may have an optional comma. Examples include array key/value pairs,
134+
and the final item may have an optional comma. Examples include array key/value pairs,
135135
function arguments, closure `use` statements, `match()` statement branches, etc.
136136

137137
If that list is contained on a single line, then the last item MUST NOT have a trailing comma.
@@ -279,6 +279,7 @@ Declare statements MUST NOT contain any spaces and MUST be exactly `declare(stri
279279

280280
Block declare statements are allowed and MUST be formatted as below. Note position of
281281
braces and spacing:
282+
282283
```php
283284
declare(ticks=1) {
284285
// some code
@@ -293,15 +294,15 @@ Any closing brace MUST NOT be followed by any comment or statement on the
293294
same line.
294295

295296
When instantiating a new class, parentheses MUST always be present even when
296-
there are no arguments passed to the constructor.
297+
there are no arguments passed to the constructor. For example:
297298

298299
```php
299300
new Foo();
300301
```
301302

302303
If class contains no additional declarations (such as an exception that exists only extend another exception with a new type),
303304
then the body of the class SHOULD be abbreviated as `{}` and placed on the same line as the previous symbol,
304-
separated by a space. For example:
305+
separated by a space. For example:
305306

306307
```php
307308
class MyException extends \RuntimeException {}
@@ -312,15 +313,13 @@ class MyException extends \RuntimeException {}
312313
The `extends` and `implements` keywords MUST be declared on the same line as
313314
the class name.
314315

315-
The opening brace for the class MUST go on its own line; the closing brace
316-
for the class MUST go on the next line after the body.
317-
318-
Opening braces MUST be on their own line and MUST NOT be preceded or followed
319-
by a blank line.
316+
The opening brace for the class MUST go on its own line, and MUST NOT be
317+
preceded or followed by a blank line.
320318

321-
Closing braces MUST be on their own line and MUST NOT be preceded by a blank
322-
line.
319+
The closing brace for the class MUST go on its own line, immediately following
320+
the last line of the class body, and MUST NOT be preceded by a blank line.
323321

322+
The following is a validly formatted class:
324323

325324
```php
326325
<?php
@@ -340,7 +339,7 @@ class ClassName extends ParentClass implements \ArrayAccess, \Countable
340339
Lists of `implements` and, in the case of interfaces, `extends` MAY be split
341340
across multiple lines, where each subsequent line is indented once. When doing
342341
so, the first item in the list MUST be on the next line, and there MUST be only
343-
one interface per line.
342+
one interface per line. For example:
344343

345344
```php
346345
<?php
@@ -365,22 +364,11 @@ class ClassName extends ParentClass implements
365364
The `use` keyword used inside the classes to implement traits MUST be
366365
declared on the next line after the opening brace.
367366

368-
```php
369-
<?php
370-
371-
namespace Vendor\Package;
372-
373-
use Vendor\Package\FirstTrait;
374-
375-
class ClassName
376-
{
377-
use FirstTrait;
378-
}
379-
```
380-
381367
Each individual trait that is imported into a class MUST be included
382368
one-per-line and each inclusion MUST have its own `use` import statement.
383369

370+
The following is a correct example of trait usage.
371+
384372
```php
385373
<?php
386374

@@ -400,6 +388,7 @@ class ClassName
400388

401389
When the class has nothing after the `use` import statement, the class
402390
closing brace MUST be on the next line after the `use` import statement.
391+
For example:
403392

404393
```php
405394
<?php
@@ -414,7 +403,7 @@ class ClassName
414403
}
415404
```
416405

417-
Otherwise, it MUST have a blank line after the `use` import statement.
406+
Otherwise, it MUST have a blank line after the `use` import statement, as in:
418407

419408
```php
420409
<?php
@@ -431,7 +420,7 @@ class ClassName
431420
}
432421
```
433422

434-
When using the `insteadof` and `as` operators they must be used as follows taking
423+
When using the `insteadof` and `as` operators they MUST be used as follows taking
435424
note of indentation, spacing, and new lines.
436425

437426
```php
@@ -525,7 +514,7 @@ function fooBarBaz($arg1, &$arg2, $arg3 = [])
525514

526515
If a function or method contains no statements (such as a no-op implementation or when using
527516
constructor property promotion), then the body SHOULD be abbreviated as `{}` and placed on the same
528-
line as the previous symbol, separated by a space. For example:
517+
line as the previous symbol, separated by a space. For example:
529518

530519
```php
531520
class Point
@@ -552,7 +541,7 @@ In the argument list, there MUST NOT be a space before each comma, and there
552541
MUST be one space after each comma.
553542

554543
Method and function parameters with default values MUST go at the end of the argument
555-
list.
544+
list. For example:
556545

557546
```php
558547
<?php
@@ -574,7 +563,7 @@ next line, and there MUST be only one argument per line.
574563

575564
When the argument list is split across multiple lines, the closing parenthesis
576565
and opening brace MUST be placed together on their own line with one space
577-
between them.
566+
between them. For example:
578567

579568
```php
580569
<?php
@@ -596,7 +585,7 @@ class ClassName
596585
When you have a return type declaration present, there MUST be one space after
597586
the colon followed by the type declaration. The colon and declaration MUST be
598587
on the same line as the argument list closing parenthesis with no spaces between
599-
the two characters.
588+
the two characters. For example:
600589

601590
```php
602591
<?php
@@ -623,7 +612,7 @@ class ReturnTypeVariations
623612
```
624613

625614
In nullable type declarations, there MUST NOT be a space between the question mark
626-
and the type.
615+
and the type. For example:
627616

628617
```php
629618
<?php
@@ -667,7 +656,7 @@ public function process(string $algorithm, &...$parts)
667656
### 4.6 Modifier Keywords
668657

669658
Classes, properties, and methods have numerous keyword modifiers that alter how the
670-
engine and language handles them. When present, they MUST be in the following order:
659+
engine and language handles them. When present, they MUST be in the following order:
671660

672661
* Inheritance modifier: `abstract` or `final`
673662
* Visibility modifier: `public`, `protected`, or `private`
@@ -678,6 +667,8 @@ engine and language handles them. When present, they MUST be in the following o
678667

679668
All keywords MUST be on a single line, and MUST be separated by a single space.
680669

670+
The following is a correct example of modifier keyword usage:
671+
681672
```php
682673
<?php
683674

@@ -711,6 +702,8 @@ after the opening parenthesis, and there MUST NOT be a space before the
711702
closing parenthesis. In the argument list, there MUST NOT be a space before
712703
each comma, and there MUST be one space after each comma.
713704

705+
The following lines show correct calls:
706+
714707
```php
715708
<?php
716709

@@ -725,6 +718,8 @@ next line, and there MUST be only one argument per line. A single argument being
725718
split across multiple lines (as might be the case with an anonymous function or
726719
array) does not constitute splitting the argument list itself.
727720

721+
The following examples show correct argument usage.
722+
728723
```php
729724
<?php
730725

@@ -748,14 +743,14 @@ $app->get('/hello/{name}', function ($name) use ($app) {
748743
```
749744

750745
If using named arguments, there MUST NOT be a space between the argument name
751-
and colon, and there MUST be a single space between the colon and the argument value.
746+
and colon, and there MUST be a single space between the colon and the argument value. For example:
752747

753748
```php
754749
somefunction($a, b: $b, c: 'c');
755750
```
756751

757752
Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first
758-
method MUST be on the next line.
753+
method MUST be on the next line. For example:
759754

760755
```php
761756
$someInstance
@@ -768,7 +763,7 @@ $someInstance
768763

769764
A function or method may be referenced in a way that creates a closure out of it, by providing `...` in place of arguments.
770765

771-
If so, the `...` MUST NOT include any whitespace before or after. That is, the correct format is `foo(...)`.
766+
If so, the `...` MUST NOT include any whitespace before or after. That is, the correct format is `foo(...)`.
772767

773768
## 5. Control Structures
774769

@@ -815,6 +810,8 @@ placed together on their own line with one space between them. Boolean
815810
operators between conditions MUST always be at the beginning or at the end of
816811
the line, not a mix of both.
817812

813+
For example:
814+
818815
```php
819816
<?php
820817

@@ -867,6 +864,8 @@ placed together on their own line with one space between them. Boolean
867864
operators between conditions MUST always be at the beginning or at the end of
868865
the line, not a mix of both.
869866

867+
For example:
868+
870869
```php
871870
<?php
872871

@@ -936,7 +935,7 @@ do {
936935
Expressions in parentheses MAY be split across multiple lines, where each
937936
subsequent line is indented at least once. When doing so, the first condition
938937
MUST be on the next line. Boolean operators between conditions MUST
939-
always be at the beginning or at the end of the line, not a mix of both.
938+
always be at the beginning or at the end of the line, not a mix of both. For example:
940939

941940
```php
942941
<?php
@@ -965,7 +964,7 @@ for ($i = 0; $i < 10; $i++) {
965964
Expressions in parentheses MAY be split across multiple lines, where each
966965
subsequent line is indented at least once. When doing so, the first expression
967966
MUST be on the next line. The closing parenthesis and opening brace MUST be
968-
placed together on their own line with one space between them.
967+
placed together on their own line with one space between them. For example:
969968

970969
```php
971970
<?php
@@ -1023,7 +1022,7 @@ All operators not described here are left undefined.
10231022
### 6.1. Unary operators
10241023

10251024
The increment/decrement operators MUST NOT have any space between
1026-
the operator and operand.
1025+
the operator and operand:
10271026

10281027
```php
10291028
$i++;
@@ -1063,6 +1062,7 @@ $variable = $foo ? 'foo' : 'bar';
10631062

10641063
When the middle operand of the conditional operator is omitted, the operator
10651064
MUST follow the same style rules as other binary [comparison][] operators:
1065+
10661066
```php
10671067
$variable = $foo ?: 'bar';
10681068
```
@@ -1194,7 +1194,7 @@ The `=>` symbol MUST be preceded and succeeded by a space.
11941194

11951195
The semicolon at the end of the expression MUST NOT be preceded by a space.
11961196

1197-
The expression portion MAY be split to a subsequent line. If so, the `=>` MUST be included
1197+
The expression portion MAY be split to a subsequent line. If so, the `=>` MUST be included
11981198
on the second line, and MUST be indented once.
11991199

12001200
The following examples show proper common usage of short closures.
@@ -1231,7 +1231,7 @@ the list of `implements` interfaces does not wrap. If the list of interfaces
12311231
wraps, the brace MUST be placed on the line immediately following the last
12321232
interface.
12331233

1234-
If the anonymous class has no arguments, the `()` after `class` MUST be omitted.
1234+
If the anonymous class has no arguments, the `()` after `class` MUST be omitted. For example:
12351235

12361236
```php
12371237
<?php
@@ -1260,17 +1260,19 @@ $instance = new class($a) extends \Foo implements
12601260

12611261
Enumerations (enums) MUST follow the same guidelines as classes, except where otherwise noted below.
12621262

1263-
Methods in enums MUST follow the same guidelines as methods in classes. Non-public methods MUST use `private`
1263+
Methods in enums MUST follow the same guidelines as methods in classes. Non-public methods MUST use `private`
12641264
instead of `protected`, as enums do not support inheritance.
12651265

12661266
When using a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one
1267-
space between the colon and the backing type. This is consistent with the style for return types.
1267+
space between the colon and the backing type. This is consistent with the style for return types.
12681268

1269-
Enum case declarations MUST use PascalCase capitalization. Enum case declarations MUST be on their own line.
1269+
Enum case declarations MUST use PascalCase capitalization. Enum case declarations MUST be on their own line.
12701270

12711271
Constants in Enumerations MAY use either PascalCase or UPPER_CASE capitalization. PascalCase is RECOMMENDED,
12721272
so that it is consistent with case declarations.
12731273

1274+
The following example shows a typical valid Enum:
1275+
12741276
```php
12751277
enum Suit: string
12761278
{
@@ -1296,6 +1298,7 @@ indentation they are declared in.
12961298

12971299
The following is ***not allowed*** due to the heredoc beginning on a
12981300
different line than the context it's being declared in:
1301+
12991302
```php
13001303
$notAllowed =
13011304
<<<'COUNTEREXAMPLE'
@@ -1306,11 +1309,12 @@ $notAllowed =
13061309
COUNTEREXAMPLE;
13071310
```
13081311

1309-
Instead the heredoc MUST be declared on the same line as the variable
1312+
Instead, the heredoc MUST be declared on the same line as the variable
13101313
declaration it's being set against.
13111314

13121315
The follow is ***not allowed*** due to the scope indention not matching the scope the
13131316
heredoc is declared in:
1317+
13141318
```php
13151319
function notAllowed()
13161320
{
@@ -1328,6 +1332,7 @@ it's declared in.
13281332

13291333
The following is an example of both a heredoc and a nowdoc declared in a
13301334
compliant way:
1335+
13311336
```php
13321337
function allowed()
13331338
{
@@ -1383,6 +1388,8 @@ MUST be placed on the next line after the last value. There MUST NOT be more
13831388
than one value assignment per line. Value assignments MAY use a single line
13841389
or multiple lines.
13851390

1391+
The following example shows correct array usage:
1392+
13861393
```php
13871394
<?php
13881395

@@ -1421,12 +1428,12 @@ be placed on their own line, immediately prior to the structure being described.
14211428
For attributes on parameters, if the parameter list is presented on a single line,
14221429
the attribute MUST be placed inline with the parameter it describes, separated by a single space.
14231430
If the parameter list is split into multiple lines for any reason, the attribute MUST be placed on
1424-
its own line prior to the parameter, indented the same as the parameter. If the parameter list
1431+
its own line prior to the parameter, indented the same as the parameter. If the parameter list
14251432
is split into multiple lines, a blank line MAY be included between one parameter and the attributes
14261433
of the following parameter in order to aid readability.
14271434

14281435
If a comment docblock is present on a structure that also includes an attribute, the comment block MUST
1429-
come first, followed by any attributes, followed by the structure itself. There MUST NOT be any blank lines
1436+
come first, followed by any attributes, followed by the structure itself. There MUST NOT be any blank lines
14301437
between the docblock and attributes, or the attributes and the structure.
14311438

14321439
If two separate attribute blocks are used in a multi-line context, they MUST be on separate lines with no blank
@@ -1435,7 +1442,7 @@ lines between them.
14351442
### 12.3 Compound attributes
14361443

14371444
If multiple attributes are placed in the same attribute block, they MUST be separated by a comma with a space
1438-
following but no space preceding. If the attribute list is split into multiple lines for any reason, then the
1445+
following but no space preceding. If the attribute list is split into multiple lines for any reason, then the
14391446
attributes MUST be placed in separate attribute blocks. Those blocks may themselves contain multiple
14401447
attributes provided this rule is respected.
14411448

0 commit comments

Comments
 (0)