Sha256: 50fcd24221141be22a797e8dc828fbcf39f0192d317f5ced36e710159856006e

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

require 'pre-commit/utils'

module PreCommit
  class PhpCheck
    def self.call(staged_files)
      staged_files = staged_files.grep /\.(php|engine|theme|install|inc|module|test)$/
      return if staged_files.empty?

      errors = staged_files.map { |file| run_check(file) }.compact
      return if errors.empty?

      errors.join("\n")
    end

    def self.run_check(file)
      # We force PHP to display errors otherwise they will likely end up in the
      # error_log and not in stdout.
      result = `php -d display_errors=1 -l #{file}`
      # Filter out the obvious note from PHP.
      result = result.split($/).find_all {|line| line !~ /Errors/}.join($/)
      # If PHP exited non-zero then there was a parse error.
      result.strip unless $? == 0
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pre-commit-0.11.0 lib/pre-commit/checks/php_check.rb
pre-commit-0.10.0 lib/pre-commit/checks/php_check.rb
pre-commit-0.9.2 lib/pre-commit/checks/php_check.rb
pre-commit-0.9.1 lib/pre-commit/checks/php_check.rb
pre-commit-0.9.0 lib/pre-commit/checks/php_check.rb