Class: Guard::PHPCS

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/phpcs.rb

Constant Summary collapse

VERSION =
'0.0.6'
DEFAULT_OPTIONS =
{
			:standard => 'Zend',
			:executable => 'phpcs',
}

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ PHPCS

Returns a new instance of PHPCS.



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

def initialize(watchers = [], options = {})
  defaults = DEFAULT_OPTIONS.clone
  @options = defaults.merge(options)
   @tabs = @options[:tabs]? " --tab-width=#{@options[:tabs]} " : ' '
  super(watchers, @options)
end

Instance Method Details

#run_on_modifications(paths) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/guard/phpcs.rb', line 21

def run_on_modifications(paths)
			paths.each do |path|
				results = `#{@options[:executable]} --report=full#{@tabs}--standard=#{@options[:standard]} #{path}`
				if $?.to_i > 0 then
::Guard::Notifier.notify(results.gsub(/^-+\n/, '').gsub(/^FILE:.*\n/, '').gsub(/^Time:.*\n/, ''), :title => 'PHP Codesniffer', :image => :failed)
puts results
				end
			end
end