このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 最新のリビジョン 両方とも次のリビジョン | ||
psr:psr12 [2020/07/11 17:30] y2sunlight [8. 匿名クラス] |
psr:psr12 [2020/07/28 14:05] tanaka [PSR-12: Extended Coding Style] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | > 編集中 | ||
- | |||
====== PSR-12: Extended Coding Style ====== | ====== PSR-12: Extended Coding Style ====== | ||
--- // | --- // | ||
- | 本章は、若干の補足を加筆してはいるものの単に[[https:// | + | 本章は、若干の補足を加筆してはいるものの単に[[https:// |
関連記事 | 関連記事 | ||
行 20: | 行 18: | ||
* [[psr: | * [[psr: | ||
* [[psr: | * [[psr: | ||
- | * [[psr: | + | * [[psr: |
+ | * [[psr: | ||
+ | * [[psr: | ||
+ | * [[psr: | ||
+ | * [[psr: | ||
----- | ----- | ||
行 911: | 行 913: | ||
===== 7. クロージャー ====== | ===== 7. クロージャー ====== | ||
- | |||
- | Closures MUST be declared with a space after the function keyword, and a space before and after the use keyword. | ||
クロージャーは、'' | クロージャーは、'' | ||
- | |||
- | The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body. | ||
開き中括弧( '' | 開き中括弧( '' | ||
- | |||
- | There MUST NOT be a space after the opening parenthesis of the argument list or variable list, and there MUST NOT be a space before the closing parenthesis of the argument list or variable list. | ||
引数リストまたは変数リストの開き丸括弧( '' | 引数リストまたは変数リストの開き丸括弧( '' | ||
- | |||
- | In the argument list and variable list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. | ||
引数リストと変数リストでは、各カンマの前にスペースがあってはならず( '' | 引数リストと変数リストでは、各カンマの前にスペースがあってはならず( '' | ||
- | |||
- | Closure arguments with default values MUST go at the end of the argument list. | ||
デフォルト値を持つクロージャー引数は、引数リストの最後に配置する必要があります( '' | デフォルト値を持つクロージャー引数は、引数リストの最後に配置する必要があります( '' | ||
- | If a return type is present, it MUST follow the same rules as with normal functions and methods; if the use keyword is present, the colon MUST follow the use list closing parentheses with no spaces between the two characters. | + | 戻り値の型が存在する場合、通常の関数とメソッドと同じルールに従う必要があります( '' |
- | + | ||
- | 戻り値の型が存在する場合、通常の関数とメソッドと同じルールに従う必要があります( '' | + | |
- | + | ||
- | A closure declaration looks like the following. Note the placement of parentheses, | + | |
クロージャー宣言は次のようになります。丸括弧( '' | クロージャー宣言は次のようになります。丸括弧( '' | ||
行 955: | 行 943: | ||
}; | }; | ||
</ | </ | ||
- | |||
- | Argument lists and variable lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument or variable per line. | ||
引数リストと変数リストは、複数の行に分割されてもよく( '' | 引数リストと変数リストは、複数の行に分割されてもよく( '' | ||
- | |||
- | When the ending list (whether of arguments or variables) is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. | ||
最後のリスト(引数または変数に関係なく)が複数の行に分割されている場合、閉じ丸括弧( '' | 最後のリスト(引数または変数に関係なく)が複数の行に分割されている場合、閉じ丸括弧( '' | ||
- | |||
- | The following are examples of closures with and without argument lists and variable lists split across multiple lines. | ||
以下は、複数行に分割された引数リストと変数リストがある場合とない場合のクロージャーの例です。 | 以下は、複数行に分割された引数リストと変数リストがある場合とない場合のクロージャーの例です。 | ||
行 1017: | 行 999: | ||
</ | </ | ||
- | Note that the formatting rules also apply when the closure is used directly in a function or method call as an argument. | + | クロージャーが関数またはメソッドの呼び出しで引数として直接使用される場合にも、フォーマッティング・ルールが適用されることに注意してください。 |
- | + | ||
- | クロージャーが関数またはメソッドの呼び出しで引数として直接使用される場合にも、フォーマットルールが適用されることに注意してください。 | + | |
<code php> | <code php> |