Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring into lib

  • Loading branch information...
commit fe58a0240e9fd75183da08eb0db1e102358ec6c7 1 parent bd1686f
@jrcryer jrcryer authored
View
10 Gruntfile.js
@@ -12,7 +12,7 @@ module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
-
+
jshint: {
all: [
'Gruntfile.js',
@@ -22,21 +22,21 @@ module.exports = function(grunt) {
jshintrc: '.jshintrc'
}
},
-
+
phpcs: {
application: {
- dir: 'application/classes'
+ dir: 'php/modules'
},
options: {
bin: 'vendor/bin/phpcs',
- standard: 'Zend'
+ standard: 'PSR2'
}
}
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
-
+
grunt.loadNpmTasks('grunt-contrib-jshint');
// By default, lint and run all tests.
View
47 php/modules/Grunt/PhpCs/World.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Sample class for tests of grunt-phpcs runner
+ *
+ * @package Grunt\PhpCs
+ */
+namespace Grunt\PhpCs;
+
+class World
+{
+
+ /**
+ *
+ * @var string
+ */
+ private $name = '';
+
+ /**
+ * Constructor
+ *
+ * @param string $name
+ */
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Sets the world's name
+ *
+ * @param string $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Returns world's name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+}
View
110 tasks/lib/phpcs.js
@@ -0,0 +1,110 @@
+/*
+ * grunt-phpunit
+ * https://github.com/SaschaGalley/grunt-phpunit
+ *
+ * Copyright (c) 2013 Sascha Galley
+ * http://xash.at
+ * Licensed under the MIT license.
+ */
+'use strict';
+
+// External libs.
+var path = require('path');
+var exec = require('child_process').exec;
+
+exports.init = function(grunt) {
+
+ var exports = {},
+ defaults = {
+ // Default options
+ bin: 'phpcs',
+ debug: false,
+ extensions: false,
+ ignore: false,
+ severity: false,
+ standard: false,
+ verbose: false
+ },
+ cmd = null,
+ done = null,
+ config = {};
+
+ /**
+ * Builds phpunit command
+ *
+ * @return string
+ */
+ var buildCommand = function(dir) {
+
+ var cmd = path.normalize(config.bin);
+
+ if (grunt.option('debug') || config.debug === true) {
+ // Display debbuging information during test execution.
+ cmd += ' --debug';
+ }
+
+ if (grunt.option('extensions') || config.extensions) {
+ // A comma separated list of file extensions to check
+ cmd += ' --extensions=' + config.extensions;
+ }
+
+ if (grunt.option('ignore') || config.ignore) {
+ // A comma separated list of patterns to ignore files and directories.
+ cmd += ' --ignore=' + config.ignore;
+ }
+
+ if (grunt.option('severity') || config.severity) {
+ // The minimum severity required to display an error or warning
+ cmd += ' --severity=' + config.severity;
+ }
+
+ if (grunt.option('verbose') || config.standard) {
+ // Define the code sniffer standard.
+ cmd += ' --standard=' + config.standard;
+ }
+
+ if (grunt.option('verbose') || config.verbose === true) {
+ // Output more verbose information.
+ cmd += ' -v';
+ }
+ return cmd;
+ };
+
+ /**
+ * Setup task before running it
+ *
+ * @param Object runner
+ */
+ exports.setup = function(runner) {
+
+ var dir = path.normalize(runner.data.dir);
+ config = runner.options(defaults);
+ cmd = buildCommand(dir) + ' ' + dir;
+
+ grunt.log.writeln('Starting phpcs (target: ' + runner.target.cyan + ') in ' + dir.cyan);
+ grunt.verbose.writeln('Exec: ' + cmd);
+
+ done = runner.async();
+ };
+
+ /**
+ * Runs phpunit command with options
+ *
+ */
+ exports.run = function() {
+
+ exec(cmd, function(err, stdout, stderr) {
+
+ if (stdout) {
+ grunt.log.write(stdout);
+ }
+
+ if (err) {
+ grunt.fatal(err);
+ }
+ done();
+ });
+ };
+
+ return exports;
+};
View
84 tasks/phpcs.js
@@ -6,83 +6,15 @@
* http://xash.at
* Licensed under the MIT license.
*/
-module.exports = function(grunt) {
- 'use strict';
+'use strict';
- var _ = grunt.util._;
-
- var path = require('path');
- var exec = require('child_process').exec;
-
- grunt.registerMultiTask( 'phpcs', 'Run phpunit', function() {
-
- var done = this.async();
-
- // Merge task-specific and/or target-specific options with these defaults.
- var options = this.options({
- // Default options
- bin: 'phpcs',
- debug: false,
- extensions: false,
- ignore: false,
- severity: false,
- standard: false,
- verbose: false
- });
-
- // Normalize dir and cmd.
- var dir = path.normalize(this.data.dir);
- var cmd = path.normalize(options.bin);
-
- if (grunt.option('debug') || options.debug === true) {
- // Display debbuging information during test execution.
- cmd += ' --debug';
- }
-
- if (grunt.option('extensions') || options.extensions) {
- // A comma separated list of file extensions to check
- cmd += ' --extensions=' + options.extensions;
- }
-
- if (grunt.option('ignore') || options.ignore) {
- // A comma separated list of patterns to ignore files and directories.
- cmd += ' --ignore=' + options.ignore;
- }
-
- if (grunt.option('severity') || options.severity) {
- // The minimum severity required to display an error or warning
- cmd += ' --severity=' + options.severity;
- }
-
- if (grunt.option('verbose') || options.standard) {
- // Define the code sniffer standard.
- cmd += ' --standard=' + options.standard;
- }
-
- if (grunt.option('verbose') || options.verbose === true) {
- // Output more verbose information.
- cmd += ' -v';
- }
-
- // Set working directory.
- cmd += ' ' + dir;
-
- grunt.log.writeln('Starting phpcs (target: ' + this.target.cyan + ') in ' + dir.cyan);
- grunt.verbose.writeln('Exec: ' + cmd);
-
- // Execute phpunit command.
- exec(cmd, function( err, stdout, stderr) {
-
- if (stdout) {
- grunt.log.write(stdout);
- }
+module.exports = function(grunt) {
- if (err) {
- grunt.fatal(err);
- }
+ // Internal lib.
+ var phpcs = require('./lib/phpcs').init(grunt);
- done();
-
- });
- });
+ grunt.registerMultiTask('phpcs', 'Run phpunit', function() {
+ phpcs.setup(this);
+ phpcs.run();
+ });
};
Please sign in to comment.
Something went wrong with that request. Please try again.