Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 355ca42
Showing
6 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# grunt-phpmd | ||
|
||
> Grunt plugin for running [PHP Mess Detector](http://phpmd.org). | ||
_This plugin is developed for Grunt `0.4.0` and is not tested for backward compatibility with Grunt `0.3.x`._ | ||
|
||
## Getting Started | ||
|
||
1. Install this grunt plugin with the follwing command: | ||
|
||
```shell | ||
npm install grunt-phpmd --save-dev | ||
``` | ||
|
||
2. [Install PHPMD](http://phpmd.org/download/index.html) | ||
|
||
3. Add this to your project's `Gruntfile.js`: | ||
|
||
```js | ||
grunt.loadNpmTasks('grunt-phpmd'); | ||
``` | ||
|
||
## PHPMD task | ||
|
||
_Run this task with the `grunt phpmd` command._ | ||
|
||
_This task is a [multi task][] so any targets, files and options should be specified according to the [multi task][] documentation._ | ||
|
||
[multi task]: https://github.com/gruntjs/grunt/wiki/Configuring-tasks | ||
|
||
### Usage Example | ||
|
||
```js | ||
phpmd: { | ||
application: { | ||
dir: 'application' | ||
} | ||
options: { | ||
rulesets: 'codesize' | ||
} | ||
} | ||
``` | ||
|
||
### Target Properties | ||
|
||
#### dir | ||
Type: `String` | ||
|
||
The file or directory where phpmd should search for files. | ||
|
||
### Options | ||
#### bin | ||
Type: `String` | ||
Default: `'phpmd'` | ||
|
||
The binary name if it is in your PATH or the full path if not. | ||
|
||
#### reportFormat | ||
Type: `String` | ||
Default: `'xml'` | ||
|
||
The type of report to generate. PHPMD supports `xml`, `text` and `html`. | ||
|
||
#### reportFile | ||
Type: `String` | ||
Default: `false` | ||
|
||
Set a path and filename here to write to a file, otherwise it will write to stdout. | ||
|
||
#### suffixes | ||
Type: `String` | ||
Default: `false` | ||
|
||
Set a comma-separated string of valid source code filename extensions. | ||
|
||
#### exclude | ||
Type: `String` | ||
Default: `false` | ||
|
||
Set a comma-separated string of patterns that are used to ignore directories. | ||
|
||
#### minimumPriority | ||
Type: `Number` | ||
Default: `false` | ||
|
||
Rule priority threshold: rules with lower priority than this will not be used. | ||
|
||
#### strict | ||
Type: `Boolean` | ||
Default: `false` | ||
|
||
Also report those nodes with a @SuppressWarnings annotation. | ||
|
||
#### rulesets | ||
Type: `String` | ||
Default: `'codesize,unusedcode,naming'` | ||
|
||
A ruleset filename or a comma-separated string of rulesetfilenames. Make sure to have no spaces between the items! | ||
|
||
#### maxBuffer | ||
Type: `Number` | ||
Default: `200*1024` | ||
|
||
Override the maxBuffer-Size of nodejs's exec() function if you expect a long output on stdout. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "grunt-phpmd", | ||
"version": "0.1.0", | ||
"description": "Grunt plugin for running PHP Mess Detector.", | ||
"main": "tasks/phpmd.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alappe/grunt-phpmd.git" | ||
}, | ||
"keywords": [ | ||
"gruntplugin", | ||
"phpmd", | ||
"mess-detection", | ||
"ci", | ||
"continous-integration" | ||
], | ||
"author": "Andreas Lappe", | ||
"license": "BSD", | ||
"bugs": { | ||
"url": "https://github.com/alappe/grunt-phpmd/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
### | ||
grunt-phpmd | ||
Copyright (c) 2013 Andreas Lappe | ||
http://kaeufli.ch | ||
Licensed under the BSD license. | ||
### | ||
|
||
path = require 'path' | ||
exec = (require 'child_process').exec | ||
|
||
exports.init = (grunt) -> | ||
|
||
exports = config = {} | ||
cmd = done = null | ||
defaults = | ||
bin: 'phpmd' | ||
# Can be xml, text or html | ||
reportFormat: 'xml' | ||
# Path and filename, otherwise STDOUT is used | ||
reportFile: false | ||
suffixes: false | ||
exclude: false | ||
minimumPriority: false | ||
strict: false | ||
rulesets: 'codesize,unusedcode,naming' | ||
maxBuffer: 200*1024 | ||
|
||
buildCommand = (dir) -> | ||
cmd = "#{path.normalize config.bin} #{dir} #{config.reportFormat} #{config.rulesets}" | ||
cmd += " --minimumpriority #{config.minimumPriority}" if config.minimumPriority | ||
cmd += " --reportfile #{config.reportFile}" if config.reportFile | ||
cmd += " --suffixes #{config.suffixes}" if config.suffixes | ||
cmd += " --exclude #{config.exclude}" if config.exclude | ||
cmd += " --strict" if config.strict | ||
cmd | ||
|
||
exports.setup = (runner) -> | ||
dir = path.normalize runner.data.dir | ||
config = runner.options defaults | ||
cmd = buildCommand dir | ||
grunt.log.writeln "Starting phpmd (target: #{runner.target.cyan}) in #{dir.cyan}" | ||
grunt.verbose.writeln "Execute: #{cmd}" | ||
done = runner.async() | ||
|
||
exports.run = -> | ||
cmdOptions = maxBuffer: config.maxBuffer | ||
exec cmd, cmdOptions, (err, stdout, stderr) -> | ||
grunt.log.write stdout if stdout | ||
if err | ||
# As documented on # http://phpmd.org/documentation/index.html#exit-codes | ||
grunt.fatal err if err.code isnt 2 | ||
done() | ||
|
||
exports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### | ||
grunt-phpmd | ||
Copyright (c) 2013 Andreas Lappe | ||
http://kaeufli.ch | ||
Licensed under the BSD license. | ||
### | ||
|
||
module.exports = (grunt) -> | ||
phpmd = (require './lib/phpmd').init grunt | ||
|
||
grunt.registerMultiTask 'phpmd', 'Run phpmd', -> | ||
phpmd.setup @ | ||
phpmd.run() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.