【问题标题】:Sublime-phpcs - Can't get PHP MD and CS packages to function properlySublime-phpcs - 无法让 PHP MD 和 CS 包正常运行
【发布时间】:2014-09-10 20:17:22
【问题描述】:

我一直在尝试配置 sublime-phpcs。我已经安装了 pear 并从命令行安装了 PHP_CodeSnifferPHPMD 使用他们记录的安装过程。 PHP 和 pear 在我的路径 d:/Program Files/xampp/php 和 d:/Program Files/xampp/php/pear 中,我可以在目录之外使用它们。我在用户配置文件中将 PHPCodeSniffer、PHPMD 和 showdebug 设置为 true,但在保存时没有突出显示或概述,只能在控制台中看到错误。说完就报错:

[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

我已重新启动服务器并在所有安装后重新打开 sublimetext。

更新 响应 Sergey 的帮助,将 phpcs 可执行路径添加到用户设置中。

[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

更新 2 响应 Sergey 的帮助,将 phpmd 可执行路径添加到用户设置中。

[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

有人遇到过这个问题吗?

【问题讨论】:

    标签: php pear sublimetext3 codesniffer phpmd


    【解决方案1】:

    尝试打开PHPCS设置:Preferences → Package Settings → PHP Code Sniffer → Settings — User

    将此添加到设置文件中:

    {
        "phpcs_executable_path": "some_path"
    }
    

    其中some_path是phpcs的可执行路径(如果你已经在Windows中通过PEAR命令安装了它,它的可执行文件是PHP根目录下的phpcs.bat)。 :)

    例如,我安装了代码嗅探器,它的可执行文件是D:\dev\php\phpcs.bat。所以我的配置是

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

    Sublime-phpcs 也不适用于我,直到我在其配置中设置了 phpcs_executable_path

    更新:我从您的问题更新中看到,现在您还需要设置phpmd_executable_path。我还将在此清单中使用您的 PHP 路径。

    {
        "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
    }
    

    【讨论】:

    • 嗨,我像你提到的那样将 phpcs_executable_path 更改为“D:\\Program Files\\xampp\\php\\phpcs.bat”,并且还注意到默认值中的 phpcs_php_path,并添加了 D:\ \Program Files\\xampp\\php 在用户设置中添加到它。这绝对是我的一部分,但我仍然收到同样的错误,并且没有 php 错误通知。
    • @mtpultz 让我们从添加phpcs_executable_path 开始,不添加任何其他内容,不添加phpcs_php_path?不好了。我们还需要添加"show_debug": true。我已经更新了我的代码清单。见上文。
    • 嗨,好的,我已经完成了,现在 sublime 控制台中显示了一个空白错误列表。编辑器中没有行指示器或突出显示,底部的错误消息已更改。我已编辑问题以反映更改。
    • 猜猜这意味着添加到phpmd的路径?但我实际上找不到 pear 安装它的位置。
    • @mtpultz 我在我的答案中添加了另一个列表。请参阅“更新”部分。
    猜你喜欢
    • 2013-12-24
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    相关资源
    最近更新 更多