PerlNitpick/Rule/DedupeIncludeStatements.pm

filter: Statementstmt 100% 27 / 27 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 80.0% 40 / 50 CC 10 SCAR 16.7
CC
10
Cov
86%
rewrite
7.3
_remove_with_trailing_characters
4.1
BEGIN
1.0
CRAP 5.3
« PerlNitpick/Rule/RemoveUnusedInclude.pm ↑ Summary PerlNitpick/Rule/AppendUnimportStatement.pm »
1 package App::PerlNitpick::Rule::DedupeIncludeStatements;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶sub rewrite {
Subroutine rewrite: called CC=7 SCAR=19.9
Pod undocumented
5 4 my ($self, $document) = @_;
6  
7 4 my %used;
8 my @to_delete;
9 4 ▶ for my $el (@{ $document->find('PPI::Statement::Include') ||[]}) {
Condition50%1/2
$document->find('PPI::Statement::Include') || []
l!l
40
MC/DC0%0/1
$document->find('PPI::Statement::Include') || []
$document->find('PPI::Statement::Include')
Truth table50%1/2
A
A= $document->find('PPI::Statement::Include')
Aresult
11
00
10 9 ▶ next unless $el->type && $el->type eq 'use';
Branch: 1 branch
BranchTrueFalseTotal
unless $el->type and $el->type eq "use" 0 9 9
Condition33%1/3
$el->type and $el->type eq "use"
!ll&&!rl&&r
009
MC/DC0%0/2
$el->type and $el->type eq "use"
$el->type $el->type eq "use"
Truth table33%1/3
A and B
A= $el->typeB= $el->type eq "use"
ABresult
0X0
100
111
11 9 my $module = $el->module;
12 9 my $code = "$el";
13 9 ▶ if ($used{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used{$code}) { } 4 5 9
14 4 push @to_delete, $el;
15 } else {
16 5 $used{$code} = 1;
17 }
18 }
19  
20 4 for my $el (@to_delete) {
21 4 $self->_remove_with_trailing_characters($el);
22 }
23  
24 4 return $document;
25 }
26  
27 4 ▶sub _remove_with_trailing_characters {
Subroutine _remove_with_trailing_characters: called CC=4 SCAR=14.0
28 4 my ($self, $el) = @_;
29  
30 4 ▶ while ( my $next = $el->next_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $el->next_sibling) 1 3 4
31 1 ▶ last if !$next->isa('PPI::Token::Whitespace');
Branch: 1 branch
BranchTrueFalseTotal
unless $next->isa("PPI::Token::Whitespace") 0 1 1
32 1 $next->remove;
33 1 ▶ last if $next eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $next eq "\n" 1 0 1
34 }
35 4 $el->remove;
36 4 return;
37 }
38  
39 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 1;
41  
42 __END__
« PerlNitpick/Rule/RemoveUnusedInclude.pm ↑ Summary PerlNitpick/Rule/AppendUnimportStatement.pm »