Questions tagged [phpmd]

PHPMD - the PHP Mess Detector -- is a code quality analysis tool for PHP, similar to PMD for Java.

80 questions
4
votes
2 answers

How to write a PHP Mess Detector rule that has a project wide context instead of only on a class level?

I would like to write a rule to find all the public unused functions in a project. I have copied and amended the original UnusedPrivateMethod to work. But alas it works too good and finds ALL the public functions in the project. It does so because…
David 'the bald ginger'
  • 1,296
  • 3
  • 20
  • 38
3
votes
1 answer

Can all PHP mess-detecter checks be replaced with PHP code-sniffer checks?

I have a project which uses both PHPMD (PHP Mess Detector) and PHPCS (PHP Code Sniffer) which got me wondering if all PHPMD checks can be replaced with PHPCS checks or is it best to use both in tandem? The list of PHPMD checks seems to be here:…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
2 answers

Setting exceptions to a rule in phpmd

I'm trying to set an exception to a rule in phpmd, to allow one specific function name to be just 2 characters in length The previous phpmd.xml.dist file was working quite happily with:
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
3
votes
2 answers

else is never necessary and you can simplify the code to work without else

I got a message of PHPMD telling me: else is never necessary and you can simplify the code to work without else on this portion of code: if ($settings == null) { $settings = new self($arrSettings); } else { …
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
3
votes
2 answers

SublimeLinter: modules phpcs and phpmd not working

in Sublime Text 3 I have installed via the Package Manager following packages: SublimeLinter SublimeLinter-phpmd SublimeLinter-phpcs and few others.. The problem is that neither phpmd or phpcs are working. When opening a php file in ST3 and then…
Alex
  • 4,607
  • 9
  • 61
  • 99
3
votes
3 answers

PhpStorm - How to detect PHP error "Non-static method should not be called statically"?

With PHP, static method can be used in both static method and non-static method, and non-static method can only used in non-static method. That's why calling a dynamic method statically generates the E_STRICT error. For example:
Guicara
  • 1,668
  • 2
  • 20
  • 34
3
votes
0 answers

PHP Mess detector - Cannot create new nodes, when internal state is frozen

I am tring to run phpmd like this: wget -c http://static.phpmd.org/php/latest/phpmd.phar php phpmd.phar ./src text cleancode codesize I get the following error message and I don't know what to do. Cannot create new nodes, when internal state is…
3
votes
2 answers

PHPMD says violating Single Responsibility Principle for argument having boolean default value

These two PHP class methods violates Single Responsibility Principle (SRP) according to the phpmd rule booleanargumentflag. How should they be written to avoid this? If the solution is to remove the default value "= true", then how is this improving…
Mikael Roos
  • 285
  • 3
  • 15
3
votes
1 answer

PHPMD - include a whole ruleset and configure the properties

I am using the PHPMD (http://phpmd.org/) and I am quite new to this. The MD works, I am now writing a ruleset to configure what metrics should be used. Instead of including each rule individually, I load the whole rulesets. But now I have the…
Alex K.
  • 707
  • 1
  • 11
  • 25
3
votes
1 answer

PHPMD - Avoid using Static Access to class - Using a constant?

I am using PHP Mess Detector 1.5.0 and have a number of issues, that I do not believe are issues. class FOO { const NEW_LINE = "\n"; const ADD = 1; const DELETE = 2; ... public function __construct($OptionOne = self::ADD) { …
Steven Scott
  • 10,234
  • 9
  • 69
  • 117
3
votes
2 answers

How can I set PHPMD rule properties?

I'm new to using PHP Mess Detector (PHPMD) and want to teak some of the parameters. For example, the naming rules are giving me output like this: "Avoid variables with short names like $id. Configured minimum length is 3." Can I change the…
fazy
  • 2,095
  • 18
  • 30
3
votes
1 answer

Looking for a way to stop a process while calling a function without return

I have developped an habit of using a return to stop a code sequence from executing, even if the return is used on a function that returns nothing $form = $this->getForm('activity'); $this->view->form = $form; return $this->render('create'); //…
JF Dion
  • 4,014
  • 2
  • 24
  • 34
2
votes
0 answers

Is "$id" class property name too short?

When used as property of an object, for example User::id or File::id, name "id" makes perfect sense in my opinion. However PHP Mess Detector complains: Avoid variables with short names like $id. I understand, that $id as a local variable is not…
Piotr Maj
  • 63
  • 6
2
votes
1 answer

What is the best place for tools like phpcpd, phpmd, php_codesniffer

What is the best place for tools like phpcpd, phpmd, php_codesniffer to include them in composer require-dev section or install as phar archive somewhere in the system? When they are included in require-dev often it is not possible to update for…
klipach
  • 818
  • 7
  • 21
2
votes
2 answers

PHP Mess Detector giving false positives

I'm working with an open source project and thought it would be a good idea to implement automated code revisions with phpmd. It showed me many coding mistakes that im fixing already. But one of them made me curious. Consider the following…
CarlosCarucce
  • 3,420
  • 1
  • 28
  • 51