PerlNitpick/Rule/RemoveEffectlessUTF8Pragma.pm

filter: Statementstmt 95.6% 22 / 23 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 80.7% 46 / 57 CC 12 SCAR 20.5
CC
12
Cov
85%
rewrite
10.6
__ANON__
3.0
BEGIN
1.0
CRAP 7.8
« PerlNitpick/Rule/RemoveUnusedImport.pm ↑ Summary PerlNitpick/Rule/RemoveUnusedInclude.pm »
1 package App::PerlNitpick::Rule::RemoveEffectlessUTF8Pragma;
2 # ABSTRACT: Remove `use utf8;` if all characters in the source file file are in ASCII.
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use PPI::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub rewrite {
Subroutine rewrite: called CC=10 SCAR=23.6
Pod undocumented
8 1 my ($self, $doc) = @_;
9  
10 my $use_utf8_statements = $doc->find(
11 23 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
12 23 my $st = $_[1];
13 23 ▶ $st->isa('PPI::Statement::Include') && $st->schild(0) eq 'use' && $st->schild(1) eq 'utf8';
Branch: 1 branch
BranchTrueFalseTotal
$st->isa("PPI::Statement::Include") and $st->schild(0) eq "use" and $st->schild(1) eq "utf8" 3 20 23
Condition66%2/3
$st->isa("PPI::Statement::Include") and $st->schild(0) eq "use"
!ll&&!rl&&r
2003
MC/DC50%1/2
$st->isa("PPI::Statement::Include") and $st->schild(0) eq "use"
$st->isa("PPI::Statement::Include") $st->schild(0) eq "use"
Truth table66%2/3
A and B
A= $st->isa("PPI::Statement::Include")B= $st->schild(0) eq "use"
ABresult
0X0
100
111
14 }
15 1 ▶ ) or return $doc;
Branch: 1 branch
BranchTrueFalseTotal
my $use_utf8_statements = $doc->find(sub { my $st = $_[1]; $st->isa("PPI::Statement::Include") and $st->schild(0) eq "use" and $st->schild(1) eq "utf8"; } ) or return $doc 1 0 1
16  
17 1 my $chars_outside_ascii_range = 0;
18 1 ▶ for (my $tok = $doc->first_token; $tok && $chars_outside_ascii_range == 0; $tok = $tok->next_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok and $chars_outside_ascii_range == 0) 19 1 20
Condition66%2/3
$tok and $chars_outside_ascii_range == 0
!ll&&!rl&&r
1019
MC/DC50%1/2
$tok and $chars_outside_ascii_range == 0
$tok $chars_outside_ascii_range == 0
Truth table66%2/3
A and B
A= $tokB= $chars_outside_ascii_range == 0
ABresult
0X0
100
111
19 19 ▶ next unless $tok->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->significant 7 12 19
20 12 my $src = $tok->content;
21 12 utf8::decode($src);
22  
23 12 my $len = length($src);
24 12 ▶ for (my $i = 0; $i < $len && $chars_outside_ascii_range == 0; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len and $chars_outside_ascii_range == 0) 34 12 46
Condition66%2/3
$i < $len and $chars_outside_ascii_range == 0
!ll&&!rl&&r
12034
MC/DC50%1/2
$i < $len and $chars_outside_ascii_range == 0
$i < $len $chars_outside_ascii_range == 0
Truth table66%2/3
A and B
A= $i < $lenB= $chars_outside_ascii_range == 0
ABresult
0X0
100
111
25 34 ▶ if (ord(substr($src, $i, 1)) > 127) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($src, $i, 1) > 127) 0 34 34
26 0 $chars_outside_ascii_range++;
27 }
28 }
29 }
30  
31 1 ▶ unless ($chars_outside_ascii_range) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($chars_outside_ascii_range) 1 0 1
32 1 $_->remove for @$use_utf8_statements;
33 }
34  
35 1 return $doc;
36 }
37  
38 1 1;
« PerlNitpick/Rule/RemoveUnusedImport.pm ↑ Summary PerlNitpick/Rule/RemoveUnusedInclude.pm »