-3

I'm trying to set up PHP Coding Standards Fixer with PhpStorm but when I run the code auto formatter (Ctrl Alt L) I get an error:

PHP External Formatter: Process exited with non-zero code

error bubble

Clicking the notification doesn’t expands any info and I don't know where to get this output or code.

I had set PHP CS Fixer as the external formatter in "Quality tools", activated the inspection in "Quality tools > PHP CS Fixer" and the validate for "PHP CS Fixer path" does not show any issues.

I have also setted "Run built-in formatter before external formatter" in Advanced settings.

I have my .php-cs-fixer.dist.php not in the root of my project but in a symfony folder (so path is symfony/.php-cs-fixer.dist.php). Could this be the issue? How can I set this path if it is the case?

How can I fix this error? I would prefer not to ignore it...

4
  • 1) Check idea.log file for possible hints (Help | Show Log in XXX) 2) If it has nothing -- add extra logging and try again (see instructions in this comment: youtrack.jetbrains.com/issue/… ) Commented Sep 10 at 12:42
  • I checked the logs and they don't show anything usefull, nothing about the formatter or quality tools, I checked the link and it seems that the issue should be solved in those but I still get the error bubble Commented Sep 11 at 10:02
  • @Saleck: The linked comment is for the instructions how you raise the log-level so that more details are being logged -- not for saying it's the same issue :D -- And thining: You could however open support ticket in the tracker and ask for individual support for your issue, the vendor might be interested in what problems may arise with the tooling, e.g. perhaps it's useful feedback for them to have the status-code numerical as well in the notification Commented Sep 11 at 10:31
  • @Saleck The link for instructions on how to get more detailed logs, which will include the full command that IDE runs, all params and the output (that can give clues on what can be wrong). Commented Sep 11 at 11:27

1 Answer 1

1

PHP External Formatter: Process exited with non-zero code

Validate the configuration in Settings > PHP > Quality Tools > PHP CS Fixer by opening your current Configuration by clicking the button with the three dots (...).

In the now open PHP CS Fixer dialog press the Validate button.

At the bottom of the dialog an info admonition should become visible showing "OK, PHP CS Fixer [version ...]". Additionally the PHP version is shown. This should be the one you selected.

FYI: PhpStorm uses the PHP version from the system, at least this is what it did for me. Not in this dialog info, but when executing, e.g. the time when you see the notice about the non-zero exit status code.

I'd therefore recommend to configure the "System PHP" as well, because it will show the PHP version as PhpStorm finds it and this info can be obtained as well.

You can now close this dialog.


After obtaining this information, use the configured path of the PHP CS Fixer PHP script and execute it in your terminal (ALT + F12):

$ /path/to/bin/php-cs-fixer help fix
...
  ---------
  
  Exit code of the `fix` command is built using following bit flags:
  
... eight more lines ...
# E_SUCCESS - exit code 0

At the very end you find the description of the PHP CS Fixer (PHP External Formatter) exit code. As we only know it is non-zero, these are your potential causes:

  • General error (or PHP minimal requirement not matched).
  • Configuration error of the application.
  • Configuration error of a Fixer.
  • Exception raised within the application.
  • 255 - Fatal Error during the execution of the PHP CS Fixer PHP script invocation (not shown in the help output of the PHP script itself)

With the information you were able to obtain by validating the configuration above, you now have to verify your coding standards configuration if they are compatible with the PHP runtime configuration that is in use.

Locate your PHP CLI SAPI configuration initialization files ("php.ini") and temporarily enable error logging to a known and accessible error log file location of yours. Then provoke the error message again and consult the log file.

You will likely see the stack trace of an exception or some other message about a PHP Fatal Error.


Could this be the issue? [Your PHP CS Fixer PHP Script configuration file location]

Likely not. PhpStorm invokes the PHP CS Fixer External Formatter on a single file copied to a temporary location with the chosen standard (Ruleset) given via command line arguments.

When you configure your custom standard, this is an option PhpStorm supports, you specify the standard location under Settings > PHP > Quality Tools > PHP CS Fixer by selecting the Custom Ruleset (dropdown box) and it requires an absolute pathname.

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

6 Comments

why is this down voted so much
@ReyDebida: Because development is hard and tooling is harder ;) Honestly, I can only guess, perhaps the OP didn't note whether or not it worked without their special configuration file. It's a bit of asking too many things at once. That is especially not that useful while troubleshooting as others can't look on their computer/box.
I followed this instructions and it worked "outside" of PHPStorm, the command did failed the first time bucause I had an incorrect rule, I fixed it and now it runs on the command line
I followed this instructions and it worked "outside" of PHPStorm, the command did failed the first time bucause I had an incorrect rule, I fixed it and now it runs on the command line but keeps sending an error inside PHPStorm. The weird thing is... I think its working because when I try to format a file that I have previously formatted outside, it has no changes, and if I first format it inside PHPStorm and then on the command line it's the same, it has no changes but it stills shows the error...
Is this the same in all permutations: A: [Internal: Off, External: On] B: [Internal: On, External: On] C: [Internal: Off, External: On + PSR2 Ruleset] D: [Internal: On, External: On + PSR2 Ruleset] --- Just "Yes" (Error)/"No" (Working)/"Different-Error" for all four variants.
Yes, I tried internal On and Off and with different rulesets for the CD Fixer (Symfony, PSR2 and custom) and all of them gave me the same super undescriptive error...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.