What is phpmd and how to use it?

I have Ubuntu 14.04 + Sublime text 3 and phpcs packages are installed

Additionally I installed phpcs and php-cs-fixer in my system

From this blog

I found that phpmd (PHP Mess Detector) is also a necessary library, so phpmd is installed according to the instructions the official php md page using an alternative method From the github repository, everything was finished.

 :~/phpmd$ curl -s http://getcomposer.org/installer | php #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /home/keshav/phpmd/composer.phar Use it: php composer.phar 

but now when I write on the terminal

  phpmd /opt/lampp/htdocs/myproject, myfile.php 

phpmd: command not found

There is phpmd in the home directory and all without errors.

I have a local project on the PHP core, create composer.json in the project folder according to the github suggestion.

Please tell me what it means

Then install Composer into your project (or download the composer directly):

+7
sublimetext3 composer-php phpmd
source share
2 answers

I think the problem is that you installed phpmd in a local directory, but you are trying to use it as if it was installed globally.

Installation instructions on linked sites may not be more understandable. Since you have already installed phpcs and php-cs-fixer and they work for you, just follow the same instructions for phpmd. These are all PHP projects and are installed in the same way.

In any case, to use phpmd as a global command, you have several options.

Github

Hide the github repository just like you do, and add the phpmd bin directory to your PATH variable .

Global Composer Installation

Use the global command command to install phpmd worldwide. You also need to make sure that the bin directory for the composer is in PATH . By default it is ~/.composer/vendor/bin .

 composer global require phpmd/phpmd 

This command will install phpmd globally, and once ~/.composer/vendor/bin is in your PATH , you can invoke it simply by calling phpmd .

This is very well explained in the composer's documentation: https://getcomposer.org/doc/03-cli.md#global

Download phar archive

This is the easiest thing you can do. Just go to the phpmd releases page, select the latest one and upload it to the phar archive .

Put the phar file anywhere. Just remember that this should be in your PATH . You can also rename it to skip the .phar extension.

For example:

 wget http://static.phpmd.org/php/2.1.3/phpmd.phar sudo mv phpmd.phar /usr/bin/phpmd sudo chmod +x /usr/bin/phpmd 

Dock container

First select the docker image using the static analysis tools for PHP :

 git pull jakzal/phpqa 

One of the tools provided by the image is phpmd. The command below starts phpmd in the docker container and mounts the current working directory as / project.

 docker run -it --rm -v $(pwd):/project -w /project jakzal/phpqa \ phpmd src text cleancode,codesize,controversial,design,naming,unusedcode 
+21
source share

When you use the composer installation, it is installed in the ./bin directory in the ./bin directory. Therefore, for me, in relation to the root directory of my project, it was here:

./vendor/bin/phpmd

And I was able to run it from my project by doing ./vendor/bin/phpmd . text codesize ./vendor/bin/phpmd . text codesize . (I don't get any useful output yet, but another problem)

0
source share

All Articles