1

I am currently trying to use the PEAR Coding Standards and I can't get anonymous functions to align correctly in function calls. Here is an example :

What is recommended by the standards:

test(
    function () {
        return "";
    }
);

This works by default.

However, as soon as I have more than one parameter, PhpStorm unindents the function content and closing brace :

test(
    "test", function () {
return "";
}
);

But what is recommended by the standards is the following :

test(
    "test", function () {
        return "";
    }
);

Note: When enabling "Function declaration parameters" > "Align when multiline", I have the correct alignment if I put each parameter on its own line :

test(
    "test", 
    function () {
        return "";
    }
);

I couldn't find a way to make this possible without having to put each parameter on its own line, would someone if this is possible/how to do it ?

Note 2 : I loaded the PEAR Coding Style using the "Predefined Style" already implemented out of the box in PhpStorm and only did little tweaks.

Note 3 : I am using PHPCS to check my code. Here are the errors I get with the PhpStorm-formatted code :

4 | ERROR | [x] Line indented incorrectly; expected at least 8 spaces, found 4 (PEAR.WhiteSpace.ScopeIndent.Incorrect)

5 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0 (PEAR.WhiteSpace.ScopeIndent.IncorrectExact)

5 | ERROR | [x] Multi-line function call not indented correctly; expected 4 spaces but found 0 | | (PEAR.Functions.FunctionCallSignature.Indent)

5 | ERROR | [x] Closing brace indented incorrectly; expected 4 spaces, found 0 (PEAR.WhiteSpace.ScopeClosingBrace.Indent)

Line 4 is the line where the return ""; is.

2
  • Could you link the coding standards you're referring to? I've looked at pear.php.net/manual/en/standards.php and can't find a part about anonymous functions. Commented Aug 7, 2018 at 19:10
  • To be honest, I haven't read the standards thoroughly. I am using PHPCS which checks that I am following the PEAR standards. (This post is therefore more about being able to indent anonymous functions regarding to the start of the function keyword.) I updated the post to include the errors I get from PHPCS. Commented Aug 10, 2018 at 17:23

1 Answer 1

2

Unfortunately there's no setting to adjust for that case. It looks like a bug similar to https://youtrack.jetbrains.com/issue/WI-32914, https://youtrack.jetbrains.com/issue/WI-25700 and https://youtrack.jetbrains.com/issue/WI-35221. Feel free to add a comment with your example at e.g. https://youtrack.jetbrains.com/issue/WI-32914 or submit your own bug report

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for showing these to me. It is exactly the case anonymous function structures in the first link. These posts were posted years ago, I'm guessing they have more urgent matters at hand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.