Php_codesniffer: VSCode / Homebrew on MacOS: UnexpectedValueException

Created on 31 May 2018  ยท  7Comments  ยท  Source: squizlabs/PHP_CodeSniffer

Just a head's up. I don't know if this is a Homebrew problem or something you guys can control. I recently started seeing errors like this in VS Code (extra line breaks to make it easier to read):

phpcs: Uncaught UnexpectedValueException: 
DirectoryIterator::__construct(/usr/local/etc/php-code-sniffer/Standards): 
failed to open dir: 
No such file or directory in /usr/local/Cellar/php-code-sniffer/3.2.3/src/Util/Standards.php:93

This used to work out of the box, so I'm not sure what has changed. On my system, there is no /usr/local/etc/php-code-sniffer. The closest is /usr/local/opt/php-code-sniffer -- which is a symlink to the /usr/local/Cellar/... installation. However, that doesn't contain the Standards directory that's being looked for.

In short, I had to change my /usr/local/Cellar/php-code-sniffer/3.2.3/CodeSniffer.conf file to the following to get it to work:

// OLD CONFIG
<?php
 $phpCodeSnifferConfig = array (
  'installed_paths' => '/usr/local/etc/php-code-sniffer/Standards',
)
?>

// WORKING CONFIG
<?php
 $phpCodeSnifferConfig = array (
  'installed_paths' => '/usr/local/opt/php-code-sniffer/src/Standards',
)
?>

This is MacOS 10.12.6 using brew with [email protected] installed.

Wanted to put this here in case anyone else is having the same problem.

Question

Most helpful comment

Had the same error.

It's not vscode related, you can run phpcs on terminal and same error will be fired.

This happened to me after run brew prune.

Anyway, you can fix by reinstalling PHP CodeSniffer, in my case, brew reinstall php-code-sniffer.

All 7 comments

I don't think this has anything to do with PHPCS itself and I'm not sure what is going on, so I'll just leave it open for a while to see if anyone else comments.

Had the same error.

It's not vscode related, you can run phpcs on terminal and same error will be fired.

This happened to me after run brew prune.

Anyway, you can fix by reinstalling PHP CodeSniffer, in my case, brew reinstall php-code-sniffer.

@skydiver Thanks, that seems to have worked. I don't remember running prune before the errors started happening, but it's possible.

It's pretty strange, though. Prior to reinstalling, I had a lots of files / directories in /usr/local/Cellar/php-code-sniffer/3.2.3 -- including that CodeSniffer.conf file. Now, it's just this:

.
โ”œโ”€โ”€ .brew
โ”‚ย ย  โ””โ”€โ”€ php-code-sniffer.rb
โ”œโ”€โ”€ INSTALL_RECEIPT.json
โ””โ”€โ”€ bin
    โ”œโ”€โ”€ phpcbf
    โ””โ”€โ”€ phpcs

Actually, I just took a look at the history for the formula and it looks like it was significantly refactored on March 31.

https://github.com/Homebrew/homebrew-core/pull/25957

Anyway, for anyone else who may hit this problem, reinstalling is the best method for fixing it.

Thanks for posting a solution.

I can't debug in peace, please help. ๐Ÿ˜ฑ

screen shot 2018-08-18 at 09 06 39

@odahcam I'm not sure what problem you are asking about. I don't know why you are getting an exception in VSCode (I don't maintain the plugin there) but it is just reporting version info, as you've found.

Let's try to report that there then, thanks.

Was this page helpful?
0 / 5 - 0 ratings