class Pronto::Phpcs
Public Class Methods
new(patches, commit = nil)
click to toggle source
Calls superclass method
# File lib/pronto/phpcs.rb, line 7 def initialize(patches, commit = nil) super @executable = ENV['PRONTO_PHPCS_EXECUTABLE'] || 'phpcs' @standard = ENV['PRONTO_PHPCS_STANDARD'] || 'PSR2' end
Public Instance Methods
inspect(patch)
click to toggle source
# File lib/pronto/phpcs.rb, line 26 def inspect(patch) path = patch.new_file_full_path.to_s run_phpcs(path).map do |offence| patch.added_lines.select { |line| line.new_lineno == offence['line'] } .map { |line| new_message(offence, line) } end end
new_message(offence, line)
click to toggle source
# File lib/pronto/phpcs.rb, line 45 def new_message(offence, line) path = line.patch.delta.new_file[:path] level = if offence['type'] == 'ERROR' then :error else :warning end Message.new(path, line, level, offence['message'], nil, self.class) end
php_file?(path)
click to toggle source
# File lib/pronto/phpcs.rb, line 52 def php_file?(path) File.extname(path) == '.php' end
run()
click to toggle source
# File lib/pronto/phpcs.rb, line 14 def run return [] unless @patches @patches.select { |patch| valid_patch?(patch) } .map { |patch| inspect(patch) } .flatten.compact end
run_phpcs(path)
click to toggle source
# File lib/pronto/phpcs.rb, line 34 def run_phpcs(path) escaped_executable = Shellwords.escape(@executable) escaped_standard = Shellwords.escape(@standard) escaped_path = Shellwords.escape(path) JSON.parse(`#{escaped_executable} -q --report=json --standard=#{escaped_standard} #{escaped_path}`) .fetch('files', {}) .fetch(path, {}) .fetch('messages', []) end
valid_patch?(patch)
click to toggle source
# File lib/pronto/phpcs.rb, line 22 def valid_patch?(patch) patch.additions > 0 && php_file?(patch.new_file_full_path) end