Class: PreCommit::Checks::Php
- Inherits:
-
Plugin
- Object
- Plugin
- PreCommit::Checks::Php
show all
- Defined in:
- lib/plugins/pre_commit/checks/php.rb
Instance Attribute Summary
Attributes inherited from Plugin
#config, #pluginator
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#initialize, #name
Class Method Details
.description ⇒ Object
27
28
29
|
# File 'lib/plugins/pre_commit/checks/php.rb', line 27
def self.description
"Detects PHP errors."
end
|
Instance Method Details
#call(staged_files) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/plugins/pre_commit/checks/php.rb', line 7
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
|
#run_check(file) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/plugins/pre_commit/checks/php.rb', line 17
def run_check(file)
result = `php -d display_errors=1 -l #{file} 2>&1`
result = result.split($/).find_all {|line| line !~ /Errors/}.join($/)
result.strip unless $? == 0
end
|