phpmetrix
phpmetrix is a node wrapper around phpmetrics that provides integration with build systems like Grunt, Gulp and more.
$ npm i -g phpmetrix
$ phpmetrix path/to/config.yml
Node
var phpmetrix = require('phpmetrix').phpmetrix
phpmetrix(['path/to/config.yml'], function (err, stdout, stderr) {
if (err) throw new Error(err)
process.stdout.write(stdout)
process.stderr.write(stderr)
// success!
})
NPM
{
"scripts": {
"pretest": "phpmetrix path/to/config.yml"
},
"devDependencies": { }
}
$ npm test
Grunt
module.exports = function (grunt) {
require('phpmetrix').gruntPlugin(grunt)
grunt.initConfig({
phpmetrix: {
config: 'path/to/config.yml',
options: {
phpCmd: '/usr/local/bin/php', // Defaults to php
phpmetricsCmd: '/usr/local/bin/phpmetrics', // Defaults to phpmetrics
stdout: true,
stderr: true
}
}
})
grunt.registerTask('test', ['phpmetrix'])
}
$ grunt test
Gulp
The same options that can be used in Grunt can be used in Gulp too.
var gulp = require('gulp')
var phpmetrics = require('phpmetrix').phpmetrics
gulp.task('phpmetrix', function (cb) {
phpmetrix(['path/to/config.yml'], function (err, stdout, stderr) {
if (err) {
cb(err)
process.exit(1)
}
cb()
})
})
gulp.task('test', ['phpmetrix'])
$ gulp test