Class: Danger::DangerPhpCodesniffer
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerPhpCodesniffer
- Defined in:
- lib/php_codesniffer/plugin.rb
Overview
Checks PHP files code standard using [PHP_CodeSniffer](github.com/squizlabs/PHP_CodeSniffer).
Instance Attribute Summary collapse
-
#fail_on_error ⇒ Boolean
An attribute for failing on errors In case phpcs finds errors, Danger will also fail This allows failing pipelines using the ‘–fail-on-errors` flag in Danger.
-
#filtering ⇒ Boolean
An attribute for enabling filtering Only show messages within changed files.
-
#ignore ⇒ String
An attribute for ignoring file or directory.
-
#standard ⇒ String
An attribute for setting code standard.
Instance Method Summary collapse
-
#exec ⇒ void
Execute and process phpcs CLL’s result.
Instance Attribute Details
#fail_on_error ⇒ Boolean
An attribute for failing on errors In case phpcs finds errors, Danger will also fail This allows failing pipelines using the ‘–fail-on-errors` flag in Danger
37 38 39 |
# File 'lib/php_codesniffer/plugin.rb', line 37 def fail_on_error @fail_on_error end |
#filtering ⇒ Boolean
An attribute for enabling filtering Only show messages within changed files.
31 32 33 |
# File 'lib/php_codesniffer/plugin.rb', line 31 def filtering @filtering end |
#ignore ⇒ String
An attribute for ignoring file or directory
26 27 28 |
# File 'lib/php_codesniffer/plugin.rb', line 26 def ignore @ignore end |
#standard ⇒ String
An attribute for setting code standard
21 22 23 |
# File 'lib/php_codesniffer/plugin.rb', line 21 def standard @standard end |
Instance Method Details
#exec ⇒ void
This method returns an undefined value.
Execute and process phpcs CLL’s result.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/php_codesniffer/plugin.rb', line 42 def exec bin = phpcs_path raise "phpcs is not installed" unless bin summary = { "errors"=> 0, "warnings"=> 0, "fixable"=> 0 } report = [] unless filtering result = run_phpcs(bin, ".") summary = result.fetch("totals") report = generate_report result else ((git.modified_files - git.deleted_files) + git.added_files) .select {|file| ((file.end_with? ".php") || (file.end_with? ".inc"))} .map { |file| file.gsub("#{Dir.pwd}/", '') } .each do |file| result = run_phpcs(bin, file) totals = result.fetch("totals") summary["errors"] += totals["errors"] summary["warnings"] += totals.fetch("warnings") summary["fixable"] += totals.fetch("fixable") if (totals["errors"] + totals.fetch("warnings") + totals.fetch("fixable")) > 0 report.push(generate_report result) end end end if (summary["errors"] + summary["warnings"] + summary["fixable"]) > 0 markdown "# PHP_CodeSniffer report" markdown generate_summary_markdown summary markdown report end if fail_on_error && summary["errors"] > 0 fail "There are #{summary["errors"]} errors that need to be resolved." end end |