PHPMD - the PHP Mess Detector -- is a code quality analysis tool for PHP, similar to PMD for Java.
Questions tagged [phpmd]
80 questions
68
votes
2 answers
PHP Mess Detector for Eclipse
I have the PTI Eclipse plugin installed.
There is a possibility to change PDepend, CodeSniffer and UnitTest
When I try right-clicking on any file I have a Mess Detector option as well but nothing happens when I click it. And after searching all…

Ilia Shakitko
- 1,417
- 2
- 18
- 25
21
votes
5 answers
Why does clean code forbid else expression
I have this code in a function:
if ($route !== null) { // a route was found
$route->dispatch();
} else {
// show 404 page
$this->showErrorPage(404);
}
Now PHPmd gives an error:
The method run uses an else expression. Else is never…

Pascal
- 2,175
- 4
- 39
- 57
17
votes
2 answers
what is phpmd and how to use it?
I have Ubuntu 14.04 + Sublime text 3 and installed phpcs packages
additionalty I have installed phpcs and php-cs-fixer on my system
From this blog
I have found that phpmd (PHP Mess Detector) is also a required library, so installed phpmd as per…

xkeshav
- 53,360
- 44
- 177
- 245
16
votes
2 answers
Why does switch(true) have a smaller NPath complexity than if() elseif()?
I have this function that is responsible for converting a file's name and mime-type into something more "human" (e.g. file.png, image/png to [Image, PNG]). What I found interesting was that groups of if() elseif() statements had a higher NPath…

Navarr
- 3,703
- 7
- 33
- 57
11
votes
4 answers
Avoid using static access to Exception
I've just fired up PHPMD for the first time and, predictably, I've got an error I can't figure out. The error is
Avoid using static access to class 'InvalidArgumentException' in
method 'setLang'.
and the code is
public function setLang($val0)…

Ben
- 54,723
- 49
- 178
- 224
8
votes
1 answer
PHPMD cannot run with parameters
I've been trying to configure phpmd to work with PhpStorm, but I'm stuck here.
Here's the error I have:
PHP Mess Detector
phpmd: Can not correctly run the tool with parameters:
C:/Users/me/AppData/Local/Temp/___18.tmp/folder/myclass.php
xml
…

Tristan Rollet
- 81
- 1
- 3
6
votes
2 answers
How to ignore specific rule for specific directory in PHPMD
command
phpmd app,config,routes text phpmd.xml
I use phpmd on Laravel project, there is a rule named CouplingBetweenObjects under design.xml, I want to ignore all files in app/Http/Controllers directory to this rule, phpmd only provide --exclude…

Chan
- 1,947
- 6
- 25
- 37
5
votes
1 answer
How to locally turn off phpmd rule in a comment?
How can I locally disable a single phpmd rule for a few lines and then re-enable a rule, for example the unusedcode?

ThorSummoner
- 16,657
- 15
- 135
- 147
5
votes
2 answers
Why does this code have high cyclomatic complexity - or is it a bug in PHPMD in Jenkins?
I'm trying to understand how Cyclomatic Complexity works and how I can avoid the warnings. Yes, I understand that the goal of writing code is not to avoid arbitrary warnings, but I'd at least like to know what's going on so I can decide if the code…

matt
- 1,947
- 1
- 19
- 29
4
votes
1 answer
PHP Mess Detector avoid using static access
i use PHP Mess Detector on my Laravel controller invokable class and i got message like this
Avoid using static access to class 'Illuminate\Support\Facades\Cache' in method '__invoke'
Can anyone explain it why i must avoid using static access on…

Panji Setya Nur Prawira
- 629
- 1
- 10
- 24
4
votes
1 answer
PHPMD and Coupling Between Object classes (CBO)
I'm working on a Magento 2 CRUD functionality following the best practices (best described here). On the project I'm working on we are using PHPMD (php mess detector). Among other rules, we have the CBO limit set to 13 (which I understand is the…

Radu
- 1,159
- 3
- 22
- 40
4
votes
1 answer
Unused foreach value in static code analyzers
Static code analyzers like (in this specific case) PHPMD bemoan an error in the following piece of PHP code:
foreach ($aSomething as $key => $value) {
... do something with the $key only
}
The error:
Avoid unused local variables such as…

Patrick
- 691
- 8
- 30
4
votes
1 answer
Cyclomatic complexity difference between switch/cases and in_array
Scenario
I need to check if my $type_id variable is one of a certain set of IDs.
For no reason other than readability, I went with
switch($type_id) {
case Type::SOME_TYPE:
case Type::SOME_OTHER_TYPE:
...
//do stuff
where most of…

Alec
- 1,986
- 4
- 23
- 47
4
votes
1 answer
PHPMD and PHPCS Camelcase for Tests
I just installed both PHPMD and PHPCS with my Project.
Now, I would like to customize them a bit, but can't seem to achieve it.
I get 2 warnings that I would like to remove for all my project:
phpcs: public method name…

Juliatzin
- 18,455
- 40
- 166
- 325
4
votes
1 answer
PHPMD Catch/Suppress fatal errors
I'm trying to automate my testing. As a smoke test I would like to check my PHP code with PHPMD before continuing with the actual Unit tests. Sounds sensible enough right?
Thing is that PHPMD seems to crash when fatal errors arise in my PHP files.…

Maarten Bicknese
- 1,498
- 1
- 14
- 27