Skip to content

Commit bcf46d0

Browse files
authored
Merge pull request #4 from leviy/add-phpmd-config
Add a ruleset for PHP Mess Detector
2 parents 4197542 + 5bb7731 commit bcf46d0

File tree

5 files changed

+449
-47
lines changed

5 files changed

+449
-47
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ cache:
1010

1111
install: composer install
1212

13-
script: vendor/bin/phpcs --standard=src/LEVIY/ruleset.xml --basepath=. --report-file=phpcs.log --report-width=120 tests/; diff tests/expected.log phpcs.log
13+
script:
14+
- vendor/bin/phpmd src/ text phpmd.xml
15+
- vendor/bin/phpcs --standard=src/LEVIY/ruleset.xml --basepath=. --report-file=phpcs.log --report-width=120 tests/; diff tests/expected.log phpcs.log

README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
[![Packagist version](https://img.shields.io/packagist/v/leviy/coding-standard.svg)](https://packagist.org/packages/leviy/coding-standard)
55
[![PHP from Packagist](https://img.shields.io/packagist/php-v/leviy/coding-standard.svg)](https://github.com/leviy/php-coding-standard/blob/master/composer.json)
66

7-
The LEVIY coding standard for PHP code, including a PHPCS ruleset.
7+
The LEVIY coding standard for PHP code, with rulesets for
8+
[PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) and
9+
[PHP Mess Detector](https://phpmd.org/).
810

911
## Installation
1012

11-
Install the coding standard using [Composer](https://getcomposer.org/):
13+
Install this package using [Composer](https://getcomposer.org/):
1214

1315
```bash
1416
composer require --dev leviy/coding-standard
1517
```
1618

17-
Create a `phpcs.xml` file containing the following bootstrap code sniffer configuration:
19+
### Installing the PHP CodeSniffer ruleset
20+
21+
Create a file `phpcs.xml` in the root of the project with the following contents:
1822

1923
```xml
2024
<?xml version="1.0"?>
@@ -31,30 +35,45 @@ Create a `phpcs.xml` file containing the following bootstrap code sniffer config
3135
</ruleset>
3236
```
3337

34-
An annotated `ruleset.xml` configuration file can be found [here](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml)
35-
where you can see the complete range of features and configuration options that can be used to modify the configuration to your project needs.
38+
### Installing the PHP Mess Detector ruleset
3639

37-
## Usage
40+
Create a file `phpmd.xml` in the root of the project with the following contents:
3841

39-
Run the code sniffer and show both errors and warnings:
40-
41-
bin/phpcs --standard=phpcs.xml
42+
```xml
43+
<?xml version="1.0" encoding="UTF-8"?>
44+
<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0"
45+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
46+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
47+
name="Mess detector ruleset">
48+
<description>Ruleset for PHP Mess Detector that enforces coding standards</description>
49+
50+
<rule ref="vendor/leviy/coding-standard/phpmd.xml"/>
51+
</ruleset>
52+
```
4253

43-
Run the code sniffer and show only errors:
54+
## Configuration
4455

45-
bin/phpcs --standard=phpcs.xml --error-severity=0 --warning-severity=1
56+
### PHP CodeSniffer
4657

47-
Run the code sniffer and show only warnings:
58+
An annotated `ruleset.xml` configuration file can be found [here](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml)
59+
where you can see the complete range of features and configuration options that can be used to modify the configuration to your project needs.
4860

49-
bin/phpcs --standard=phpcs.xml --error-severity=0 --warning-severity=1
61+
### PHP Mess Detector
5062

51-
Run the code sniffer against a specific file or directory
63+
Documentation about tweaking the ruleset and exluding rules or changing settings
64+
can be found [here](https://phpmd.org/documentation/creating-a-ruleset.html).
5265

53-
bin/phpcs --standard=phpcs.xml src/path/to/file.php
66+
## Usage
5467
55-
bin/phpcs --standard=phpcs.xml src/path/to/file_1.php src/path/to/file_2.php
68+
Run `vendor/bin/phpcs` to run PHP CodeSniffer. If you have a file `phpcs.xml` or
69+
`phpcs.xml.dist` in root directory of the project, CodeSniffer will use it
70+
automatically. Add a path to run CodeSniffer only against that
71+
file or directory. See
72+
[Usage](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage) for more
73+
detailed usage instructions.
5674

57-
bin/phpcs --standard=phpcs.xml src/path/to/directory
75+
Run `vendor/bin/phpmd src/ text phpmd.xml` to run PHP Mess Detector against the
76+
`src` directory and print a report in the "text" format.
5877

5978
## PHPStorm code sniffer validation
6079

composer.json

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
{
2-
"name": "leviy/coding-standard",
3-
"type": "phpcodesniffer-standard",
4-
"description": "LEVIY Coding Standard",
5-
"license": "proprietary",
6-
"authors": [
7-
{
8-
"name": "LEVIY B.V. (Netherlands)",
9-
"email": "[email protected]"
2+
"name": "leviy/coding-standard",
3+
"type": "phpcodesniffer-standard",
4+
"description": "LEVIY Coding Standard",
5+
"license": "proprietary",
6+
"authors": [
7+
{
8+
"name": "LEVIY B.V. (Netherlands)",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": "^7.1",
14+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
15+
"escapestudios/symfony2-coding-standard": "^3.0",
16+
"phpmd/phpmd": "^2.6",
17+
"slevomat/coding-standard": "^4.3",
18+
"squizlabs/php_codesniffer": "^3.0"
19+
},
20+
"require-dev": {
21+
"liip/rmt": "^1.3"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"": "src"
26+
}
27+
},
28+
"minimum-stability": "stable",
29+
"config": {
30+
"sort-packages": true
1031
}
11-
],
12-
"require": {
13-
"php": "^7.1",
14-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
15-
"escapestudios/symfony2-coding-standard": "^3.0",
16-
"slevomat/coding-standard": "^4.3",
17-
"squizlabs/php_codesniffer": "^3.0"
18-
},
19-
"require-dev": {
20-
"liip/rmt": "^1.3"
21-
},
22-
"autoload": {
23-
"psr-4": {
24-
"": "src"
25-
}
26-
},
27-
"minimum-stability": "stable",
28-
"config": {
29-
"sort-packages": true
30-
}
3132
}

0 commit comments

Comments
 (0)