diff --git a/spec.md b/spec.md index f5c590a..f677e76 100644 --- a/spec.md +++ b/spec.md @@ -131,7 +131,7 @@ Short form of type keywords MUST be used i.e. `bool` instead of `boolean`, ### 2.6 Trailing commas Numerous PHP constructs allow a sequence of values to be separated by a comma, -and the final item may have an optional comma. Examples include array key/value pairs, +and the final item may have an optional comma. Examples include array key/value pairs, function arguments, closure `use` statements, `match()` statement branches, etc. 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 Block declare statements are allowed and MUST be formatted as below. Note position of braces and spacing: + ```php declare(ticks=1) { // some code @@ -293,7 +294,7 @@ Any closing brace MUST NOT be followed by any comment or statement on the same line. When instantiating a new class, parentheses MUST always be present even when -there are no arguments passed to the constructor. +there are no arguments passed to the constructor. For example: ```php new Foo(); @@ -301,7 +302,7 @@ new Foo(); If class contains no additional declarations (such as an exception that exists only extend another exception with a new type), then the body of the class SHOULD be abbreviated as `{}` and placed on the same line as the previous symbol, -separated by a space. For example: +separated by a space. For example: ```php class MyException extends \RuntimeException {} @@ -312,15 +313,13 @@ class MyException extends \RuntimeException {} The `extends` and `implements` keywords MUST be declared on the same line as the class name. -The opening brace for the class MUST go on its own line; the closing brace -for the class MUST go on the next line after the body. - -Opening braces MUST be on their own line and MUST NOT be preceded or followed -by a blank line. +The opening brace for the class MUST go on its own line, and MUST NOT be +preceded or followed by a blank line. -Closing braces MUST be on their own line and MUST NOT be preceded by a blank -line. +The closing brace for the class MUST go on its own line, immediately following +the last line of the class body, and MUST NOT be preceded by a blank line. +The following is a validly formatted class: ```php get('/hello/{name}', function ($name) use ($app) { ``` If using named arguments, there MUST NOT be a space between the argument name -and colon, and there MUST be a single space between the colon and the argument value. +and colon, and there MUST be a single space between the colon and the argument value. For example: ```php somefunction($a, b: $b, c: 'c'); ``` Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first -method MUST be on the next line. +method MUST be on the next line. For example: ```php $someInstance @@ -768,7 +763,7 @@ $someInstance A function or method may be referenced in a way that creates a closure out of it, by providing `...` in place of arguments. -If so, the `...` MUST NOT include any whitespace before or after. That is, the correct format is `foo(...)`. +If so, the `...` MUST NOT include any whitespace before or after. That is, the correct format is `foo(...)`. ## 5. Control Structures @@ -815,6 +810,8 @@ placed together on their own line with one space between them. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both. +For example: + ```php ` symbol MUST be preceded and succeeded by a space. The semicolon at the end of the expression MUST NOT be preceded by a space. -The expression portion MAY be split to a subsequent line. If so, the `=>` MUST be included +The expression portion MAY be split to a subsequent line. If so, the `=>` MUST be included on the second line, and MUST be indented once. 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 wraps, the brace MUST be placed on the line immediately following the last interface. -If the anonymous class has no arguments, the `()` after `class` MUST be omitted. +If the anonymous class has no arguments, the `()` after `class` MUST be omitted. For example: ```php