-
Notifications
You must be signed in to change notification settings - Fork 279
/
php_stan.rb
30 lines (24 loc) · 749 Bytes
/
php_stan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `phpstan` against any modified PHP files.
# For running `phpstan` with Laravel, it requires setup with `ide_helper`.
#
# References:
# https://github.com/phpstan/phpstan/issues/239
# https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2
class PhpStan < Base
MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/.freeze
def run
messages = []
result = execute(command, args: applicable_files)
unless result.success?
messages += result.stdout.lstrip.split("\n")
end
return :pass if messages.empty?
extract_messages(
messages,
MESSAGE_REGEX
)
end
end
end