sublimetext3sublimelinterphpmdphpcs

SublimeLinter: modules phpcs and phpmd not working


in Sublime Text 3 I have installed via the Package Manager following packages:

The problem is that neither phpmd or phpcs are working. When opening a php file in ST3 and then clicking: ctrl and ` I get following debug info:

SublimeLinter: debug mode: on 
SublimeLinter: temp directory: c:\users\alekspav\appdata\local\temp\SublimeLinter3-alekspav 
SublimeLinter: annotations activated: <builtin> 
SublimeLinter: json activated: <builtin> 
SublimeLinter: WARNING: phpcs deactivated, cannot locate 'phpcs' 
SublimeLinter: annotations activated: <builtin> 
SublimeLinter: WARNING: jshint deactivated, cannot locate 'jshint' 
SublimeLinter: php activated: C:\xampp\php\php.exe 
SublimeLinter: WARNING: phpmd deactivated, cannot locate 'phpmd'
SublimeLinter: WARNING: htmltidy deactivated, cannot locate 'tidy' 
SublimeLinter: WARNING: csslint deactivated, cannot locate 'csslint' 
SublimeLinter: php: submitter.php ['C:\\xampp\\php\\php.exe', '-l', '-n', '-d', 'display_errors=On', '-d', 'log_errors=Off'] 
SublimeLinter: php output:
No syntax errors detected in - 

I am particularry interested in these 2 lines:

What I tried to do to fix the problem is to edit users config file: Sublime text 3: Preferences -> package settings -> sublime linter-> settings - user

And then added cmd key as following:

    "phpcs": {
        "@disable": false,
        "args": [],
        "cmd": "C:/xampp/htdocs/web/vendor/bin/phpcs/",
        "excludes": [],
        "standard": "PSR2"
    },
    "phpmd": {
        "@disable": false,
        "args": [],
        "cmd": "C:/xampp/htdocs/web/vendor/bin/phpmd/",
        "excludes": [],
        "rulesets": "cleancode,codesize,controversial,design,naming,unusedcode"
    }

As you have guessed - this didn't resolve the issue. I also tried to write path without / at the end and also tried to use \ delimeter instead of /. And I also tried to specify PFAM file directly.. And also tried to use ${project} variable rather than whole C:/ path. I am still getting warnings after ST3 restart.

My other question would be - how to output "${project}" directory in debug window? Because I am not sure it is set correctly so I want to test it.

More info:

Sublime project directory is: C:\xampp\htdocs\web\test.sublime-project

Here are phpmd and phpcs installations:

Edit:

Seems like I was doing it wrong. I have added a composer.json into project directory with following contents:

{
    "require-dev": {
        "squizlabs/php_codesniffer": "2.*",
        "phpmd/phpmd" : "@stable",
        "mongodb/mongodb" : "@dev"
    }
}

After installing everything with composer install command - I got vendor folder created for me with lots of directories inside, including the bin folder. It has all the necessary files now, but I am still getting the same error. Modules could not be found for some reason.


Solution

  • Okay,

    I am not sure if it's a bug or a feature, but I found the solution to the problem.

    1. First - you have to install phpcs and phpmd using the pear! Without this - you will see the warnings from initial post.

    phpcs: pear install PHP_CodeSniffer

    phpmd: instructions here: http://pear.phpmd.org/ (I do not remember the name of another repository but during the first installation you will encounter the error that some lib is missing and you will be prompted with a text to add one more repository which has missing dependencies for phpmd pear installation. All easy)

    Start ST3 and check. No edits in configuration are necessary. Both modules should be working in Sublime Text 3! But we are now using the pear modules instead of composer modules. My initial idea was to use the conmposer. It is much easier to mantain and update.

    In case you are not familliar with it - google. In project directory you should have a file called composer.json with the content similar to:

    {
        "require-dev": {
            "squizlabs/php_codesniffer":    "2.*",
            "phpmd/phpmd" :                 "@stable"
        }
    }
    

    Then go and install all modules using the Windows command prompt with composer install command

    1. As adressed in intiail post - in user config of SublimeLinter use the following config:

          "phpcs": {
              "@disable": false,
              "args": [],
              "cmd": "${project}/vendor/bin/phpcs.bat",
              "excludes": [],
              "standard": "${project}/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/ruleset.xml"
          },
          "phpmd": {
              "@disable": false,
              "args": [],
              "cmd": "${project}/vendor/bin/phpmd.bat",
              "excludes": [],
              "rulesets": "cleancode,codesize,controversial,design,naming,unusedcode"
          }
      

    Now restart Sublime test 3 and turn on debugging and open PHP file. Result is:

    reloading plugin SublimeLinter-phpcs.linter
    SublimeLinter: phpcs linter loaded 
    reloading plugin SublimeLinter-phpmd.linter
    SublimeLinter: phpmd linter loaded 
    ...
    reloading settings Packages/User/SublimeLinter.sublime-settings
    SublimeLinter: phpcs activated: C:\xampp\php\phpcs.bat 
    SublimeLinter: phpmd activated: C:\xampp\php\phpmd.bat 
    ...
    SublimeLinter: phpcs: index.php ['C:/xampp/htdocs/web/vendor/bin/phpcs.bat', '--report=checkstyle', '--standard=C:/xampp/htdocs/web/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/ruleset.xml'] 
    SublimeLinter: phpcs output:
    .. errors in PHP file listed
    Package Control: Skipping automatic upgrade, last run at 2016-09-05 17:12:20, next run at 2016-09-05 18:12:20 or after
    ...
    SublimeLinter: phpmd: index.php ['C:/xampp/htdocs/web/vendor/bin/phpmd.bat', '@', 'text', 'cleancode,codesize,controversial,design,naming,unusedcode'] 
    SublimeLinter: phpmd output:
    .. errors in PHP file listed
    

    As you can see - SublimeLinter first loads the pear bats in PHP directory! But when submitting the PHP file for analysis - it is using the new bats in project directory.

    My explanation is that SublimeLinter always needs pear phpcs and phpmd to be installed before using composer equivalents. This is quite stupid, if you ask me.. but I couldn't find any other solution.