Skip to content

Commit 0a2c305

Browse files
authored
feat(tool): PHP Mess Detector (#23)
1 parent c5788d1 commit 0a2c305

File tree

11 files changed

+1083
-0
lines changed

11 files changed

+1083
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ phpctl sh echo 'Hello, World!' # To run arbitrary sh commands inside the contain
9090
|----------------|-------------------------------------------------------------------------------------------------------------------------------|
9191
| `phpunit` | [PHPUnit](https://phpunit.de) is a programmer-oriented testing framework for PHP. |
9292
| `php-cs-fixer` | [PHP Coding Standards Fixer (PHP CS Fixer)](https://cs.symfony.com/) fixes your code to follow standards. |
93+
| `phpmd` | [PHP Mess Detector](https://phpmd.org/) looks for several potential problems within your source code. |
9394
| `phpstan` | [PHPStan](https://phpstan.org/) finds bugs in your code without writing tests. It's open-source and free. |
9495
| `infection` | [Infection](https://infection.github.io) is a Mutation Testing Framework. |
9596
| `pest` | [Pest](https://pestphp.com) is a testing framework with a focus on simplicity. |

bin/phpmd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+
phpctl phpmd $@

examples/phpmd/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/

examples/phpmd/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# PHP Mess Detector
2+
3+
An example of [PHP Mess Detector](https://phpmd.org/) usage.
4+
5+
Run `phpctl phpmd src text cleancode,controversial,design,naming,unusedcode` to get PHPMD output execution for [Example](./src/Example.php) class.
6+
7+
You should have an output as following:
8+
```shell
9+
/usr/local/src/src/Example.php:6 LongVariable Avoid excessively long variable names like $thiIsAnAmazingVariable. Keep variable name length under 20.
10+
/usr/local/src/src/Example.php:8 UnusedLocalVariable Avoid unused local variables such as '$anotherVariable'.
11+
/usr/local/src/src/Example.php:11 CamelCaseMethodName The method snake_case_method is not named in camelCase.
12+
/usr/local/src/src/Example.php:17 MissingImport Missing class import via use statement (line '17', column '23').
13+
/usr/local/src/src/Example.php:18 EmptyCatchBlock Avoid using empty try-catch blocks in uselessCatchBlock.
14+
/usr/local/src/src/Example.php:24 UndefinedVariable Avoid using undefined variables such as '$age' which will lead to PHP notices.
15+
/usr/local/src/src/Example.php:24 UnusedLocalVariable Avoid unused local variables such as '$age'.
16+
```

examples/phpmd/composer.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"App\\": "src/"
5+
}
6+
},
7+
"require-dev": {
8+
"phpmd/phpmd": "^2.15"
9+
}
10+
}

0 commit comments

Comments
 (0)