Created
October 26, 2012 14:50
-
-
Save lenada/3959235 to your computer and use it in GitHub Desktop.
PHPCodeSniffer inline Guard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A sample Guardfile | |
# More info at https://github.com/guard/guard#readme | |
require 'guard/guard' | |
module ::Guard | |
class Phpcs < Guard | |
def run_on_change(paths) | |
puts phpcs_command(paths) | |
execute_command(phpcs_command(paths)) | |
end | |
private | |
def phpcs_command(paths) | |
cmd_parts = [] | |
cmd_parts << phpcs_executable | |
cmd_parts << '--standard=' + phpcs_rules | |
cmd_parts << '-s' | |
cmd_parts += paths.map{|path| "./#{path}" } | |
cmd_parts.join(' ') | |
end | |
def execute_command(command) | |
result = `#{command}` | |
if $?.to_i == 256 | |
puts "An Error occured" | |
results = "#{ result }".split(/\r?\n/) | |
puts results | |
line = results[5].sub! %r{\A(.{1,6})(?: .*)?\z}, '\\1' | |
::Guard::Notifier.notify(results[1], :title => 'PhpCS Error' + line, :image => :failed) | |
else | |
puts "All good" | |
end | |
end | |
def phpcs_executable | |
options.fetch(:executable){'/usr/local/php5/bin/phpcs'} | |
end | |
def phpcs_rules | |
options.fetch(:rules){'/Users/leander/Sites/easybib/coding-standard/EasyBib/ruleset.xml'} | |
end | |
end | |
end | |
notification :terminal_notifier | |
guard 'phpcs' do | |
watch(%r{app/modules/.+\.(php|phtml)}) { |m| "#{m[0]}"} | |
end | |
guard 'livereload' do | |
#watch(%r{app/views/.+\.(erb|haml|slim)$}) | |
watch(%r{app/modules/.+\.php}) | |
watch(%r{public/.+\.(css|js|html)}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment