Skip to content

Ignore PHP namespace/use statements #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/cc/engine/analyzers/php/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/cc/engine/analyzers/php/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,37 @@
"lines" => { "begin" => 11, "end" => 16 },
})
end

it "ignores namespace and use declarations" do
create_source_file("foo.php", <<~EOPHP)
<?php
namespace KeepClear\\Http\\Controllers\\API\\V1;
use Illuminate\\Http\\Request;
use KeepClear\\Http\\Controllers\\Controller;
use KeepClear\\Models\\Comment;
use KeepClear\\Models\\User;
use KeepClear\\Models\\Asset;
use KeepClear\\Traits\\Controllers\\ApiFilter;
use KeepClear\\Traits\\Controllers\\ApiParseBody;
use KeepClear\\Traits\\Controllers\\ApiException;
EOPHP

create_source_file("bar.php", <<~EOPHP)
<?php
namespace KeepClear\\Http\\Controllers\\API\\V1;
use Illuminate\\Http\\Request;
use KeepClear\\Http\\Controllers\\Controller;
use KeepClear\\Models\\Comment;
use KeepClear\\Models\\User;
use KeepClear\\Models\\Asset;
use KeepClear\\Traits\\Controllers\\ApiFilter;
use KeepClear\\Traits\\Controllers\\ApiParseBody;
use KeepClear\\Traits\\Controllers\\ApiException;
EOPHP

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

def engine_conf
Expand Down