2

I've been trying to configure sublime-phpcs. I've installed pear and from command line installed PHP_CodeSniffer, and PHPMD using their documented install procedures. PHP and pear are in my path at d:/Program Files/xampp/php and d:/Program Files/xampp/php/pear, and I can use them outside of the directories. I set PHPCodeSniffer, PHPMD, and showdebug to be true in the user config file, but on save nothing get highlighted or outlined, can only see an error in the console. It pops an error after saying:

[Phpcs] phpcs --report=checkstyle --standard=PSR2 -n D:\htdocs\ubc\app\main\source\plugins\project\core\class-cse-meta-boxes.php
[Phpcs] phpcs --report=checkstyle --standard=PSR2 -n D:\htdocs\ubc\app\main\source\plugins\project\core\class-cse-meta-boxes.php
[Phpcs] cwd: C:\Users\mtpultz
Exception in thread Thread-183:
Traceback (most recent call last):
File "X/subprocess.py", line 1090, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "X/threading.py", line 639, in _bootstrap_inner
File "X/threading.py", line 596, in run
File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 433, in run
File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 139, in get_errors
File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 215, in execute
File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 218, in parse_report
File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 169, in shell_out
File "X/subprocess.py", line 818, in __init__
File "X/subprocess.py", line 1096, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

I've restarted the server and reopened sublimetext after all installs.

UPDATE In response to Sergey's help with the addition of the phpcs executable path to user settings.

[Phpcs] phpmd D:\htdocs\ubc\app\main\source\plugins\ubc\core\class-cse-meta-boxes.php text codesize,unusedcode,naming
[Phpcs] phpmd D:\htdocs\ubc\app\main\source\plugins\ubc\core\class-cse-meta-boxes.php text codesize,unusedcode,naming
[Phpcs] cwd: C:\Users\mtpultz
Exception in thread Thread-183:
Traceback (most recent call last):
  File "X/subprocess.py", line 1090, in _execute_child
  FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "X/threading.py", line 639, in _bootstrap_inner
  File "X/threading.py", line 596, in run
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 435, in run
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 139, in get_errors
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 311, in execute
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 314, in parse_report
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 169, in shell_out
  File "X/subprocess.py", line 818, in __init__
  File "X/subprocess.py", line 1096, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

UPDATE 2 In response to Sergey's help with the addition of the phpmd executable path to user settings.

[Phpcs] D:\Program Files\xampp\php\pear\phing\tasks\ext\phpmd D:\htdocs\ubc\app\main\source\plugins\ubc-petrography\core\class-cse-meta-boxes.php text codesize,unusedcode,naming
[Phpcs] D:\Program Files\xampp\php\pear\phing\tasks\ext\phpmd D:\htdocs\ubc\app\main\source\plugins\ubc-petrography\core\class-cse-meta-boxes.php text codesize,unusedcode,naming
[Phpcs] cwd: C:\Users\mtpultz
Exception in thread Thread-18:
Traceback (most recent call last):
  File "X/subprocess.py", line 1090, in _execute_child
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "X/threading.py", line 639, in _bootstrap_inner
  File "X/threading.py", line 596, in run
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 435, in run
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 139, in get_errors
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 311, in execute
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 314, in parse_report
  File "phpcs in C:\Users\mtpultz\AppData\Roaming\Sublime Text 3\Installed Packages\Phpcs.sublime-package", line 169, in shell_out
  File "X/subprocess.py", line 818, in __init__
  File "X/subprocess.py", line 1096, in _execute_child
PermissionError: [WinError 5] Access is denied

Anyone had this issue?

mtpultz
  • 17,267
  • 22
  • 122
  • 201

1 Answers1

2

Try to open PHPCS settings: Preferences → Package Settings → PHP Code Sniffer → Settings — User

Add this to the settings file:

{
    "phpcs_executable_path": "some_path"
}

Where some_path is the phpcs's executable path (if you have installed it by PEAR command in Windows, its executable file is phpcs.bat in root folder of PHP). :)

For example, I have installed code sniffer and its executable is D:\dev\php\phpcs.bat. So my config is

{
    "phpcs_executable_path": "D:\\dev\\php\\phpcs.bat",
    // Enable debug to see verbose output
    "show_debug": true
}

Sublime-phpcs did not work for me, too, until I've set phpcs_executable_path in its config.

Update: As I see from your question update, right now you need also set phpmd_executable_path. Also I will use your path to PHP in this listing.

{
    "phpcs_executable_path": "D:\\Program Files\\xampp\\php\\phpcs.bat",
    "phpmd_executable_path": "D:\\Program Files\\xampp\\php\\phpmd.bat",
    // Enable debug to see verbose output
    "show_debug": true
}
Ronin
  • 1,688
  • 1
  • 13
  • 23
  • Hi, I changed phpcs_executable_path to "D:\\Program Files\\xampp\\php\\phpcs.bat" like you mentioned, and also noticed phpcs_php_path in the defaults, and added D:\\Program Files\\xampp\\php to it in the user settings. That's definitely an oversite on my part, but I'm still getting the same error, and no php error notifications. – mtpultz Jul 20 '14 at 17:35
  • 1
    @mtpultz Let's start only with adding `phpcs_executable_path` without anything else, without `phpcs_php_path`? Oh, no. Also we need to add `"show_debug": true`. I've updated my code listing. See above. – Ronin Jul 20 '14 at 17:46
  • Hi, okay I've done that and a list of whitespace errors are now showing up in the sublime console. No line indicators or highlighting in the editor, and the error message at the bottom has changed. I've edited the question to reflect the changes. – mtpultz Jul 20 '14 at 18:06
  • Guess that means add the path to phpmd? but I can't actually find where pear installed it. – mtpultz Jul 20 '14 at 18:11
  • 1
    @mtpultz I've added another one listing to my answer. See 'Update' section. – Ronin Jul 20 '14 at 18:20
  • Hi, okay I've added the executable path to phpmd, and the error message has changed again, but no other visual changes. I updated the question with the new error message. – mtpultz Jul 20 '14 at 18:31
  • I've also added the php executable path as D:\\Program Files\\xampp\\php. It was like fireworks, every whitespace error on my page lit up :) Thanks so much for the help. Do you use PHP CS Fixer? I was unsure if I wanted to add that and have it automagically making changes. It doesn't install with pear, would you put it in the php folder and run php-cs-fixer.phar file? – mtpultz Jul 20 '14 at 18:34
  • Got php-cs-fixer to run, was missing: "phpcs_commands_to_php_prefix": ["Fixer"] in user settings. – mtpultz Jul 20 '14 at 22:50
  • @mtpultz Great! It works! :) Sorry, I was off line. Thank you for selecting my answer. – Ronin Jul 21 '14 at 16:02