Class: Danger::DangerPhpmd

Inherits:
Plugin
  • Object
show all
Defined in:
lib/phpmd/plugin.rb

Overview

[Danger](danger.systems/ruby/) plugin for [phpmd](phpmd.org/).

Examples:

Run phpmd and send warn comment.


phpmd.binary_path = "vendor/bin/phpmd"
phpmd.run ruleset: "rulesets.xml"

See Also:

  • ktakayama/danger-phpmd

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binary_pathString

phpmd path

Returns:

  • (String)


20
21
22
# File 'lib/phpmd/plugin.rb', line 20

def binary_path
  @binary_path
end

Instance Method Details

#run(options) ⇒ void

This method returns an undefined value.

Execute phpmd



24
25
26
27
28
29
30
31
32
33
# File 'lib/phpmd/plugin.rb', line 24

def run(options)
  return if target_files.empty?

  tmpfile = Tempfile.open("phpmd_result")
  Open3.capture3(cmd_path, "--reportfile", tmpfile.path, target_files.join(","), "json", options[:ruleset])
  results = parse(tmpfile.read)
  results.each do |result|
    warn(result[:message], file: result[:file], line: result[:line])
  end
end