From 14b99e0fed78ff3bdb184e11af1d1e3d3a8c8cab Mon Sep 17 00:00:00 2001 From: Robin Speekenbrink Date: Thu, 23 Jun 2022 11:25:07 +0200 Subject: [PATCH 1/2] feat: Include the example of using the shortform of a closure This explains the use of "spaces" around `fn ()` --- accepted/PSR-12-extended-coding-style-guide.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/accepted/PSR-12-extended-coding-style-guide.md b/accepted/PSR-12-extended-coding-style-guide.md index 8f3209c41..fa8f71340 100644 --- a/accepted/PSR-12-extended-coding-style-guide.md +++ b/accepted/PSR-12-extended-coding-style-guide.md @@ -929,7 +929,7 @@ $variable = $foo ?: 'bar'; ## 7. Closures Closures MUST be declared with a space after the `function` keyword, and a -space before and after the `use` keyword. +space before and after the `use` keyword. This includes the use of the `shortform notation`. The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body. @@ -958,6 +958,10 @@ $closureWithArgs = function ($arg1, $arg2) { // body }; +$shortClosureWithoutArgs = fn () => /* body */; + +$shortClosureWithArgs = fn ($arg1, $arg2) => /* body */; + $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) { // body }; From 416a54ac4ea217c5d7de933ffd090a34adcc5886 Mon Sep 17 00:00:00 2001 From: Robin Speekenbrink Date: Thu, 23 Jun 2022 11:36:45 +0200 Subject: [PATCH 2/2] feat: Also align the anonymous class declarations with the use of parentheses due to directly instantiating This change aligns the required use of parentheses as mentioned in chapter `4. Classes, Properties, and Methods`: > When instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. --- accepted/PSR-12-extended-coding-style-guide.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/accepted/PSR-12-extended-coding-style-guide.md b/accepted/PSR-12-extended-coding-style-guide.md index fa8f71340..35e4f22e9 100644 --- a/accepted/PSR-12-extended-coding-style-guide.md +++ b/accepted/PSR-12-extended-coding-style-guide.md @@ -1054,24 +1054,27 @@ in the above section. ~~~php