Skip to content

Commit e963f62

Browse files
committed
PHP: filter out use statements by default
1 parent 4058ff1 commit e963f62

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

Diff for: lib/cc/engine/analyzers/php/main.rb

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Main < CC::Engine::Analyzers::Base
1515
"**/*.php",
1616
].freeze
1717
DEFAULT_MASS_THRESHOLD = 28
18+
DEFAULT_FILTERS = [
19+
"(use ___)".freeze,
20+
].freeze
1821
POINTS_PER_OVERAGE = 100_000
1922

2023
def transform_sexp(sexp)
@@ -32,6 +35,10 @@ def process_file(path)
3235
def php_parser
3336
::CC::Engine::Analyzers::Php::Parser
3437
end
38+
39+
def default_filters
40+
DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
41+
end
3542
end
3643
end
3744
end

Diff for: spec/cc/engine/analyzers/php/main_spec.rb

+25-25
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,31 @@
165165
end
166166

167167
it "ignores namespace and use declarations" do
168-
create_source_file("foo.php", <<-EOF)
169-
<?php
170-
namespace KeepClear\\Http\\Controllers\\API\\V1;
171-
use Illuminate\\Http\\Request;
172-
use KeepClear\\Http\\Controllers\\Controller;
173-
use KeepClear\\Models\\Comment;
174-
use KeepClear\\Models\\User;
175-
use KeepClear\\Models\\Asset;
176-
use KeepClear\\Traits\\Controllers\\ApiFilter;
177-
use KeepClear\\Traits\\Controllers\\ApiParseBody;
178-
use KeepClear\\Traits\\Controllers\\ApiException;
179-
EOF
180-
181-
create_source_file("bar.php", <<-EOF)
182-
<?php
183-
namespace KeepClear\\Http\\Controllers\\API\\V1;
184-
use Illuminate\\Http\\Request;
185-
use KeepClear\\Http\\Controllers\\Controller;
186-
use KeepClear\\Models\\Comment;
187-
use KeepClear\\Models\\User;
188-
use KeepClear\\Models\\Asset;
189-
use KeepClear\\Traits\\Controllers\\ApiFilter;
190-
use KeepClear\\Traits\\Controllers\\ApiParseBody;
191-
use KeepClear\\Traits\\Controllers\\ApiException;
192-
EOF
168+
create_source_file("foo.php", <<~EOPHP)
169+
<?php
170+
namespace KeepClear\\Http\\Controllers\\API\\V1;
171+
use Illuminate\\Http\\Request;
172+
use KeepClear\\Http\\Controllers\\Controller;
173+
use KeepClear\\Models\\Comment;
174+
use KeepClear\\Models\\User;
175+
use KeepClear\\Models\\Asset;
176+
use KeepClear\\Traits\\Controllers\\ApiFilter;
177+
use KeepClear\\Traits\\Controllers\\ApiParseBody;
178+
use KeepClear\\Traits\\Controllers\\ApiException;
179+
EOPHP
180+
181+
create_source_file("bar.php", <<~EOPHP)
182+
<?php
183+
namespace KeepClear\\Http\\Controllers\\API\\V1;
184+
use Illuminate\\Http\\Request;
185+
use KeepClear\\Http\\Controllers\\Controller;
186+
use KeepClear\\Models\\Comment;
187+
use KeepClear\\Models\\User;
188+
use KeepClear\\Models\\Asset;
189+
use KeepClear\\Traits\\Controllers\\ApiFilter;
190+
use KeepClear\\Traits\\Controllers\\ApiParseBody;
191+
use KeepClear\\Traits\\Controllers\\ApiException;
192+
EOPHP
193193

194194
issues = run_engine(engine_conf).strip.split("\0")
195195
expect(issues).to be_empty

0 commit comments

Comments
 (0)