Sha256: 9efa3d40c72936d33a8b905bed50b8bb8ab4e877b4678ea07fe88fe11deeaa72

Contents?: true

Size: 917 Bytes

Versions: 13

Compression:

Stored size: 917 Bytes

Contents

require 'pre-commit/checks/plugin'

module PreCommit
  module Checks
    class Php < Plugin

      def 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 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} 2>&1`
        # 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

      def self.description
        "Detects PHP errors."
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
pre-commit-0.20.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-php-1.0.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.19.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.18.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.17.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.16.3 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.16.2 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.16.1 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.16.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.15.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.14.1 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.14.0 lib/plugins/pre_commit/checks/php.rb
pre-commit-0.13.0 lib/plugins/pre_commit/checks/php.rb