<commit_before>var gutil = require('gulp-util')
var through = require('through2')
var exec = require('child_process').exec
var chalk = require('chalk')

/**
 * Builds shell command for PHPMD according to specified options.
 */
var buildCommand = function(file, opt) {
  var opt = opt || {}
  var command = (opt.bin || 'phpmd') + ' ' + file.path

  if (opt.hasOwnProperty('format')) {
    command += ' ' + opt.format + ' '
  }

  if (opt.hasOwnProperty('ruleset')) {
    command += ' ' + opt.ruleset + ' '
  }

  if (opt.hasOwnProperty('minimumpriority')) {
    command += ' --minimumpriority="' + opt.minimumpriority + '"'
  }

  if (opt.hasOwnProperty('strict')) {
    command += ' --strict'
  }

  return command
}

var phpmdPlugin = function(options) {
  return through.obj(function(file, enc, callback) {
    var stream = this

    if (file.isNull()) {
      stream.push(file)
      callback()

      return
    }

    if (file.isStream()) {
      stream.emit('error', new gutil.PluginError('gulp-phpmd', 'Streams are not supported'))
      callback()

      return
    }

    // Run PHPMD
    exec(buildCommand(file, options), function(error, stdout, stderr) {
      if (error) {
        var message = 'PHP Code Sniffer found a ' + chalk.yellow('problem')
                    + ' in ' + chalk.magenta(file.path) + '\n\t'
                    + report.output.replace(/\n/g, '\n\t');
        stream.emit('error', new gutil.PluginError('gulp-phpmd', message))
        callback()

        return
      }

      stream.push(file)
      callback()
    })
  })
}

module.exports = phpmdPlugin<commit_msg>report is not defined<commit_after>var gutil = require('gulp-util')
var through = require('through2')
var exec = require('child_process').exec
var chalk = require('chalk')

/**
 * Builds shell command for PHPMD according to specified options.
 */
var buildCommand = function(file, opt) {
  var opt = opt || {}
  var command = (opt.bin || 'phpmd') + ' ' + file.path

  if (opt.hasOwnProperty('format')) {
    command += ' ' + opt.format + ' '
  }

  if (opt.hasOwnProperty('ruleset')) {
    command += ' ' + opt.ruleset + ' '
  }

  if (opt.hasOwnProperty('minimumpriority')) {
    command += ' --minimumpriority="' + opt.minimumpriority + '"'
  }

  if (opt.hasOwnProperty('strict')) {
    command += ' --strict'
  }

  return command
}

var phpmdPlugin = function(options) {
  return through.obj(function(file, enc, callback) {
    var stream = this

    if (file.isNull()) {
      stream.push(file)
      callback()

      return
    }

    if (file.isStream()) {
      stream.emit('error', new gutil.PluginError('gulp-phpmd', 'Streams are not supported'))
      callback()

      return
    }

    // Run PHPMD
    exec(buildCommand(file, options), function(error, stdout, stderr) {
      if (error) {
        var message = 'PHP Code Sniffer found a ' + chalk.yellow('problem')
                    + ' in ' + chalk.magenta(file.path) + '\n\t'
                    + stdout.replace(/\n/g, '\n\t');
        stream.emit('error', new gutil.PluginError('gulp-phpmd', message))
        callback()

        return
      }

      stream.push(file)
      callback()
    })
  })
}

module.exports = phpmdPlugin
{'fraction_non_alphanumeric': 0.16016234779893848, 'fraction_numerical': 0.0006244146113019045, 'mean_word_length': 2.556048834628191, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6995339', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1032, 'n_words': 222}