Class: Guard::PHPMD

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

Constant Summary collapse

VERSION =
'0.0.5'
DEFAULT_OPTIONS =
{
       :path => '.',
       :rules => 'pmd-rules.xml',
       :executable => 'phpmd',
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PHPMD

Returns a new instance of PHPMD.



14
15
16
17
18
# File 'lib/guard/phpmd.rb', line 14

def initialize(options = {})
  defaults = DEFAULT_OPTIONS.clone
  @options = defaults.merge(options)
  super(@options)
end

Instance Method Details

#run_on_modifications(paths) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/guard/phpmd.rb', line 20

def run_on_modifications(paths)
			@options[:rules] = File.expand_path @options[:rules]
			paths.each do |path|
				path = File.expand_path path
				Dir.chdir(@options[:path]) do
results = `#{@options[:executable]} #{path} text #{@options[:rules]}`
if $?.to_i > 0 then
	::Guard::Notifier.notify(results, :title => 'PHP Mess Detector', :image => :failed)
	puts results
end
				end
			end
end