benmatselby / sublime-phpcs

🔍 PHP CodeSniffer, PHP Coding Standard Fixer, Linter, and Mess Detector Support for Sublime Text
Other
811 stars 127 forks source link

[Phpcs] env: php: No such file or directory #177

Closed whiteheadrj closed 7 years ago

whiteheadrj commented 7 years ago

I am stumped.

I have reviewed the config option (http://benmatselby.github.io/sublime-phpcs/#configuration) I have reviewed the common errors in the FAQ in the readme (https://github.com/benmatselby/sublime-phpcs/blob/master/README.md) While similar to https://github.com/benmatselby/sublime-phpcs/issues/116, it isn't quite the same.

OS: MacOS 10.12.16 PHP 5.3.29 PHPMD installed today via composer

I am getting the following output in the console when trying to run phpmd triggered by the save event:

[Phpcs] Project files:
[Phpcs]  Current: /Users/rjwhitehead/Documents/nsaWeb.sublime-project
[Phpcs]  Last Known: /Users/rjwhitehead/Documents/nsaWeb.sublime-project
[Phpcs] Project files are the same, skipping reload
[Phpcs] /Users/rjwhitehead/.composer/vendor/bin/phpmd /Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php text codesize,unusedcode
[Phpcs] /Users/rjwhitehead/.composer/vendor/bin/phpmd /Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php text codesize,unusedcode
[Phpcs] cwd: /Users/rjwhitehead
[Phpcs] env: php: No such file or directory

[Phpcs] MessDetector found 0 errors

However, I can copy and paste the command into the terminal and it works just fine:

$ which phpmd
/Users/rjwhitehead/.composer/vendor/bin/phpmd
$ /Users/rjwhitehead/.composer/vendor/bin/phpmd /Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php text codesize,unusedcode
/Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php:5    The class dispatch has 86 public methods and attributes. Consider reducing the number of public items to less than 45.
/Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php:5    The class dispatch has 86 fields. Consider redesigning dispatch to keep the number of fields under 15.
/Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php:131  The method getDispatchFromDB() has 198 lines of code. Current threshold is set to 100. Avoid really long methods.

Here is my current user config:

{
    // Plugin settings

    // Turn the debug output on/off
    "show_debug": true,

    // Which file types (file extensions), do you want the plugin to
    // execute for
    "extensions_to_execute": ["php","cgi"],

    // Do we need to blacklist any sub extensions from extensions_to_execute
    // An example would be ["twig.php"]
    "extensions_to_blacklist": [],

    // Execute the sniffer on file save
    "phpcs_execute_on_save": true,

    // Show the error list after save.
    "phpcs_show_errors_on_save": true,

    // Show the errors in the gutter
    "phpcs_show_gutter_marks": true,

    // Show outline for errors
    "phpcs_outline_for_errors": true,

    // Show the errors in the status bar
    "phpcs_show_errors_in_status": true,

    // Show the errors in the quick panel so you can then goto line
    "phpcs_show_quick_panel": true,

    // The path to the php executable.
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_php_prefix_path": "",

    // Options include:
    // - Sniffer
    // - Fixer
    // - Mess Detector
    //
    // This will prepend the application with the path to php
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_commands_to_php_prefix": [],

    // What color to stylise the icon
    // https://www.sublimetext.com/docs/3/api_reference.html#sublime.View
    // add_regsions
    "phpcs_icon_scope_color": "comment",

    // PHP_CodeSniffer settings

    // Do you want to run the phpcs checker?
    "phpcs_sniffer_run": false,

    // Execute the sniffer on file save
    "phpcs_command_on_save": true,

    // It seems python/sublime cannot always find the phpcs application
    // If empty, then use PATH version of phpcs, else use the set value
    "phpcs_executable_path": "/Users/rjwhitehead/.composer/vendor/bin/phpcs",

    // Additional arguments you can specify into the application
    //
    // Example:
    // {
    //     "--standard": "PEAR",
    //     "-n"
    // }
    "phpcs_additional_args": {
        "--standard": "PSR2",
        "-n": ""
    },

    // PHP-CS-Fixer settings

    // Fix the issues on save
    "php_cs_fixer_on_save": false,

    // Show the quick panel
    "php_cs_fixer_show_quick_panel": false,

    // Path to where you have the php-cs-fixer installed
    "php_cs_fixer_executable_path": "/Users/rjwhitehead/.composer/vendor/bin/php-cs-fixer",

    // Additional arguments you can specify into the application
    "php_cs_fixer_additional_args": {

    },

    // phpcbf settings

    // Fix the issues on save
    "phpcbf_on_save": false,

    // Show the quick panel
    "phpcbf_show_quick_panel": false,

    // Path to where you have the phpcbf installed
    "phpcbf_executable_path": "/Users/rjwhitehead/.composer/vendor/bin/phpcbf",

    // Additional arguments you can specify into the application
    //
    // Example:
    // {
    //     "--level": "all"
    // }
    "phpcbf_additional_args": {
        "--standard": "PSR2",
        "-n": ""
    },

    // PHP Linter settings

    // Are we going to run php -l over the file?
    "phpcs_linter_run": false,

    // Execute the linter on file save
    "phpcs_linter_command_on_save": true,

    // It seems python/sublime cannot always find the php application
    // If empty, then use PATH version of php, else use the set value
    "phpcs_php_path": "/usr/local/bin/php",

    // What is the regex for the linter? Has to provide a named match for 'message' and 'line'
    "phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)",

    // PHP Mess Detector settings

    // Execute phpmd
    "phpmd_run": true,

    // Execute the phpmd on file save
    "phpmd_command_on_save": true,

    // It seems python/sublime cannot always find the phpmd application
    // If empty, then use PATH version of phpmd, else use the set value
    "phpmd_executable_path": "/Users/rjwhitehead/.composer/vendor/bin/phpmd",

    // Additional arguments you can specify into the application
    //
    // Example:
    // {
    //     "codesize,unusedcode"
    // }
    "phpmd_additional_args": {
        "codesize,unusedcode":""
    },

    // PHP Scheck settings

    // Execute scheck
    "scheck_run": false,

    // Execute the scheck on file save
    "scheck_command_on_save": false,

    // It seems python/sublime cannot always find the scheck application
    // If empty, then use PATH version of scheck, else use the set value
    "scheck_executable_path": "/Users/rjwhitehead/pfff/scheck",

    // Additional arguments you can specify into the application
    //
    //Example:
    //{
    //  "-php_stdlib" : "/path/to/pfff",
    //  "-strict" : ""
    //}
    "scheck_additional_args": {
        "-strict" : ""
    }
}

Hopefully, I am missing something silly. Thanks for your help.

benmatselby commented 7 years ago

@whiteheadrj

Hi there, you may need to set this:

    // Options include:
    // - Sniffer
    // - Fixer
    // - Mess Detector
    //
    // This will prepend the application with the path to php
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_commands_to_php_prefix": [],
whiteheadrj commented 7 years ago

I have modified the phpcs_commands_to_php_prefix setting per your recommendation:

    // The path to the php executable.
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_php_prefix_path": "/usr/local/bin/php",

    // Options include:
    // - Sniffer
    // - Fixer
    // - Mess Detector
    //
    // This will prepend the application with the path to php
    // Needed for windows, or anyone who doesn't/can't make phars
    // executable. Avoid setting this if at all possible
    "phpcs_commands_to_php_prefix": ["Mess Detector"],

I also changed phpmd_executable_path to not have to redirect through a symbolic link.

I am still having the same issue:

[Phpcs] Project files:
[Phpcs]  Current: /Users/rjwhitehead/Documents/nsaWeb.sublime-project
[Phpcs]  Last Known: /Users/rjwhitehead/Documents/nsaWeb.sublime-project
[Phpcs] Project files are the same, skipping reload
[Phpcs] /Users/rjwhitehead/.composer/vendor/phpmd/phpmd/src/bin/phpmd /Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php text codesize,unusedcode
[Phpcs] /Users/rjwhitehead/.composer/vendor/phpmd/phpmd/src/bin/phpmd /Users/rjwhitehead/nsaWeb/webroot/globals/utils/dispatch.class.php text codesize,unusedcode
[Phpcs] cwd: /Users/rjwhitehead
[Phpcs] env: php: No such file or directory

[Phpcs] MessDetector found 0 errors
benmatselby commented 7 years ago

@whiteheadrj

I think there is a type in our docs. Try this:

"phpcs_commands_to_php_prefix": ["MessDetector"],
whiteheadrj commented 7 years ago

That solved it. Thanks! I created a pull request to update the doc so that other people don't run into the same issue.

benmatselby commented 7 years ago

@whiteheadrj Sorry about the delay! Thank you for replying and raising the PR