From 803f0f903ef3efc9ff88543076cf50686d218a12 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 9 Oct 2017 13:28:39 -0400 Subject: [PATCH 1/2] Add spec for PHP imports that should not be considered duplicaton --- spec/cc/engine/analyzers/php/main_spec.rb | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/cc/engine/analyzers/php/main_spec.rb b/spec/cc/engine/analyzers/php/main_spec.rb index 008b33b0..288ee4dd 100644 --- a/spec/cc/engine/analyzers/php/main_spec.rb +++ b/spec/cc/engine/analyzers/php/main_spec.rb @@ -163,6 +163,37 @@ "lines" => { "begin" => 11, "end" => 16 }, }) end + + it "ignores namespace and use declarations" do + create_source_file("foo.php", <<-EOF) + Date: Mon, 9 Oct 2017 15:12:57 -0400 Subject: [PATCH 2/2] PHP: filter out use statements by default --- lib/cc/engine/analyzers/php/main.rb | 7 ++++ spec/cc/engine/analyzers/php/main_spec.rb | 50 +++++++++++------------ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/cc/engine/analyzers/php/main.rb b/lib/cc/engine/analyzers/php/main.rb index 8237ca88..052506cf 100644 --- a/lib/cc/engine/analyzers/php/main.rb +++ b/lib/cc/engine/analyzers/php/main.rb @@ -15,6 +15,9 @@ class Main < CC::Engine::Analyzers::Base "**/*.php", ].freeze DEFAULT_MASS_THRESHOLD = 28 + DEFAULT_FILTERS = [ + "(use ___)".freeze, + ].freeze POINTS_PER_OVERAGE = 100_000 def transform_sexp(sexp) @@ -32,6 +35,10 @@ def process_file(path) def php_parser ::CC::Engine::Analyzers::Php::Parser end + + def default_filters + DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter } + end end end end diff --git a/spec/cc/engine/analyzers/php/main_spec.rb b/spec/cc/engine/analyzers/php/main_spec.rb index 288ee4dd..1f2c5b03 100644 --- a/spec/cc/engine/analyzers/php/main_spec.rb +++ b/spec/cc/engine/analyzers/php/main_spec.rb @@ -165,31 +165,31 @@ end it "ignores namespace and use declarations" do - create_source_file("foo.php", <<-EOF) -