lib/PHP/Decode/Parser.pm

filter: Statementstmt 56.8% 1729 / 3041 Branchbran 48.7% 896 / 1840 Conditioncond 51.0% 491 / 962 MC/DCmcdc 35.4% 191 / 539 Subroutinesub 85.0% 91 / 107 Podpod 3.1% 3 / 94 totaltotal 51.6% 3401 / 6583 CC 1306 SCAR 90.0
CC
1306
Cov
53%
translate_stmt
41006.0
map_stmt
6509.7
_read_statement
4710.2
CRAP 8131.3
« blib/lib/PHP/Decode/Op.pm ↑ Summary lib/PHP/Decode/Transformer.pm »
1 #
2 # parse PHP source files
3 #
4 package PHP::Decode::Parser;
5 6 ▶use base 'PHP::Decode::Tokenizer';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use PHP::Decode::Array qw(is_int_index);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 our @EXPORT_OK = qw(is_variable is_symbol is_null is_const is_numval is_strval is_array is_block global_var global_split inst_var inst_split method_name method_split ns_name ns_split);
14 6 our %EXPORT_TAGS = (all => \@EXPORT_OK);
15  
16 6 our $VERSION = '0.127';
17  
18 # avoid 'Deep recursion' warnings for depth > 100
19 #
20 6 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 my $stridx = 1;
23 6 my $numidx = 1;
24 6 my $constidx = 1;
25 6 my $funidx = 1;
26 6 my $callidx = 1;
27 6 my $elemidx = 1;
28 6 my $expridx = 1;
29 6 my $stmtidx = 1;
30 6 my $blkidx = 1;
31 6 my $pfxidx = 1;
32 6 my $objidx = 1; # obj->
33 6 my $scopeidx = 1; # class::
34 6 my $refidx = 1; # & $var
35 6 my $classidx = 1; # class name {}
36 6 my $instidx = 1; # class instance
37 6 my $traitidx = 1; # trait name {}
38 6 my $nsidx = 1; # namespace\
39 6 my $fhidx = 1;
40  
41 # Initialize new parser using PHP::Decode::Tokenizer
42 # {inscript} - set to indicate already inside of script
43 # {warn} - warning message handler
44 # {log} - log message handler
45 # {debug} - debug message handler
46 # {filename} - optional filename (if not stdin or textstr)
47 # {max_strlen} - max strlen for debug strings
48 #
49 795 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
50 795 my ($class, %args) = @_;
51 795 ▶ my $strmap = $args{strmap} or croak __PACKAGE__ . " expects strmap";
Branch: 1 branch
BranchTrueFalseTotal
my $strmap = $args{"strmap"} or croak("PHP::Decode::Parser expects strmap") 795 0 795
52  
53 795 my $self = $class->SUPER::new(%args);
54 795 ▶ $self->{max_strlen} = 0 unless exists $self->{max_strlen};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"max_strlen"} 725 70 795
55 795 $self->{tok} = []; # init token list
56  
57 # filename is required to decode __FILE__
58 795 ▶ $self->{filename} = '__FILE__' unless exists $self->{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"filename"} 725 70 795
59  
60 795 ▶ $strmap->{'__LINE__'} = 1 unless exists $strmap->{'__LINE__'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $strmap->{"__LINE__"} 725 70 795
61 795 ▶ $strmap->{'#null'} = '' unless exists $strmap->{'#null'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $strmap->{"#null"} 725 70 795
62 795 return $self;
63 }
64  
65 # A sub parser is always inscript (the parent might have inscript=0)
66 #
67 70 ▶sub subparser {
Subroutine subparser: called CC=4 SCAR=14.6
Pod undocumented
68 70 my ($self, %args) = @_;
69 70 my $parser = PHP::Decode::Parser->new(strmap => $self->{strmap}, inscript => 1, filename => $self->{filename}, max_strlen => $self->{max_strlen}, warn => $self->{warn});
70 70 ▶ $parser->{log} = $self->{log} if exists $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"log"} 0 70 70
71 70 ▶ $parser->{debug} = $self->{debug} if exists $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"debug"} 0 70 70
72  
73 70 foreach my $k (keys %args) {
74 0 $parser->{$k} = $args{$k};
75 }
76 70 return $parser;
77 }
78  
79 0 ▶sub clear_strmap {
Subroutine clear_strmap: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my ($self) = @_;
81  
82 0 $stridx = 1;
83 0 $self->{strmap} = {};
84 0 $self->{strmap}{'__LINE__'} = 1;
85 0 return;
86 }
87  
88 6 my %ctrlmap = map { chr($_) => sprintf "\\x%02x", $_ } (0x00..0x1f, 0x7f);
89  
90 # convert controls from pattern to "\xNN"
91 #
92 0 ▶sub escape_ctrl {
Subroutine escape_ctrl: not called CC=5 SCAR=34.0
Pod undocumented
93 0 my ($s, $pat) = @_;
94 0 my @list = ();
95  
96 0 ▶ return "''" if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
97  
98 0 $_ = $s;
99 0 while (1) {
100 #if(/\G([${pat}])/sgc) {
101 # push(@list, sprintf "\"\\x%02x\"", ord($1));
102 0 ▶ if(/\G([${pat}]+)/sgc) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\G([$pat]+)/cgs) { } 0 0 0
elsif (/\G([^$pat]+)/cgs) { } 0 0 0
103 0 ▶ push(@list, '"' . join('', map { exists $ctrlmap{$_} ? $ctrlmap{$_} : $_ } split(//, $1)) . '"');
Branch: 1 branch
BranchTrueFalseTotal
exists $ctrlmap{$_} ? : 0 0 0
104 } elsif (/\G([^${pat}]+)/sgc) {
105 0 push(@list, "'" . $1 . "'");
106 } else {
107 0 last;
108 }
109 }
110 0 return join('.', @list);
111 }
112  
113 0 ▶sub shortstr {
Subroutine shortstr: not called CC=7 SCAR=40.3
Pod undocumented
114 0 my ($self, $s, $maxlen) = @_;
115  
116 0 ▶ if (!defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s) 0 0 0
117 0 return '(null)';
118 }
119  
120 # remove linefeeds
121 #
122 #$s =~ s/\r\n/ /g;
123  
124 # remove non-printable
125 #
126 0 $s =~ s/[\x01-\x1f\x7f]/\./g;
127  
128 0 ▶ if (($self->{max_strlen} > 0) && (!$maxlen || ($maxlen > $self->{max_strlen}))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}) 0 0 0
Condition0%0/6
$self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}
!ll&&!rl&&r
000
not $maxlen or $maxlen > $self->{"max_strlen"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"max_strlen"} > 0 and !$maxlen || $maxlen > $self->{"max_strlen"}
$self->{"max_strlen"} > 0 not $maxlen $maxlen > $self->{"max_strlen"}
Truth table0%0/4
A and not(B) or C
A= $self->{"max_strlen"} > 0B= not $maxlenC= $maxlen > $self->{"max_strlen"}
ABCresult
0XX0
1000
11X1
1011
129 0 $maxlen = $self->{max_strlen};
130 }
131 0 ▶ if ($maxlen && (length($s) > $maxlen)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxlen and length $s > $maxlen) 0 0 0
Condition0%0/3
$maxlen and length $s > $maxlen
!ll&&!rl&&r
000
MC/DC0%0/2
$maxlen and length $s > $maxlen
$maxlen length $s > $maxlen
Truth table0%0/3
A and B
A= $maxlenB= length $s > $maxlen
ABresult
0X0
100
111
132 0 $s = substr($s, 0, $maxlen-2).'..';
133 }
134 0 return $s;
135 }
136  
137 # 'str' -> #str$i
138 #
139 2030 ▶sub setstr {
Subroutine setstr: called CC=4 SCAR=14.1
Pod undocumented
140 2030 my ($self, $v) = @_;
141 2030 my $k;
142  
143 2030 ▶ if (exists $self->{strmap}->{rev}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'rev'}{$v}) { } 121 1909 2030
144 121 $k = $self->{strmap}->{rev}{$v};
145 121 return $k;
146 } else {
147 1909 $k = "#str$stridx";
148 1909 $stridx++;
149 1909 $self->{strmap}->{$k} = $v;
150 1909 $self->{strmap}->{rev}{$v} = $k;
151 }
152 # TODO: log also for $opt{P}
153 1909 ▶ $self->{log}->('setstr', "%s = %s", $k, $self->shortstr($v, $self->{max_strlen} || 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 1909 1909
Condition0%0/2
$self->{'max_strlen'} || 60
l!l
00
MC/DC0%0/1
$self->{'max_strlen'} || 60
$self->{'max_strlen'}
Truth table0%0/2
A
A= $self->{'max_strlen'}
Aresult
11
00
154 1909 return $k;
155 }
156  
157 # for expensive operations like repeated strconcat don't
158 # store reverse entry to save some space
159 #
160 110 ▶sub setstr_norev {
Subroutine setstr_norev: called CC=4 SCAR=14.1
Pod undocumented
161 110 my ($self, $v) = @_;
162 110 my $k;
163  
164 110 ▶ if (exists $self->{strmap}->{rev}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'rev'}{$v}) { } 21 89 110
165 21 $k = $self->{strmap}->{rev}{$v};
166 21 return $k;
167 } else {
168 89 $k = "#str$stridx";
169 89 $stridx++;
170 89 $self->{strmap}->{$k} = $v;
171 }
172 # TODO: log also for $opt{P}
173 89 ▶ $self->{log}->('setstr', "%s = %s [norev]", $k, $self->shortstr($v, $self->{max_strlen} || 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 89 89
Condition0%0/2
$self->{'max_strlen'} || 60
l!l
00
MC/DC0%0/1
$self->{'max_strlen'} || 60
$self->{'max_strlen'}
Truth table0%0/2
A
A= $self->{'max_strlen'}
Aresult
11
00
174 89 return $k;
175 }
176  
177 # number -> #num$i
178 #
179 868 ▶sub setnum {
Subroutine setnum: called CC=3 SCAR=11.0
Pod undocumented
180 868 my ($self, $v) = @_;
181 868 my $k;
182  
183 868 ▶ if (exists $self->{strmap}->{num}{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'num'}{$v}) { } 182 686 868
184 182 $k = $self->{strmap}->{num}{$v};
185 182 return $k;
186 } else {
187 686 $k = "#num$numidx";
188 686 $numidx++;
189 686 $self->{strmap}->{$k} = $v;
190 686 $self->{strmap}->{num}{$v} = $k;
191 }
192 686 ▶ $self->{log}->('setnum', "%s = %s", $k, $self->shortstr($v, 60)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 686 686
193 686 return $k;
194 }
195  
196 # 'const' -> #const$i
197 #
198 344 ▶sub setconst {
Subroutine setconst: called CC=2 SCAR=7.0
Pod undocumented
199 344 my ($self, $v) = @_;
200 344 my $k = "#const$constidx";
201 344 $constidx++;
202  
203 344 $self->{strmap}->{$k} = $v;
204 344 ▶ $self->{log}->('setconst', "%s = %s", $k, $v) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 344 344
205 344 return $k;
206 }
207  
208 274 ▶sub newarr {
Subroutine newarr: called CC=2 SCAR=7.0
Pod undocumented
209 274 my ($self) = @_;
210 274 my $arr = PHP::Decode::Array->new(strmap => $self->{strmap});
211 274 ▶ $self->{log}->('newarr', "%s", $arr->{name}) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 274 274
212 274 return $arr;
213 }
214  
215 # function -> #fun$i
216 #
217 309 ▶sub setfun {
Subroutine setfun: called CC=2 SCAR=7.0
Pod undocumented
218 309 my ($self, $cmd, $arglist, $block, $p) = @_;
219 309 my $k = "#fun$funidx";
220 309 $funidx++;
221  
222 309 $self->{strmap}->{$k} = [$cmd, $arglist, $block, $p];
223 309 ▶ $self->{log}->('setfun', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 309 309
224 309 return $k;
225 }
226  
227 781 ▶sub setcall {
Subroutine setcall: called CC=2 SCAR=7.0
Pod undocumented
228 781 my ($self, $cmd, $arglist) = @_;
229 781 my $k = "#call$callidx";
230 781 $callidx++;
231  
232 781 $self->{strmap}->{$k} = [$cmd, $arglist];
233 781 ▶ $self->{log}->('setcall', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 781 781
234 781 return $k;
235 }
236  
237 538 ▶sub setelem {
Subroutine setelem: called CC=2 SCAR=7.0
Pod undocumented
238 538 my ($self, $var, $idx) = @_;
239 538 my $k = "#elem$elemidx";
240 538 $elemidx++;
241  
242 538 $self->{strmap}->{$k} = [$var, $idx];
243 538 ▶ $self->{log}->('setelem', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 538 538
244 538 return $k;
245 }
246  
247 1983 ▶sub setexpr {
Subroutine setexpr: called CC=2 SCAR=7.0
Pod undocumented
248 1983 my ($self, $op, $v1, $v2) = @_;
249 1983 my $k = "#expr$expridx";
250 1983 $expridx++;
251  
252 1983 $self->{strmap}->{$k} = [$op, $v1, $v2];
253 1983 ▶ $self->{log}->('setexpr', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 1983 1983
254 1983 return $k;
255 }
256  
257 2877 ▶sub setblk {
Subroutine setblk: called CC=2 SCAR=7.0
Pod undocumented
258 2877 my ($self, $type, $a) = @_;
259 2877 my $k = "#blk$blkidx";
260 2877 $blkidx++;
261  
262 2877 $self->{strmap}->{$k} = [$type, $a];
263 2877 ▶ $self->{log}->('setblk', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 2877 2877
264 2877 return $k;
265 }
266  
267 853 ▶sub setstmt {
Subroutine setstmt: called CC=2 SCAR=7.0
Pod undocumented
268 853 my ($self, $s) = @_;
269 853 my $k = "#stmt$stmtidx";
270 853 $stmtidx++;
271  
272 853 $self->{strmap}->{$k} = $s;
273 853 ▶ $self->{log}->('setstmt', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 853 853
274 853 return $k;
275 }
276  
277 55 ▶sub setpfx {
Subroutine setpfx: called CC=2 SCAR=7.0
Pod undocumented
278 55 my ($self, $s) = @_;
279 55 my $k = "#pfx$pfxidx";
280 55 $pfxidx++;
281  
282 55 $self->{strmap}->{$k} = $s;
283 55 ▶ $self->{log}->('setpfx', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 55 55
284 55 return $k;
285 }
286  
287 52 ▶sub setobj {
Subroutine setobj: called CC=2 SCAR=7.0
Pod undocumented
288 52 my ($self, $s, $property) = @_;
289 52 my $k = "#obj$objidx";
290 52 $objidx++;
291  
292 52 $self->{strmap}->{$k} = [$s, $property];
293 52 ▶ $self->{log}->('setobj', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 52 52
294 52 return $k;
295 }
296  
297 41 ▶sub setscope {
Subroutine setscope: called CC=2 SCAR=7.0
Pod undocumented
298 41 my ($self, $s, $elem) = @_;
299 41 my $k = "#scope$scopeidx";
300 41 $scopeidx++;
301  
302 41 $self->{strmap}->{$k} = [$s, $elem];
303 41 ▶ $self->{log}->('setscope', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 41 41
304 41 return $k;
305 }
306  
307 8 ▶sub setref {
Subroutine setref: called CC=2 SCAR=7.0
Pod undocumented
308 8 my ($self, $s) = @_;
309 8 my $k = "#ref$refidx";
310 8 $refidx++;
311  
312 8 $self->{strmap}->{$k} = [$s];
313 8 ▶ $self->{log}->('setref', "%s = %s", $k, $s) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 8 8
314 8 return $k;
315 }
316  
317 69 ▶sub setclass {
Subroutine setclass: called CC=2 SCAR=7.0
Pod undocumented
318 69 my ($self, $name, $block, $p) = @_;
319 69 my $k = "#class$classidx";
320 69 $classidx++;
321  
322 69 $self->{strmap}->{$k} = [$name, $block, $p];
323 69 ▶ $self->{log}->('setclass', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 69 69
324 69 return $k;
325 }
326  
327 1 ▶sub settrait {
Subroutine settrait: called CC=2 SCAR=7.0
Pod undocumented
328 1 my ($self, $name, $block) = @_;
329 1 my $k = "#trait$traitidx";
330 1 $traitidx++;
331  
332 1 $self->{strmap}->{$k} = [$name, $block];
333 1 ▶ $self->{log}->('settrait', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 1 1
334 1 return $k;
335 }
336  
337 34 ▶sub setinst {
Subroutine setinst: called CC=2 SCAR=7.0
Pod undocumented
338 34 my ($self, $class, $initcall, $instctx) = @_;
339 34 my $k = "#inst$instidx";
340 34 $instidx++;
341  
342 34 $self->{strmap}->{$k} = [$class, $initcall, $instctx];
343 34 ▶ $self->{log}->('setinst', "%s = %s", $k, $class) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 34 34
344 34 return $k;
345 }
346  
347 12 ▶sub setns {
Subroutine setns: called CC=2 SCAR=7.0
Pod undocumented
348 12 my ($self, $name, $elem) = @_;
349 12 my $k = "#ns$nsidx";
350 12 $nsidx++;
351  
352 12 $self->{strmap}->{$k} = [$name, $elem];
353 12 ▶ $self->{log}->('setns', "%s = %s", $k, $self->stmt_str($k)) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 12 12
354 12 return $k;
355 }
356  
357 2 ▶sub newfh {
Subroutine newfh: called CC=3 SCAR=11.9
Pod undocumented
358 2 my ($self, $filename, $mode) = @_;
359 2 my %file;
360 my $a;
361 2 my $fh = "#fh$fhidx";
362 2 $fhidx++;
363  
364 2 $self->{strmap}->{$fh} = \%file;
365 2 $self->{strmap}->{idx}{$fh} = 0;
366  
367 2 $file{name} = $filename;
368 2 $file{mode} = $mode;
369 2 $file{pos} = 0;
370 2 ▶ if ($filename eq '__FILE__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq '__FILE__') { } 0 2 2
371 0 $file{buf} = $self->{strmap}->{$filename}; # todo: cleanup
372 } else {
373 2 $file{buf} = '';
374 2 return; # TODO: support write & non-existing files
375 }
376 0 ▶ $self->{log}->('newfh', "$fh ($filename, $mode)") if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
377 0 return ($fh, \%file);
378 }
379  
380 71 ▶sub stmt_str {
Subroutine stmt_str: called CC=58 SCAR=78.8
Pod undocumented
381 71 my ($self, $s) = @_;
382  
383 71 ▶ unless ($s =~ /^#\w+\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ /^#\w+\d+$/) 0 71 71
384 0 return $s;
385 }
386  
387 71 ▶ if ($s =~ /^#null$/) {
Branch: 20 branches
BranchTrueFalseTotal
if ($s =~ /^#null$/) { } 0 71 71
elsif ($s =~ /^#num\d+$/) { } 0 71 71
elsif ($s =~ /^#const\d+$/) { } 0 71 71
elsif ($s =~ /^#str\d+$/) { } 0 71 71
elsif ($s =~ /^#arr\d+$/) { } 0 71 71
elsif ($s =~ /^#fun\d+$/) { } 0 71 71
elsif ($s =~ /^#call\d+$/) { } 69 2 71
elsif ($s =~ /^#elem\d+$/) { } 2 0 2
elsif ($s =~ /^#expr\d+$/) { } 0 0 0
elsif ($s =~ /^#pfx\d+$/) { } 0 0 0
elsif ($s =~ /^#obj\d+$/) { } 0 0 0
elsif ($s =~ /^#scope\d+$/) { } 0 0 0
elsif ($s =~ /^#ns\d+$/) { } 0 0 0
elsif ($s =~ /^#inst\d+$/) { } 0 0 0
elsif ($s =~ /^#ref\d+$/) { } 0 0 0
elsif ($s =~ /^#class\d+$/) { } 0 0 0
elsif ($s =~ /^#trait\d+$/) { } 0 0 0
elsif ($s =~ /^#fh\d+$/) { } 0 0 0
elsif ($s =~ /^#blk\d+$/) { } 0 0 0
elsif ($s =~ /^#stmt\d+$/) { } 0 0 0
388 0 return 'null'; # '' or 0 in str/num context
389 } elsif ($s =~ /^#num\d+$/) {
390 0 return $self->{strmap}{$s};
391 } elsif ($s =~ /^#const\d+$/) {
392 0 return $self->{strmap}{$s};
393 } elsif ($s =~ /^#str\d+$/) {
394 0 my $v = $self->{strmap}{$s};
395 0 return $self->shortstr($v, 60);
396 } elsif ($s =~ /^#arr\d+$/) {
397 0 my $arr = $self->{strmap}{$s};
398 0 my $keys = $arr->get_keys();
399 0 my $size = scalar @$keys;
400  
401 0 return $arr->{name} . "[size $size]";
402 } elsif ($s =~ /^#fun\d+$/) {
403 0 my ($f, $a, $b, $p) = @{$self->{strmap}{$s}};
404 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
405  
406 0 ▶ return (defined $f ? $f : '') . "(" . join(', ', @$a) . ") { " . join(' ', @$stmts) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $f ? : 0 0 0
407 } elsif ($s =~ /^#call\d+$/) {
408 69 my ($f, $a) = @{$self->{strmap}->{$s}};
409  
410 69 return $f . "(" . join(', ', @$a) . ")";
411 } elsif ($s =~ /^#elem\d+$/) {
412 2 my ($v, $i) = @{$self->{strmap}{$s}};
413  
414 2 ▶ return $v . "[" . (defined $i ? $i : '') . "]";
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 2 0 2
415 } elsif ($s =~ /^#expr\d+$/) {
416 # if v1 missing: prefix op
417 # if v2 missing: postfix op
418 0 my ($op, $v1, $v2) = @{$self->{strmap}{$s}};
419  
420 0 ▶ return (defined $v1 ? $v1 . " " : '') . $op . (defined $v2 ? " " . $v2 : '');
Branch: 2 branches
BranchTrueFalseTotal
defined $v1 ? : 0 0 0
defined $v2 ? : 0 0 0
421 } elsif ($s =~ /^#pfx\d+$/) {
422 0 my $pfx = $self->{strmap}{$s};
423 0 return join(' ', sort keys %$pfx);
424 } elsif ($s =~ /^#obj\d+$/) {
425 0 my ($o, $m) = @{$self->{strmap}{$s}};
426 0 return $o . "->" . $m;
427 } elsif ($s =~ /^#scope\d+$/) {
428 0 my ($c, $e) = @{$self->{strmap}{$s}};
429 0 return $c . "::" . $e;
430 } elsif ($s =~ /^#ns\d+$/) {
431 0 my ($n, $e) = @{$self->{strmap}{$s}};
432 0 ▶ return (defined $n ? $n : '') . '\\' . $e;
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
433 } elsif ($s =~ /^#inst\d+$/) {
434 0 my ($c, $f, $i) = @{$self->{strmap}{$s}};
435 0 return $c;
436 } elsif ($s =~ /^#ref\d+$/) {
437 0 my ($v) = @{$self->{strmap}{$s}};
438 0 return "&" . $v;
439 } elsif ($s =~ /^#class\d+$/) {
440 0 my ($c, $b, $p) = @{$self->{strmap}{$s}};
441 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
442  
443 0 ▶ return (defined $c ? $c : '') . (exists $p->{parent} ? " extends $p->{parent}" : '') . " { " . join(' ', @$stmts) . " }";
Branch: 2 branches
BranchTrueFalseTotal
defined $c ? : 0 0 0
exists $p->{'parent'} ? : 0 0 0
444 } elsif ($s =~ /^#trait\d+$/) {
445 0 my ($t, $b) = @{$self->{strmap}{$s}};
446 0 my ($type, $stmts) = @{$self->{strmap}{$b}};
447  
448 0 ▶ return (defined $t ? $t : '') . " { " . join(' ', @$stmts) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 0 0 0
449 } elsif ($s =~ /^#fh\d+$/) {
450 0 my $f = $self->{strmap}{$s}{name};
451 0 my $m = $self->{strmap}{$s}{mode};
452 0 my $p = $self->{strmap}{$s}{pos};
453  
454 0 return "(" . $f . ", " . $m . ")";
455 } elsif ($s =~ /^#blk\d+$/) {
456 0 my ($type, $a) = @{$self->{strmap}{$s}};
457 0 return $type . " { " . join(' ', @$a) . " }";
458 } elsif ($s =~ /^#stmt\d+$/) {
459 0 my $cmd = $self->{strmap}{$s}[0];
460  
461 0 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 0 0 0
elsif ($cmd eq 'print') { } 0 0 0
elsif ($cmd eq 'namespace') { } 0 0 0
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 0 0
elsif ($cmd eq 'use') { } 0 0 0
elsif ($cmd eq 'global') { } 0 0 0
elsif ($cmd eq 'static') { } 0 0 0
elsif ($cmd eq 'const') { } 0 0 0
elsif ($cmd eq 'unset') { } 0 0 0
elsif ($cmd eq 'return') { } 0 0 0
elsif ($cmd eq 'goto') { } 0 0 0
elsif ($cmd eq 'label') { } 0 0 0
elsif ($cmd eq 'throw') { } 0 0 0
elsif ($cmd eq 'if') { } 0 0 0
elsif ($cmd eq 'while') { } 0 0 0
elsif ($cmd eq 'do') { } 0 0 0
elsif ($cmd eq 'for') { } 0 0 0
elsif ($cmd eq 'foreach') { } 0 0 0
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'case') { } 0 0 0
elsif ($cmd eq 'try') { } 0 0 0
462 0 my $a = $self->{strmap}{$s}[1];
463 0 return $cmd . " " . join(', ', @$a);
464 } elsif ($cmd eq 'print') {
465 0 my $arg = $self->{strmap}{$s}[1];
466 0 return $cmd . " " . $arg;
467 } elsif ($cmd eq 'namespace') {
468 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
469 0 ▶ return $cmd . " " . $arg . (defined $block ? " { $block }" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $block ? : 0 0 0
470 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
471 0 my $arg = $self->{strmap}{$s}[1];
472 0 return $cmd . " " . $arg;
473 } elsif ($cmd eq 'use') {
474 0 my $a = $self->{strmap}{$s}[1];
475 0 return $cmd . " " . join(', ', @$a);
476 } elsif ($cmd eq 'global') {
477 0 my $a = $self->{strmap}{$s}[1];
478 0 return $cmd . " " . join(', ', @$a);
479 } elsif ($cmd eq 'static') {
480 0 my ($a, $p) = @{$self->{strmap}{$s}}[1..2];
481 0 return $cmd . join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd) . ' ' . join(', ', @$a);
482 } elsif ($cmd eq 'const') {
483 0 my ($a, $p) = @{$self->{strmap}{$s}}[1..2];
484 0 return $cmd . join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd) . ' ' . join(', ', @$a);
485 } elsif ($cmd eq 'unset') {
486 0 my $a = $self->{strmap}{$s}[1];
487 0 return $cmd . " (" . join(', ', @$a) . ")";
488 } elsif ($cmd eq 'return') {
489 0 my $a = $self->{strmap}{$s}[1];
490 0 return $cmd . " " . $a;
491 } elsif ($cmd eq 'goto') {
492 0 my $a = $self->{strmap}{$s}[1];
493 0 return $cmd . " " . $a;
494 } elsif ($cmd eq 'label') {
495 0 my $a = $self->{strmap}{$s}[1];
496 0 return $cmd . " " . $a . ":";
497 } elsif ($cmd eq 'throw') {
498 0 my $arg = $self->{strmap}{$s}[1];
499 0 return $cmd . " " . $arg;
500 } elsif ($cmd eq 'if') {
501 0 my ($cond, $then, $else) = @{$self->{strmap}{$s}}[1..3];
502 0 ▶ return $cmd . " ($cond) then $then" . (defined $else ? " else $else" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $else ? : 0 0 0
503 } elsif ($cmd eq 'while') {
504 0 my ($cond, $block) = @{$self->{strmap}{$s}}[1..2];
505 0 return $cmd . " ($cond) { $block }";
506 } elsif ($cmd eq 'do') {
507 0 my ($cond, $block) = @{$self->{strmap}{$s}}[1..2];
508 0 return $cmd . " { $block } while ($cond)";
509 } elsif ($cmd eq 'for') {
510 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}{$s}}[1..4];
511 0 return $cmd . " ($pre; $cond; $post) { $block }";
512 } elsif ($cmd eq 'foreach') {
513 0 my ($expr, $key, $value, $block) = @{$self->{strmap}{$s}}[1..4];
514 0 ▶ return $cmd . " ($expr " . (defined $key ? "$key => " : '') . "$value) { $block }";
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 0 0 0
515 } elsif ($cmd eq 'switch') {
516 0 my ($expr, $cases) = @{$self->{strmap}{$s}}[1..2];
517 0 ▶ return $cmd . " ($expr) { " . join(' ', map { sprintf "%s %s", defined $_->[0] ? "case $_->[0]:" : "default:", $_->[1]; } @$cases) . " }";
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[0] ? : 0 0 0
518 } elsif ($cmd eq 'case') {
519 0 my $expr = $self->{strmap}{$s}[1];
520 0 ▶ return (defined $expr ? "case $expr:" : "default:");
Branch: 1 branch
BranchTrueFalseTotal
defined $expr ? : 0 0 0
521 } elsif ($cmd eq 'try') {
522 0 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
523 0 ▶ return $cmd . " { $try }" . join(' ', map { sprintf " catch (%s) { %s }", $_->[0] // '-', $_->[1]; } @$catches) . (defined $finally ? " finally { $finally }" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $finally ? : 0 0 0
Condition0%0/2
$_->[0] // "-"
l!l
00
MC/DC0%0/1
$_->[0] // "-"
$_->[0]
Truth table0%0/2
A
A= $_->[0]
Aresult
11
00
524 } else {
525 0 return $cmd;
526 }
527 }
528 0 return $s;
529 }
530  
531 0 ▶sub val {
Subroutine val: not called CC=1 SCAR=6.9
Pod undocumented
532 0 my ($self, $s) = @_;
533 #exists $self->{strmap}{$s} || die "assert: bad statement $s passed to parser->val()";
534 0 return $self->{strmap}{$s}; # for lookup after is_strval(), is_array(), ..
535 }
536  
537 1223 ▶sub get_strval {
Subroutine get_strval: called CC=2 SCAR=6.9
Pod undocumented
538 1223 my ($self, $s) = @_;
539 #defined($s) || die "assert: undefined statement passed to parser->get_strval()";
540  
541 1223 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 1202 21 1223
542 1202 return $self->{strmap}{$s};
543 }
544 21 return;
545 }
546  
547 199 ▶sub get_strval_or_str {
Subroutine get_strval_or_str: called CC=2 SCAR=6.9
Pod undocumented
548 199 my ($self, $s) = @_;
549  
550 199 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 64 135 199
551 64 $s = $self->{strmap}{$s};
552 }
553 199 return $s;
554 }
555  
556 0 ▶sub get_numval {
Subroutine get_numval: not called CC=2 SCAR=17.9
Pod undocumented
557 0 my ($self, $s) = @_;
558  
559 0 ▶ if ($s =~ /^(\#num\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#num\d+|\#null)$/) 0 0 0
560 0 $s = $self->{strmap}{$s};
561 }
562 0 return $s;
563 }
564  
565 1079 ▶sub is_null {
Subroutine is_null: called CC=2 SCAR=6.9
Pod undocumented
566 1079 my ($s) = @_;
567  
568 1079 ▶ if ($s =~ /^(\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#null)$/) 57 1022 1079
569 57 return 1;
570 }
571 1022 return 0;
572 }
573  
574 7561 ▶sub is_const {
Subroutine is_const: called CC=2 SCAR=6.9
Pod undocumented
575 7561 my ($s) = @_;
576  
577 7561 ▶ if ($s =~ /^(\#const\d++)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#const\d++)$/) 259 7302 7561
578 259 return 1;
579 }
580 7302 return 0;
581 }
582  
583 190 ▶sub is_numval {
Subroutine is_numval: called CC=2 SCAR=6.9
Pod undocumented
584 190 my ($s) = @_;
585  
586 190 ▶ if ($s =~ /^(\#num\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#num\d+)$/) 135 55 190
587 135 return 1;
588 }
589 55 return 0;
590 }
591  
592 16224 ▶sub is_strval {
Subroutine is_strval: called CC=2 SCAR=6.9
Pod undocumented
593 16224 my ($s) = @_;
594  
595 16224 ▶ if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^(\#(str|num|const)\d+|\#null)$/) 5832 10392 16224
596 5832 return 1;
597 }
598 10392 return 0;
599 }
600  
601 2478 ▶sub is_array {
Subroutine is_array: called CC=2 SCAR=6.9
Pod undocumented
602 2478 my ($s) = @_;
603  
604 2478 ▶ if ($s =~ /^#arr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#arr\d+$/) 968 1510 2478
605 968 return 1;
606 }
607 1510 return 0;
608 }
609  
610 12800 ▶sub is_block {
Subroutine is_block: called CC=2 SCAR=6.9
Pod undocumented
611 12800 my ($s) = @_;
612  
613 12800 ▶ if ($s =~ /^#blk\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#blk\d+$/) 4254 8546 12800
614 4254 return 1;
615 }
616 8546 return 0;
617 }
618  
619 4 ▶sub bighex {
Subroutine bighex: called CC=5 SCAR=17.4
Pod undocumented
620 4 my ($hex) = @_;
621  
622 # hex() warns for 64-bit numbers like 0x10000000
623 # (Hexadecimal number > 0xffffffff non-portable)
624 # php converts such numbers to float.
625 #
626 # The 'use bigint qw/hex/' workaround would transparently
627 # use Math::BigInt internally. So convert 64-bit floats
628 # manually to float.
629 #
630 # also: perl warns for '0X'-prefix - php not
631 #
632 4 ▶ if (length($hex) <= 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $hex <= 10) 3 1 4
633 3 ▶ if ($hex =~ /^0X(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hex =~ /^0X(.*)$/) { } 0 3 3
634 0 return hex($1);
635 } else {
636 3 return hex($hex);
637 }
638 }
639 1 my ($high, $low) = $hex =~ /^0[xX]([0-9a-fA-F]{1,8})([0-9a-fA-F]{8})$/;
640 1 ▶ unless (defined $high) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $high) 0 1 1
641 0 warn "$hex is not a 64-bit hex number";
642 0 return hex($hex);
643 }
644 # with 32bit integers perl truncates (1 << 32) to 0x1
645 #
646 # use bignum instead of bigint here - bigint overrides the
647 # operators to result in a bigint when one of its operands
648 # is a bigint (so division would never result in a float).
649 # https://perldoc.perl.org/bigint
650 #
651 1 ▶ if ($Config{ivsize} == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PHP::Decode::Parser::Config{'ivsize'} == 4) { } 0 1 1
652 6 ▶ use bignum;
Subroutine BEGIN: called CC=1 SCAR=0.0
653 0 return hex("0x$low") + (hex("0x$high") << 32);
654 } else {
655 1 return hex("0x$low") + (hex("0x$high") << 32);
656 }
657 }
658  
659 # override methods inherited from PhpTokenizer
660 {
661 3143 ▶ sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
662 3143 my ($tab, $sym) = @_;
663 3143 push(@{$tab->{tok}}, $sym);
664 3143 return;
665 }
666 2271 ▶ sub add_open {
Subroutine add_open: called CC=1 SCAR=0.0
Pod undocumented
667 2271 my ($tab, $sym) = @_;
668 2271 push(@{$tab->{tok}}, $sym);
669 2271 return;
670 }
671 2263 ▶ sub add_close {
Subroutine add_close: called CC=8 SCAR=20.9
Pod undocumented
672 2263 my ($tab, $sym) = @_;
673 2263 my $pos = scalar @{$tab->{tok}};
674  
675 # join string literals with '.' operator if possible
676 # (this should also be done by php_decode)
677 #
678 2263 ▶ if (defined $tab->{strmap}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'} and $sym eq ')' and $pos > 2 and $tab->{'tok'}[$pos - 1] =~ /^#num\d+$/ and $tab->{'tok'}[$pos - 2] eq '(' and $tab->{'tok'}[$pos - 3] =~ /^chr$/i) { } 6 2257 2263
Condition93%14/15
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "(" and $tab->{"tok"}[$pos - 3] =~ /^chr$/i
!ll&&!rl&&r
2175826
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "("
!ll&&!rl&&r
21264988
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/
!ll&&!rl&&r
10021124137
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2
!ll&&!rl&&r
978241261
defined $tab->{"strmap"} and $sym eq ")"
!ll&&!rl&&r
09781285
MC/DC83%5/6
defined $tab->{"strmap"} and $sym eq ")" and $pos > 2 and $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ and $tab->{"tok"}[$pos - 2] eq "(" and $tab->{"tok"}[$pos - 3] =~ /^chr$/i
defined $tab->{"strmap"} $sym eq ")" $pos > 2 $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/ $tab->{"tok"}[$pos - 2] eq "(" $tab->{"tok"}[$pos - 3] =~ /^chr$/i
Truth table85%6/7
A and B and C and D and E and F
A= defined $tab->{"strmap"}B= $sym eq ")"C= $pos > 2D= $tab->{"tok"}[$pos - 1] =~ /^#num\d+$/E= $tab->{"tok"}[$pos - 2] eq "("F= $tab->{"tok"}[$pos - 3] =~ /^chr$/i
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
679 && ($sym eq ')')
680 && ($pos > 2)
681 && ($tab->{tok}->[$pos-1] =~ /^#num\d+$/)
682 && ($tab->{tok}->[$pos-2] eq '(')
683 && ($tab->{tok}->[$pos-3] =~ /^chr$/i)) {
684 6 my $val = $tab->{strmap}->{$tab->{tok}->[$pos-1]};
685 6 ▶ if ($val != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val != 0) { } 6 0 6
686 6 my $ch = chr(int($val) & 0xff);
687 6 pop(@{$tab->{tok}});
688 6 pop(@{$tab->{tok}});
689 6 pop(@{$tab->{tok}});
690 #$tab->{log}->('tokenize', "CHR chr($val) [$ch]") if $tab->{log};
691 6 $tab->add_str($ch);
692 } else {
693 0 push(@{$tab->{tok}}, $sym);
694 }
695 } else {
696 2257 push(@{$tab->{tok}}, $sym);
697 }
698 2263 return;
699 }
700 3493 ▶ sub add_white {
Subroutine add_white: called CC=3 SCAR=11.0
Pod undocumented
701 3493 my ($tab, $sym) = @_;
702 3493 ▶ if ($sym eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq "\n") 6 3487 3493
703 6 $tab->{strmap}->{'__LINE__'} += 1;
704 6 ▶ $tab->{debug}->('tokenize', "set linenum: %d", $tab->{strmap}->{'__LINE__'}) if $tab->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $tab->{"debug"} 0 6 6
705 }
706 #push(@{$tab->{tok}}, ' ');
707 3493 return;
708 }
709 8 ▶ sub add_comment {
Subroutine add_comment: called CC=1 SCAR=0.0
Pod undocumented
710 8 my ($tab, $sym) = @_;
711 #push(@{$tab->{tok}}, "/*$sym*/");
712 8 return;
713 }
714 2187 ▶ sub add_sym {
Subroutine add_sym: called CC=2 SCAR=6.9
Pod undocumented
715 2187 my ($tab, $sym) = @_;
716 2187 ▶ if ($sym eq '__LINE__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq '__LINE__') { } 4 2183 2187
717 # TODO: track line-number for each symbol, so that
718 # it is also valid in eval()-code?
719 #
720 4 $tab->{warn}->('tokenize', "substitute __LINE__ with %d", $tab->{strmap}->{'__LINE__'});
721 4 my $k = $tab->setnum($tab->{strmap}->{'__LINE__'});
722 4 push(@{$tab->{tok}}, $k);
723 } else {
724 2183 push(@{$tab->{tok}}, $sym);
725 }
726 2187 return;
727 }
728 1780 ▶ sub add_var {
Subroutine add_var: called CC=1 SCAR=0.0
Pod undocumented
729 1780 my ($tab, $sym) = @_;
730 1780 push(@{$tab->{tok}}, '$'.$sym);
731 1780 return;
732 }
733 1041 ▶ sub add_str {
Subroutine add_str: called CC=5 SCAR=16.6
Pod undocumented
734 1041 my ($tab, $sym) = @_;
735  
736 1041 ▶ if (defined $tab->{strmap}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'}) { } 1041 0 1041
737 1041 my $pos = scalar @{$tab->{tok}};
738  
739 # join string literals with '.' operator if possible
740 # (this should also be done by php_decode)
741 #
742 1041 ▶ if (($pos > 1) && ($tab->{tok}->[$pos-1] eq '.') && ($tab->{tok}->[$pos-2] =~ /^#str\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/) 11 1030 1041
Condition100%6/6
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
!ll&&!rl&&r
10022811
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "."
!ll&&!rl&&r
4695639
MC/DC100%3/3
$pos > 1 and $tab->{"tok"}[$pos - 1] eq "." and $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
$pos > 1 $tab->{"tok"}[$pos - 1] eq "." $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
Truth table100%4/4
A and B and C
A= $pos > 1B= $tab->{"tok"}[$pos - 1] eq "."C= $tab->{"tok"}[$pos - 2] =~ /^#str\d+$/
ABCresult
0XX0
10X0
1100
1111
743 11 my $oldstr = $tab->{strmap}->{$tab->{tok}->[$pos-2]};
744 11 pop(@{$tab->{tok}});
745 11 pop(@{$tab->{tok}});
746 #$tab->{log}->('tokenize', "JOIN $oldstr . $sym") if $tab->{log};
747 11 $sym = $oldstr . $sym;
748 }
749  
750 # remember last linenum for each new #str symbol
751 #
752 1041 $tab->{strmap}->{'__LINEMAP__'}{"#str$stridx"} = $tab->{strmap}->{'__LINE__'};
753  
754 # substitute: 'str' -> #str$i
755 #
756 1041 my $k = $tab->setstr($sym);
757 1041 push(@{$tab->{tok}}, $k);
758 } else {
759 0 push(@{$tab->{tok}}, '\'');
760 0 push(@{$tab->{tok}}, $sym);
761 0 push(@{$tab->{tok}}, '\'');
762 }
763 1041 return;
764 }
765 538 ▶ sub add_num {
Subroutine add_num: called CC=5 SCAR=16.7
Pod undocumented
766 538 my ($tab, $sym) = @_;
767  
768 538 ▶ if (defined $tab->{strmap}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tab->{'strmap'}) { } 538 0 538
769 # substitute: number -> #num$i
770 #
771 538 my $num;
772 538 ▶ if ($sym =~ /^0[xX][0-9a-fA-F]+$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($sym =~ /^0[xX][0-9a-fA-F]+$/) { } 4 534 538
elsif ($sym =~ /^0[0-7]+$/) { } 0 534 534
elsif ($sym =~ /^[0-9]*\.[0-9]*/) { } 6 528 534
773 #$num = hex($sym);
774 4 $num = bighex($sym);
775 } elsif ($sym =~ /^0[0-7]+$/) {
776 0 $num = oct($sym);
777 } elsif ($sym =~ /^[0-9]*\.[0-9]*/) {
778 6 $num = $sym * 1;
779 } else {
780 528 $num = $sym;
781 }
782 538 my $k = $tab->setnum($num);
783 538 push(@{$tab->{tok}}, $k);
784 } else {
785 0 push(@{$tab->{tok}}, $sym);
786 }
787 538 return;
788 }
789 8 ▶ sub add_script_start {
Subroutine add_script_start: called CC=1 SCAR=0.0
Pod undocumented
790 8 my ($tab, $sym) = @_;
791 #push(@{$tab->{tok}}, $sym);
792 8 return;
793 }
794 799 ▶ sub add_script_end {
Subroutine add_script_end: called CC=1 SCAR=0.0
Pod undocumented
795 799 my ($tab, $sym) = @_;
796 #push(@{$tab->{tok}}, $sym);
797 799 return;
798 }
799 8 ▶ sub add_noscript {
Subroutine add_noscript: called CC=3 SCAR=11.0
Pod undocumented
800 8 my ($tab, $sym) = @_;
801  
802 8 ▶ if ((scalar @{$tab->{tok}} > 0) && ($tab->{tok}->[-1] ne ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";") 1 7 8
Condition100%3/3
scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";"
!ll&&!rl&&r
611
MC/DC100%2/2
scalar @{$tab->{"tok"};} > 0 and $tab->{"tok"}[-1] ne ";"
scalar @{$tab->{"tok"};} > 0 $tab->{"tok"}[-1] ne ";"
Truth table100%3/3
A and B
A= scalar @{$tab->{"tok"};} > 0B= $tab->{"tok"}[-1] ne ";"
ABresult
0X0
100
111
803 # append ';' if missing at end of php-block
804 1 $tab->add(';');
805 }
806 8 $tab->add_sym('echo');
807 8 $tab->add_str($sym);
808 8 $tab->add(';');
809 8 $tab->add_script_end('');
810 8 return;
811 }
812 0 ▶ sub add_bad_open {
Subroutine add_bad_open: not called CC=1 SCAR=6.9
Pod undocumented
813 0 my ($tab, $sym) = @_;
814  
815 0 $tab->{warn}->('tokenize', "in script got bad open %s", $sym);
816 0 $tab->add($sym);
817 0 return;
818 }
819 0 ▶ sub tok_dump {
Subroutine tok_dump: not called CC=1 SCAR=6.9
Pod undocumented
820 0 my ($tab) = @_;
821 0 return join('', @{$tab->{tok}});
822 }
823 0 ▶ sub tok_count {
Subroutine tok_count: not called CC=1 SCAR=6.9
Pod undocumented
824 0 my ($tab) = @_;
825 0 return scalar @{$tab->{tok}};
826 }
827 }
828  
829 # http://php.net/manual/en/reserved.keywords.php
830 #
831 6 my %php_keywords = map { $_ => 1 } ('__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'readonly', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor');
832  
833 6 my %php_modifiers = map { $_ => 1 } ('const', 'final', 'private', 'protected', 'public', 'readonly', 'static', 'var');
834  
835 # All magic constants are resolved at compile time
836 # https://www.php.net/manual/en/language.constants.magic.php
837 #
838 6 my %magic_constants = map { $_ => 1 } ('__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__', 'ClassName::class');
839  
840 # builtin types: https://www.php.net/manual/en/language.types.intro.php
841 #
842 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
843 6 T_VOID => 0x0001,
844 T_INT => 0x0002,
845 T_FLOAT => 0x0004,
846 T_BOOL => 0x0008,
847 T_STR => 0x0010,
848 T_ARRAY => 0x0020,
849 T_OBJECT => 0x0040,
850 T_CALL => 0x0080,
851 T_MASK => 0xffff,
852 6 };
853  
854  
855 # see: http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
856 # http://php.net/manual/en/language.operators.precedence.php
857 #
858 6 my %op_prio = (
859 '\\' => 0,
860 '->' => 1,
861 '::' => 1,
862 '+-' => 2, # sign
863 '$' => 2,
864 '++' => 2,
865 '--' => 2,
866 'new'=> 2, # unary
867 '**' => 3,
868 '!' => 4, # unary
869 '~' => 4, # unary
870 '*' => 5,
871 '/' => 5,
872 '%' => 5,
873 '+' => 6,
874 '-' => 6,
875 '.' => 6,
876 '<<' => 7,
877 '>>' => 7,
878 '<' => 8,
879 '>' => 8,
880 '<=' => 8,
881 '>=' => 8,
882 'lt' => 8, # (does not exist in php5-8)
883 'gt' => 8, # (does not exist in php5-8)
884 'le' => 8, # (does not exist in php5-8)
885 'ge' => 8, # (does not exist in php5-8)
886 '==' => 9,
887 '!=' => 9,
888 '<>' => 9, # diamond seems to work as != even if not documented
889 '===' => 9,
890 '!==' => 9,
891 '<=>' => 9, # spaceship since php7
892 'eq' => 9, # (does not exist in php5-8)
893 'ne' => 9, # (does not exist in php5-8)
894 '&' => 10,
895 '^' => 11,
896 '|' => 12,
897 '&&' => 13,
898 '||' => 14,
899 '??' => 15, # right since php7
900 ':' => 16, # right
901 '?' => 17, # right
902 '?:' => 17, # right
903 '=' => 18, # right
904 'not'=> 19, # right (does not exist in php5-8)
905 'and'=> 20,
906 'or' => 21,
907 'xor'=> 21,
908 'instanceof'=> 21,
909 '...'=> 22, # ellipses
910 );
911  
912 6 my %op_right = (
913 '**' => 1, # right associative
914 '->' => 1, # right associative
915 '::' => 1, # right associative
916 '??' => 1, # right associative
917 '$' => 1, # right associative
918 '=' => 1, # right associative
919 );
920  
921 6 my %op_unary = (
922 'new'=> 1, # unary
923 '!' => 1, # unary
924 '~' => 1, # unary
925 '?' => 1, # in ternary (dummy for op_prio)
926 ':' => 1, # in ternary (dummy for op_prio)
927 );
928  
929 # Variables, constants & function names: ^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$
930 # see: https://www.php.net/manual/en/language.variables.basics.php
931 # see: https://www.php.net/manual/en/language.constants.php
932 # see: https://www.php.net/manual/en/functions.user-defined.php
933 #
934 21476 ▶sub is_variable {
Subroutine is_variable: called CC=2 SCAR=6.9
Pod undocumented
935 21476 my ($s) = @_;
936  
937 # represent global vars as $GLOBALS$varname
938 # represent class vars as $classname$varname
939 # represent instance vars as $#instNNN$varname
940 # represent non symbol ${"xxx"} vars also as $#instNNN$varname
941 #
942 21476 ▶ if ($s =~/^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?(\$|[^\$]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?(\$|[^\$]*)$/) 7443 14033 21476
943 7443 return 1;
944 }
945 14033 return 0;
946 }
947  
948 10339 ▶sub is_strict_variable {
Subroutine is_strict_variable: called CC=2 SCAR=6.9
Pod undocumented
949 10339 my ($s) = @_;
950  
951 10339 ▶ if ($s =~/^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^\$(GLOBALS\$|#inst\d+\$|[\w\x80-\xff]+\$)?[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) 4442 5897 10339
952 4442 return 1;
953 }
954 5897 return 0;
955 }
956  
957 2086 ▶sub is_symbol {
Subroutine is_symbol: called CC=2 SCAR=6.9
Pod undocumented
958 2086 my ($s) = @_;
959  
960 2086 ▶ if ($s =~/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/) 1814 272 2086
961 1814 return 1;
962 }
963 272 return 0;
964 }
965  
966 17 ▶sub is_magic_const {
Subroutine is_magic_const: called CC=3 SCAR=11.0
Pod undocumented
967 17 my ($self, $s) = @_;
968  
969 17 ▶ if ($s =~ /^#const\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#const\d+$/) 17 0 17
970 17 ▶ if (exists $magic_constants{$self->{strmap}->{$s}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $magic_constants{$self->{"strmap"}{$s}}) 12 5 17
971 12 return $self->{strmap}->{$s};
972 }
973 }
974 5 return;
975 }
976  
977 # check if statement is empty block
978 #
979 148 ▶sub is_empty_block {
Subroutine is_empty_block: called CC=3 SCAR=11.0
Pod undocumented
980 148 my ($self, $s) = @_;
981  
982 148 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) 84 64 148
983 84 my ($type, $a) = @{$self->{strmap}->{$s}};
984 84 ▶ if (scalar @$a == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 0) 79 5 84
985 79 return 1;
986 }
987 }
988 69 return 0;
989 }
990  
991 # flatten block (and remove #null statements)
992 #
993 3793 ▶sub flatten_block {
Subroutine flatten_block: called CC=4 SCAR=13.9
Pod undocumented
994 3793 my ($self, $s, $out) = @_;
995  
996 3793 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) { } 694 3099 3793
997 694 my ($type, $a) = @{$self->{strmap}{$s}};
998 694 foreach my $stmt (@$a) {
999 876 $self->flatten_block($stmt, $out);
1000 }
1001 } else {
1002 3099 ▶ if ($s ne '#null') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne "#null") 2996 103 3099
1003 2996 push(@$out, $s);
1004 }
1005 }
1006 3793 return;
1007 }
1008  
1009 # flatten block with single statement
1010 #
1011 245 ▶sub flatten_block_if_single {
Subroutine flatten_block_if_single: called CC=3 SCAR=11.0
Pod undocumented
1012 245 my ($self, $s) = @_;
1013  
1014 245 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) 238 7 245
1015 238 my ($type, $a) = @{$self->{strmap}{$s}};
1016 238 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) 147 91 238
1017 147 return $a->[0];
1018 }
1019 }
1020 98 return $s;
1021 }
1022  
1023 # create and split global var
1024 #
1025 59 ▶sub global_var {
Subroutine global_var: called CC=1 SCAR=0.0
Pod undocumented
1026 59 my ($global) = @_;
1027 59 return '$GLOBALS' . $global;
1028 }
1029  
1030 6053 ▶sub global_split {
Subroutine global_split: called CC=1 SCAR=0.0
Pod undocumented
1031 6053 my ($var) = @_;
1032 6053 my ($global) = $var =~ /^\$GLOBALS(\$.*)$/;
1033 6053 return $global;
1034 }
1035  
1036 # create and split method name
1037 #
1038 354 ▶sub method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
1039 354 my ($class, $name) = @_;
1040 354 return $class . '::' . $name;
1041 }
1042  
1043 2080 ▶sub method_split {
Subroutine method_split: called CC=1 SCAR=0.0
Pod undocumented
1044 2080 my ($method) = @_;
1045 # allow namespace prefix
1046 2080 my ($class, $name) = $method =~ /^(#inst\d+|[\w\x80-\xff\\]+)::([\w\x80-\xff]+)$/;
1047 2080 return ($class, $name);
1048 }
1049  
1050 # create and split instance var
1051 #
1052 53 ▶sub inst_var {
Subroutine inst_var: called CC=1 SCAR=0.0
Pod undocumented
1053 53 my ($inst, $var) = @_;
1054 53 return '$' . $inst . $var;
1055 }
1056  
1057 7042 ▶sub inst_split {
Subroutine inst_split: called CC=1 SCAR=0.0
Pod undocumented
1058 7042 my ($instvar) = @_;
1059 7042 my ($inst, $var) = $instvar =~ /^\$(#inst\d+|[\w\x80-\xff]+)(\$.*)$/;
1060 7042 return ($inst, $var);
1061 }
1062  
1063 # create and split namespace name
1064 #
1065 31 ▶sub ns_name {
Subroutine ns_name: called CC=1 SCAR=0.0
Pod undocumented
1066 31 my ($name, $elem) = @_;
1067 31 return $name . '\\' . $elem;
1068 }
1069  
1070 0 ▶sub ns_split {
Subroutine ns_split: not called CC=1 SCAR=6.9
Pod undocumented
1071 0 my ($name) = @_;
1072 0 my ($ns, $elem) = $name =~ /^([^\\]*)\\(.+)$/;
1073 0 return ($ns, $elem);
1074 }
1075  
1076 # create path from namespace
1077 #
1078 14 ▶sub ns_to_str {
Subroutine ns_to_str: called CC=5 SCAR=16.1
Pod undocumented
1079 14 my ($self, $var) = @_;
1080  
1081 14 ▶ if ($var =~ /^#ns\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var =~ /^#ns\d+$/) { } 3 11 14
elsif (is_strval($var)) { } 8 3 11
1082 3 my ($n, $e) = @{$self->{strmap}{$var}};
1083  
1084 3 ▶ unless (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $n) 2 1 3
1085 2 $n = ''; # toplevel
1086 }
1087 3 $e = $self->ns_to_str($e);
1088 3 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 3 0 3
1089 3 return ns_name($n, $e);
1090 }
1091 } elsif (is_strval($var)) {
1092 8 return $self->{strmap}{$var};
1093 } else {
1094 3 return $var;
1095 }
1096 0 return;
1097 }
1098  
1099 # create variable from variable variable
1100 # $$var -> $val
1101 # ${$var} -> $val
1102 #
1103 90 ▶sub varvar_to_var {
Subroutine varvar_to_var: called CC=2 SCAR=6.9
Pod undocumented
1104 90 my ($self, $var) = @_;
1105  
1106 90 ▶ if (is_strval($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($var)) 79 11 90
1107 79 my $str = $self->{strmap}{$var};
1108  
1109 # variable names are only handled up to first '$'.
1110 # also 'null' is allowed (represented as '' or ${null})
1111 #
1112 79 my ($suffix) = $str =~ /^(\$$|[^\$]*)/;
1113 79 return '$' . $suffix;
1114 }
1115 11 return;
1116 }
1117  
1118 # $GLOBALS['str'] -> $str
1119 #
1120 604 ▶sub globalvar_to_var {
Subroutine globalvar_to_var: called CC=3 SCAR=11.0
Pod undocumented
1121 604 my ($self, $base, $idx) = @_;
1122  
1123 604 ▶ if ($base =~ /^\$GLOBALS$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base =~ /^\$GLOBALS$/) 124 480 604
1124 124 my $idxval = $self->get_strval($idx);
1125 124 ▶ if (defined $idxval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idxval) 123 1 124
1126 # variable names are only handled up to first '$'.
1127 # also 'null' is allowed (represented as '' or ${null})
1128 #
1129 123 my ($suffix) = $idxval =~ /^(\$$|[^\$]*)/;
1130 123 return '$' . $suffix;
1131 }
1132 }
1133 481 return;
1134 }
1135  
1136 # return base var of multi dimensional elem
1137 #
1138 363 ▶sub elem_base {
Subroutine elem_base: called CC=4 SCAR=13.9
Pod undocumented
1139 363 my ($self, $s) = @_;
1140  
1141 363 ▶ while ($s =~ /^#elem\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /^#elem\d+$/) 54 355 409
1142 54 my ($v, $i) = @{$self->{strmap}->{$s}};
1143  
1144 54 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 37 17 54
1145 # add resolvable globals
1146 #
1147 37 my $g = $self->globalvar_to_var($v, $i);
1148 37 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) 8 29 37
1149 8 $g = global_var($g);
1150 8 return $g;
1151 }
1152 }
1153 46 $s = $v;
1154 }
1155 355 return $s;
1156 }
1157  
1158 0 ▶sub getline {
Subroutine getline: not called CC=1 SCAR=6.9
Pod undocumented
1159 0 my ($self) = @_;
1160  
1161 #$self->{log}->('getline', "%d", $self->{strmap}->{'__LINE__'}) if $self->{log};
1162 0 return $self->{strmap}->{'__LINE__'};
1163 }
1164  
1165 1027 ▶sub updateline {
Subroutine updateline: called CC=4 SCAR=15.9
Pod undocumented
1166 1027 my ($self, $var) = @_;
1167  
1168 #$self->{log}->('updateline', "test $var") if $self->{log};
1169  
1170 # update line number based on preceeding string
1171 #
1172 1027 ▶ if (exists $self->{strmap}->{'__LINEMAP__'}{$var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{"__LINEMAP__"}{$var}) 1026 1 1027
1173 1026 my $val = $self->{strmap}->{'__LINEMAP__'}{$var};
1174 1026 ▶ if ($self->{strmap}->{'__LINE__'} < $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"strmap"}{"__LINE__"} < $val) 0 1026 1026
1175 0 ▶ $self->{log}->('updateline', "[$var] %d -> %d", $self->{strmap}->{'__LINE__'}, $val) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1176 0 $self->{strmap}->{'__LINE__'} = $val;
1177 }
1178 }
1179 1027 return;
1180 }
1181  
1182 0 ▶sub trim_list {
Subroutine trim_list: not called CC=5 SCAR=34.0
Pod undocumented
1183 0 my ($list) = @_;
1184  
1185 0 ▶ while ((scalar @$list > 0) && ($list->[0] =~ /^\s+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 0 and $list->[0] =~ /^\s+$/) 0 0 0
Condition0%0/3
scalar @$list > 0 and $list->[0] =~ /^\s+$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$list > 0 and $list->[0] =~ /^\s+$/
scalar @$list > 0 $list->[0] =~ /^\s+$/
Truth table0%0/3
A and B
A= scalar @$list > 0B= $list->[0] =~ /^\s+$/
ABresult
0X0
100
111
1186 0 shift @$list;
1187 }
1188 0 ▶ while ((scalar @$list > 0) && ($list->[-1] =~ /^\s+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 0 and $list->[-1] =~ /^\s+$/) 0 0 0
Condition0%0/3
scalar @$list > 0 and $list->[-1] =~ /^\s+$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$list > 0 and $list->[-1] =~ /^\s+$/
scalar @$list > 0 $list->[-1] =~ /^\s+$/
Truth table0%0/3
A and B
A= scalar @$list > 0B= $list->[-1] =~ /^\s+$/
ABresult
0X0
100
111
1189 0 pop @$list;
1190 }
1191 }
1192  
1193 785 ▶sub unspace_list {
Subroutine unspace_list: called CC=1 SCAR=0.0
Pod undocumented
1194 785 my ($list) = @_;
1195 # remove empty fields
1196 785 my @filtered = grep { $_ !~ /^\s+$/ } @$list;
1197  
1198 # remove comments
1199 785 @filtered = grep { $_ !~ /^\/\*.*\*\/$/ } @filtered;
1200  
1201 785 return \@filtered;
1202 }
1203  
1204 6083 ▶sub unquote_names {
Subroutine unquote_names: called CC=1 SCAR=0.1
Pod undocumented
1205 6083 my ($str) = @_;
1206  
1207 # todo: is this really needed?
1208 6083 if (1) {
1209 # \xXX
1210 6083 $str =~ s/\\x([0-9a-fA-F]{2})/chr(hex($1))/ge;
1211 }
1212 6083 return $str;
1213 }
1214  
1215 0 ▶sub dump_line {
Subroutine dump_line: not called CC=3 SCAR=24.8
Pod undocumented
1216 0 my ($self, $prefix, $tok) = @_;
1217  
1218 0 ▶ for (my $i=0; $i < scalar @$tok; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$tok) 0 0 0
1219 0 my $word = $tok->[$i];
1220  
1221 0 ▶ if ($word =~ /^#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^#/) { } 0 0 0
1222 0 my $s = $self->shortstr($self->{strmap}->{$word}, 100);
1223 0 print "$prefix> $word [$s]\n";
1224 } else {
1225 0 my $t = unquote_names($word);
1226 0 print "$prefix> $t [$word]\n";
1227 }
1228 }
1229 0 my $q = join('', @$tok);
1230 0 print "$prefix> SHORTQ: $q\n";
1231 0 return;
1232 }
1233  
1234 145 ▶sub read_array {
Subroutine read_array: called CC=21 SCAR=33.3
Pod undocumented
1235 145 my ($self, $tok, $close, $arr) = @_;
1236  
1237 145 while (1) {
1238 244 ▶ if (scalar @$tok == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok == 0) 0 244 244
1239 0 last;
1240 }
1241 244 ▶ if ($tok->[0] eq $close) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] eq $close) 25 219 244
1242 25 shift @$tok;
1243 25 last;
1244 }
1245 219 my $val = $self->read_statement($tok, undef);
1246 219 ▶ if (!defined $val || ($val eq $close)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq $close) 0 219 219
Condition33%1/3
not defined $val or $val eq $close
l!l&&r!l&&!r
00219
MC/DC0%0/2
not defined $val or $val eq $close
not defined $val $val eq $close
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq $close
ABresult
1X1
011
000
1247 0 last;
1248 }
1249 219 ▶ if ($val eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq ",") 1 218 219
1250 1 $arr->set(undef, undef);
1251 1 next; # allow empty fields for list()
1252 }
1253 218 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 218 0 218
1254 218 ▶ if ($tok->[0] eq $close) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tok->[0] eq $close) { } 103 115 218
elsif ($tok->[0] eq ',') { } 82 33 115
elsif ($tok->[0] eq '=>') { } 33 0 33
1255 103 shift @$tok;
1256 103 $arr->set(undef, $val);
1257 103 last;
1258 } elsif ($tok->[0] eq ',') {
1259 82 shift @$tok;
1260 82 $arr->set(undef, $val);
1261 82 next;
1262 } elsif ($tok->[0] eq '=>') {
1263 33 shift @$tok;
1264 33 my $key = $val;
1265 33 ▶ if ($key =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /^#expr\d+$/) { } 2 31 33
elsif (is_null($key)) { } 1 30 31
1266 2 my ($op, $v1, $v2) = @{$self->{strmap}->{$key}};
1267 2 ▶ if (($op eq '-') && !defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "-" and not defined $v1) 2 0 2
Condition33%1/3
$op eq "-" and not defined $v1
!ll&&!rl&&r
002
MC/DC0%0/2
$op eq "-" and not defined $v1
$op eq "-" not defined $v1
Truth table33%1/3
A and not(B)
A= $op eq "-"B= not defined $v1
ABresult
0X0
100
111
1268 2 my $str = $self->get_strval($v2);
1269 2 ▶ if (defined $str && is_int_index($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and is_int_index($str)) 2 0 2
Condition33%1/3
defined $str and is_int_index($str)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $str and is_int_index($str)
defined $str is_int_index($str)
Truth table33%1/3
A and B
A= defined $strB= is_int_index($str)
ABresult
0X0
100
111
1270 2 $key = -$str;
1271 }
1272 }
1273 } elsif (is_null($key)) {
1274 1 $key = $self->setstr(''); # null maps to '' array index
1275 }
1276 33 $val = $self->read_statement($tok, undef);
1277 33 ▶ if (!defined $val || ($val eq $close)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or $val eq $close) 0 33 33
Condition33%1/3
not defined $val or $val eq $close
l!l&&r!l&&!r
0033
MC/DC0%0/2
not defined $val or $val eq $close
not defined $val $val eq $close
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq $close
ABresult
1X1
011
000
1278 0 $arr->set($key, undef);
1279 0 last;
1280 }
1281 33 $arr->set($key, $val);
1282 33 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) { } 33 0 33
1283 33 ▶ if ($tok->[0] eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok->[0] eq $close) { } 17 16 33
elsif ($tok->[0] eq ',') { } 16 0 16
1284 17 shift @$tok;
1285 17 last;
1286 } elsif ($tok->[0] eq ',') {
1287 16 shift @$tok;
1288 16 next;
1289 }
1290 } else {
1291 0 last;
1292 }
1293 }
1294 }
1295 }
1296 145 return;
1297 }
1298  
1299 # last_op is optional param
1300 #
1301 13401 ▶sub _read_statement {
Subroutine _read_statement: called CC=387 SCAR=84.6
1302 13401 my ($self, $tok, $last_op) = @_;
1303  
1304 13401 ▶ if ((scalar @$tok > 0) && ($tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i)) {
Branch: 47 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i) { } 3389 10012 13401
elsif (scalar @$tok > 0 and $tok->[0] =~ /^null$/i) { } 16 9996 10012
elsif (scalar @$tok > 1 and $tok->[0] eq '{') { } 184 9812 9996
elsif (scalar @$tok > 1 and $tok->[0] eq '(') { } 60 9752 9812
elsif (scalar @$tok > 1 and $tok->[0] eq '[') { } 12 9740 9752
elsif (scalar @$tok > 1 and $tok->[0] eq '&') { } 8 9732 9740
elsif (scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ':' && $tok->[2] ne ':' and not exists $php_keywords{$tok->[0]}) { } 6083 3649 9732
elsif (scalar @$tok > 1 and $tok->[0] eq '<' and $tok->[1] eq '?') { } 0 3649 3649
elsif (scalar @$tok > 5 and $tok->[0] eq '<' and $tok->[1] eq 'script' and $tok->[2] eq 'type' and $tok->[3] eq '=' and $tok->[5] eq '>') { } 0 3649 3649
elsif (scalar @$tok > 1 and $tok->[0] eq '?' and $tok->[1] eq '>') { } 0 3649 3649
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'echo') { } 147 3502 3649
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'print') { } 0 3502 3502
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'namespace') { } 10 3492 3502
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'use') { } 0 3492 3492
elsif (scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i) { } 0 3492 3492
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'global') { } 6 3486 3492
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'return') { } 118 3368 3486
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'goto') { } 1 3367 3368
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'throw') { } 0 3367 3367
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'break') { } 2 3365 3367
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'continue') { } 0 3365 3365
elsif (scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/) { } 55 3310 3365
elsif (scalar @$tok > 0 and lc $tok->[0] eq '__halt_compiler') { } 0 3310 3310
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'if' and $tok->[1] eq '(') { } 124 3186 3310
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'switch' and $tok->[1] eq '(') { } 9 3177 3186
elsif (scalar @$tok > 2 and lc $tok->[0] eq 'case') { } 15 3162 3177
elsif (scalar @$tok > 1 and lc $tok->[0] eq 'default') { } 0 3162 3162
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'try' and $tok->[1] eq '{') { } 1 3161 3162
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'for' and $tok->[1] eq '(') { } 20 3141 3161
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'while' and $tok->[1] eq '(') { } 10 3131 3141
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'do' and $tok->[1] eq '{') { } 7 3124 3131
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'foreach' and $tok->[1] eq '(') { } 18 3106 3124
elsif (scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq '(') { } 133 2973 3106
elsif (scalar @$tok > 4 and lc $tok->[0] eq 'function' || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq 'function') { } 228 2745 2973
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'class' || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq 'class') { } 56 2689 2745
elsif (scalar @$tok > 3 and lc $tok->[0] eq 'trait') { } 1 2688 2689
elsif (scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/) { } 36 2652 2688
elsif (scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq '(') { } 721 1931 2652
elsif (scalar @$tok > 1 and $tok->[0] eq '$' and is_symbol($tok->[1])) { } 0 1931 1931
elsif (scalar @$tok > 1 and $tok->[0] eq '$' and $tok->[1] =~ /^\$/) { } 6 1925 1931
elsif (scalar @$tok > 3 and $tok->[0] eq '$' and $tok->[1] eq '{') { } 78 1847 1925
elsif (scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq '[' || $tok->[1] eq '{') { } 420 1427 1847
elsif (scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]) { } 12 1415 1427
elsif (scalar @$tok > 3 and $tok->[0] eq '.' and $tok->[1] eq '.' and $tok->[2] eq '.') { } 0 1415 1415
elsif (scalar @$tok > 1 and $tok->[0] =~ /^\\$/) { } 7 1408 1415
elsif (scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i) { } 66 1342 1408
elsif (scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i) { } 1329 13 1342
Condition66%2/3
scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i
!ll&&!rl&&r
0100123389
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i
scalar @$tok > 0 $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] =~ /^([\;\:\,\)\]\}]|else|endif|endwhile|endfor|endforeach|as|=>|catch|finally)$/i
ABresult
0X0
100
111
1305 3389 my $sym = shift @$tok;
1306 3389 return $sym;
1307 ▶ } elsif ((scalar @$tok > 0) && ($tok->[0] =~ /^null$/i)) {
Condition66%2/3
scalar @$tok > 0 and $tok->[0] =~ /^null$/i
!ll&&!rl&&r
0999616
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] =~ /^null$/i
scalar @$tok > 0 $tok->[0] =~ /^null$/i
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] =~ /^null$/i
ABresult
0X0
100
111
1308 16 shift @$tok;
1309 16 unshift(@$tok, '#null');
1310 16 my $res = $self->read_statement($tok, $last_op);
1311 16 return $res;
1312 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '{')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "{"
!ll&&!rl&&r
19997813184
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "{"
scalar @$tok > 1 $tok->[0] eq "{"
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "{"
ABresult
0X0
100
111
1313 # block expression { statement1; statement2; ... }
1314 # also allow empty { } block
1315 #
1316 184 shift @$tok;
1317 184 my $arglist = $self->read_code_block($tok, '}', ';');
1318 184 my $k = $self->setblk('std', $arglist);
1319 184 return $k;
1320 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '(')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "("
!ll&&!rl&&r
1999775360
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "("
scalar @$tok > 1 $tok->[0] eq "("
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "("
ABresult
0X0
100
111
1321 # brace expression ( expr | call ) => result
1322 # also: allow empty ( ) block
1323 # also: type casting (int|bool|float|array|object|unset)
1324 # http://php.net/manual/en/language.types.type-juggling.php
1325 #
1326 60 shift @$tok;
1327 60 my $arglist = $self->read_block($tok, ')', undef);
1328  
1329 60 ▶ if (scalar @$arglist > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist > 0) 60 0 60
1330 60 ▶ if (scalar @$arglist == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist == 1) 60 0 60
1331 60 my $ref = $arglist->[0];
1332 60 my $str = $self->get_strval_or_str($ref);
1333 #$self->{log}->('parse', "braces: $ref, $str") if $self->{log};
1334 60 ▶ if (is_strval($ref) && ($str =~ /^(int|bool|float|string|array|object|unset)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/) 2 58 60
Condition100%3/3
is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/
!ll&&!rl&&r
5712
MC/DC100%2/2
is_strval($ref) and $str =~ /^(int|bool|float|string|array|object|unset)$/
is_strval($ref) $str =~ /^(int|bool|float|string|array|object|unset)$/
Truth table100%3/3
A and B
A= is_strval($ref)B= $str =~ /^(int|bool|float|string|array|object|unset)$/
ABresult
0X0
100
111
1335 # type casting
1336 # https://www.php.net/manual/en/language.types.type-juggling.php
1337 # https://www.php.net/manual/en/function.settype.php
1338 #
1339 2 my $res = $self->read_statement($tok, $last_op);
1340 2 my $k;
1341 2 ▶ if ($str eq 'int') {
Branch: 12 branches
BranchTrueFalseTotal
if ($str eq 'int') { } 1 1 2
elsif ($str eq 'integer') { } 0 1 1
elsif ($str eq 'string') { } 1 0 1
elsif ($str eq 'binary') { } 0 0 0
elsif ($str eq 'float') { } 0 0 0
elsif ($str eq 'double') { } 0 0 0
elsif ($str eq 'real') { } 0 0 0
elsif ($str eq 'bool') { } 0 0 0
elsif ($str eq 'boolean') { } 0 0 0
elsif ($str eq 'array') { } 0 0 0
elsif ($str eq 'object') { } 0 0 0
elsif ($str eq 'unset') { } 0 0 0
1342 1 $k = $self->setcall('intval', [$res]);
1343 } elsif ($str eq 'integer') {
1344 0 $k = $self->setcall('intval', [$res]);
1345 } elsif ($str eq 'string') {
1346 1 $k = $self->setcall('strval', [$res]);
1347 } elsif ($str eq 'binary') {
1348 0 $k = $self->setcall('strval', [$res]);
1349 } elsif ($str eq 'float') {
1350 0 $k = $self->setcall('floatval', [$res]);
1351 } elsif ($str eq 'double') {
1352 0 $k = $self->setcall('floatval', [$res]);
1353 } elsif ($str eq 'real') { # removed in php8
1354 0 $k = $self->setcall('floatval', [$res]);
1355 } elsif ($str eq 'bool') {
1356 0 $k = $self->setcall('boolval', [$res]);
1357 } elsif ($str eq 'boolean') {
1358 0 $k = $self->setcall('boolval', [$res]);
1359 } elsif ($str eq 'array') {
1360 0 $k = $self->setcall('array', [$res]);
1361 } elsif ($str eq 'object') {
1362 0 $k = $self->setcall('object', [$res]);
1363 } elsif ($str eq 'unset') { # removed in php8
1364 0 my $t = $self->setstr('null');
1365 0 $k = $self->setcall('settype', [$res, $t]);
1366 } else {
1367 0 $k = $self->setcall('settype', [$res, $ref]);
1368 }
1369 2 unshift(@$tok, $k);
1370 2 $res = $self->read_statement($tok, $last_op);
1371 2 return $res;
1372 }
1373 58 ▶ if (is_strval($ref) || ($ref =~ /^#expr\d+$/) || ($ref =~ /^#call\d+$/) || ($ref =~ /^#inst\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/) 56 2 58
Condition88%8/9
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/
l!l&&r!l&&!r
5602
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/
l!l&&r!l&&!r
5062
is_strval($ref) or $ref =~ /^#expr\d+$/
l!l&&r!l&&!r
1498
MC/DC75%3/4
is_strval($ref) or $ref =~ /^#expr\d+$/ or $ref =~ /^#call\d+$/ or $ref =~ /^#inst\d+$/
is_strval($ref) $ref =~ /^#expr\d+$/ $ref =~ /^#call\d+$/ $ref =~ /^#inst\d+$/
Truth table80%4/5
A or B or C or D
A= is_strval($ref)B= $ref =~ /^#expr\d+$/C= $ref =~ /^#call\d+$/D= $ref =~ /^#inst\d+$/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1374 56 unshift(@$tok, $ref);
1375 56 my $res = $self->read_statement($tok, $last_op);
1376 56 return $res;
1377 }
1378 }
1379 2 my $res = $self->setblk('brace', $arglist);
1380  
1381 # - anonymous functions might be called directly -> '(function () { return 1; })()'
1382 # - also subexpressions might use braces -> '$x = ($y) ? 1 : 2'
1383 #
1384 2 unshift(@$tok, $res);
1385 2 $res = $self->read_statement($tok, $last_op);
1386 2 return $res;
1387 }
1388 0 my $res = $self->setblk('brace', []);
1389 0 return $res;
1390 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '[')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "["
!ll&&!rl&&r
1999774112
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "["
scalar @$tok > 1 $tok->[0] eq "["
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "["
ABresult
0X0
100
111
1391 # $array = ['a','b','c']
1392 #
1393 12 shift @$tok;
1394  
1395 12 my $arr = $self->newarr();
1396 12 $self->read_array($tok, ']', $arr);
1397  
1398 #my $arglist = $self->read_block($tok, ']', ',');
1399 #foreach my $val (@$arglist) {
1400 # $arr->set(undef, $val);
1401 #}
1402 12 unshift(@$tok, $arr->{name});
1403 12 my $res = $self->read_statement($tok, $last_op);
1404 12 return $res;
1405 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '&')) {
Condition100%3/3
scalar @$tok > 1 and $tok->[0] eq "&"
!ll&&!rl&&r
199977338
MC/DC100%2/2
scalar @$tok > 1 and $tok->[0] eq "&"
scalar @$tok > 1 $tok->[0] eq "&"
Truth table100%3/3
A and B
A= scalar @$tok > 1B= $tok->[0] eq "&"
ABresult
0X0
100
111
1406 # variable reference
1407 # & $var
1408 #
1409 8 shift @$tok;
1410  
1411 8 my $var = $self->read_statement($tok, undef);
1412 8 my $k = $self->setref($var);
1413 8 return $k;
1414 ▶ } elsif (((scalar @$tok == 1)
Condition94%17/18
scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ":" && $tok->[2] ne ":" and not exists $php_keywords{$tok->[0]}
!ll&&!rl&&r
364726083
scalar @$tok == 1 or scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ or scalar @$tok > 2 and $tok->[1] eq ":" and $tok->[2] ne ":"
l!l&&r!l&&!r
6053323647
scalar @$tok == 1 or scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/
l!l&&r!l&&!r
199940543679
scalar @$tok > 1 and $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/
!ll&&!rl&&r
036794054
scalar @$tok > 2 and $tok->[1] eq ":" and $tok->[2] ne ":"
!ll&&!rl&&r
36064132
scalar @$tok > 2 and $tok->[1] eq ":"
!ll&&!rl&&r
8359873
MC/DC85%6/7
scalar @$tok == 1 || scalar @$tok > 1 && $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ || scalar @$tok > 2 && $tok->[1] eq ":" && $tok->[2] ne ":" and not exists $php_keywords{$tok->[0]}
scalar @$tok == 1 scalar @$tok > 1 $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/ scalar @$tok > 2 $tok->[1] eq ":" $tok->[2] ne ":" not exists $php_keywords{$tok->[0]}
Truth table50%7/14
A or B and C or D and E and F and not(G)
A= scalar @$tok == 1B= scalar @$tok > 1C= $tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/D= scalar @$tok > 2E= $tok->[1] eq ":"F= $tok->[2] ne ":"G= not exists $php_keywords{$tok->[0]}
ABCDEFGresult
00X0XXX0
00X10XX0
00X110X0
0100XXX0
01010XX0
010110X0
1XXXXX00
011XXX00
00X11100
01011100
1XXXXX11
011XXX11
00X11111
01011111
1415 || ((scalar @$tok > 1) && ($tok->[1] =~ /^([\;\,\)\]\}]|as|=>)$/))
1416 || ((scalar @$tok > 2) && ($tok->[1] eq ':') && ($tok->[2] ne ':'))) && !exists $php_keywords{$tok->[0]}) {
1417 # variable dereference
1418 # #str/#num/#const
1419 # constant
1420 # __FILE__
1421 # __LINE__
1422 #
1423 6083 my $sym = shift @$tok;
1424 6083 my $var = unquote_names($sym);
1425  
1426 6083 ▶ if (is_strict_variable($var) || ($var =~ /^#/)) {
Branch: 6 branches
BranchTrueFalseTotal
if (is_strict_variable($var) or $var =~ /^#/) { } 5733 350 6083
elsif ($var =~ /^__FILE__$/) { } 0 350 350
elsif ($var =~ /^__LINE__$/) { } 0 350 350
elsif ($var =~ /^false$/i) { } 3 347 350
elsif ($var =~ /^true$/i) { } 3 344 347
elsif (is_symbol($var)) { } 344 0 344
Condition100%3/3
is_strict_variable($var) or $var =~ /^#/
l!l&&r!l&&!r
14314302350
MC/DC100%2/2
is_strict_variable($var) or $var =~ /^#/
is_strict_variable($var) $var =~ /^#/
Truth table100%3/3
A or B
A= is_strict_variable($var)B= $var =~ /^#/
ABresult
1X1
011
000
1427 5733 ▶ if ($var =~ /^#str/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^#str/) 1027 4706 5733
1428 1027 $self->updateline($var);
1429 }
1430 5733 return $var;
1431 } elsif ($var =~ /^__FILE__$/) {
1432 0 my $v = $self->{filename};
1433 0 my $k = $self->setstr($v);
1434 0 ▶ $self->{log}->('parse', "getfile: $k -> $v") if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1435 0 return $k;
1436 } elsif ($var =~ /^__LINE__$/) {
1437 0 my $k = $self->setnum($self->getline());
1438 0 ▶ $self->{log}->('parse', "getline: $k -> %d", $self->{strmap}->{$k}) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1439 0 return $k;
1440 } elsif ($var =~ /^false$/i) {
1441 3 return $self->setnum(0);
1442 } elsif ($var =~ /^true$/i) {
1443 3 return $self->setnum(1);
1444 } elsif (is_symbol($var)) {
1445 # constants are always global
1446 # (undefined constants are propagated to string in exec)
1447 #
1448 344 my $k = $self->setconst($var);
1449 344 ▶ if ((scalar @$tok > 1) && ($tok->[0] eq ':') && ($tok->[1] ne ':') && !defined $last_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op) 2 342 344
Condition77%7/9
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op
!ll&&!rl&&r
34202
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":"
!ll&&!rl&&r
34202
scalar @$tok > 1 and $tok->[0] eq ":"
!ll&&!rl&&r
270722
MC/DC50%2/4
scalar @$tok > 1 and $tok->[0] eq ":" and $tok->[1] ne ":" and not defined $last_op
scalar @$tok > 1 $tok->[0] eq ":" $tok->[1] ne ":" not defined $last_op
Truth table60%3/5
A and B and C and not(D)
A= scalar @$tok > 1B= $tok->[0] eq ":"C= $tok->[1] ne ":"D= not defined $last_op
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1450 2 shift @$tok;
1451 2 $k = $self->setstmt(['label', $k]); # goto label
1452 }
1453 344 return $k;
1454 }
1455 0 return $var;
1456 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '<') && ($tok->[1] eq '?')) {
Condition33%2/6
scalar @$tok > 1 and $tok->[0] eq "<" and $tok->[1] eq "?"
!ll&&!rl&&r
364900
scalar @$tok > 1 and $tok->[0] eq "<"
!ll&&!rl&&r
036490
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "<" and $tok->[1] eq "?"
scalar @$tok > 1 $tok->[0] eq "<" $tok->[1] eq "?"
Truth table25%1/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "<"C= $tok->[1] eq "?"
ABCresult
0XX0
10X0
1100
1111
1457 0 ▶ if ((scalar @$tok > 2) && ($tok->[2] eq 'php')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 2 and $tok->[2] eq 'php') { } 0 0 0
Condition0%0/3
scalar @$tok > 2 and $tok->[2] eq "php"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 2 and $tok->[2] eq "php"
scalar @$tok > 2 $tok->[2] eq "php"
Truth table0%0/3
A and B
A= scalar @$tok > 2B= $tok->[2] eq "php"
ABresult
0X0
100
111
1458 0 shift @$tok;
1459 0 shift @$tok;
1460 0 shift @$tok;
1461 0 return '<?php';
1462 } else {
1463 0 shift @$tok;
1464 0 shift @$tok;
1465 0 return '<?';
1466 }
1467 ▶ } elsif ((scalar @$tok > 5) && ($tok->[0] eq '<') && ($tok->[1] eq 'script') && ($tok->[2] eq 'type') && ($tok->[3] eq '=') && ($tok->[5] eq '>')) {
Condition40%6/15
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "=" and $tok->[5] eq ">"
!ll&&!rl&&r
364900
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "="
!ll&&!rl&&r
364900
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type"
!ll&&!rl&&r
364900
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script"
!ll&&!rl&&r
364900
scalar @$tok > 5 and $tok->[0] eq "<"
!ll&&!rl&&r
64930000
MC/DC0%0/6
scalar @$tok > 5 and $tok->[0] eq "<" and $tok->[1] eq "script" and $tok->[2] eq "type" and $tok->[3] eq "=" and $tok->[5] eq ">"
scalar @$tok > 5 $tok->[0] eq "<" $tok->[1] eq "script" $tok->[2] eq "type" $tok->[3] eq "=" $tok->[5] eq ">"
Truth table28%2/7
A and B and C and D and E and F
A= scalar @$tok > 5B= $tok->[0] eq "<"C= $tok->[1] eq "script"D= $tok->[2] eq "type"E= $tok->[3] eq "="F= $tok->[5] eq ">"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1468 # filter out bad javascript tags in scripts with no proper end-tag
1469 # (this avoids misinterpretations of javascript while(1)-loops)
1470 #
1471 0 my @list = ();
1472 0 push(@list, shift @$tok);
1473 0 push(@list, shift @$tok);
1474 0 push(@list, shift @$tok);
1475 0 push(@list, shift @$tok);
1476 0 push(@list, shift @$tok); # type
1477 0 push(@list, shift @$tok);
1478  
1479 0 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 0 0 0
1480 0 ▶ if ((scalar @$tok > 3) && ($tok->[0] eq '<') && ($tok->[1] eq '/') && ($tok->[2] eq 'script') && ($tok->[3] eq '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">") 0 0 0
Condition0%0/12
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/"
!ll&&!rl&&r
000
scalar @$tok > 3 and $tok->[0] eq "<"
!ll&&!rl&&r
000
MC/DC0%0/5
scalar @$tok > 3 and $tok->[0] eq "<" and $tok->[1] eq "/" and $tok->[2] eq "script" and $tok->[3] eq ">"
scalar @$tok > 3 $tok->[0] eq "<" $tok->[1] eq "/" $tok->[2] eq "script" $tok->[3] eq ">"
Truth table0%0/6
A and B and C and D and E
A= scalar @$tok > 3B= $tok->[0] eq "<"C= $tok->[1] eq "/"D= $tok->[2] eq "script"E= $tok->[3] eq ">"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1481 0 push(@list, shift @$tok);
1482 0 push(@list, shift @$tok);
1483 0 push(@list, shift @$tok);
1484 0 push(@list, shift @$tok);
1485 0 last;
1486 }
1487 0 my $sym = shift @$tok;
1488 0 push(@list, $sym);
1489 }
1490 0 my $script = join(' ', @list);
1491 0 my $s = $self->setstr($script);
1492 0 my $k = $self->setstmt(['echo', [$s]]);
1493 0 ▶ $self->{log}->('parse', "javascript string: %s", $script) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
1494 0 return $k;
1495 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '?') && ($tok->[1] eq '>')) {
Condition33%2/6
scalar @$tok > 1 and $tok->[0] eq "?" and $tok->[1] eq ">"
!ll&&!rl&&r
364900
scalar @$tok > 1 and $tok->[0] eq "?"
!ll&&!rl&&r
036490
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "?" and $tok->[1] eq ">"
scalar @$tok > 1 $tok->[0] eq "?" $tok->[1] eq ">"
Truth table25%1/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "?"C= $tok->[1] eq ">"
ABCresult
0XX0
10X0
1100
1111
1496 0 shift @$tok;
1497 0 shift @$tok;
1498 0 return '?>';
1499 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'echo')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "echo"
!ll&&!rl&&r
03502147
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "echo"
scalar @$tok > 1 lc $tok->[0] eq "echo"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "echo"
ABresult
0X0
100
111
1500 147 shift @$tok;
1501 147 my $all_str = 1;
1502 147 my @args = ();
1503 147 while (1) {
1504 156 my $arg = $self->read_statement($tok, undef);
1505  
1506 156 ▶ unless (is_strval($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_strval($arg)) 64 92 156
1507 64 $all_str = 0;
1508 }
1509 156 ▶ if ($arg ne ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne ",") 156 0 156
1510 156 push(@args, $arg);
1511 }
1512 156 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 147 9 156
Condition100%3/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
91389
MC/DC100%2/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table100%3/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1513 147 last;
1514 }
1515 9 shift @$tok;
1516 }
1517 147 my $k = $self->setstmt(['echo', \@args]);
1518  
1519 # execute expr & might continue with operation
1520 #
1521 147 unshift(@$tok, $k);
1522 147 return $self->read_statement($tok, $last_op);
1523 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'print')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "print"
!ll&&!rl&&r
035020
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "print"
scalar @$tok > 1 lc $tok->[0] eq "print"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "print"
ABresult
0X0
100
111
1524 0 shift @$tok;
1525 0 my $arg = $self->read_statement($tok, undef);
1526 0 my $k = $self->setstmt(['print', $arg]);
1527  
1528 # execute expr & might continue with operation
1529 #
1530 0 unshift(@$tok, $k);
1531 0 return $self->read_statement($tok, $last_op);
1532 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'namespace')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "namespace"
!ll&&!rl&&r
0349210
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "namespace"
scalar @$tok > 1 lc $tok->[0] eq "namespace"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "namespace"
ABresult
0X0
100
111
1533 10 shift @$tok;
1534  
1535 10 my $arg = ''; # toplevel
1536 10 ▶ if ($tok->[0] ne '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] ne "{") 9 1 10
1537 9 $arg = $self->read_statement($tok, undef);
1538 9 my $str = $self->ns_to_str($arg);
1539 9 ▶ if (defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str) { } 9 0 9
1540 9 $arg = $str;
1541 } else {
1542 0 $self->{warn}->('parse', "bad namespace: %s", $arg);
1543 }
1544 }
1545 10 my $block;
1546 10 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 2 8 10
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
082
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1547 2 shift @$tok;
1548 2 my $arglist = $self->read_code_block($tok, '}', ';');
1549 2 $block = $self->setblk('std', $arglist);
1550 }
1551 10 return $self->setstmt(['namespace', $arg, $block]);
1552 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'use')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "use"
!ll&&!rl&&r
034920
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "use"
scalar @$tok > 1 lc $tok->[0] eq "use"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "use"
ABresult
0X0
100
111
1553 0 shift @$tok;
1554 # https://php.net/manual/en/language.oop5.traits.php
1555 0 my @args = ();
1556 0 while (1) {
1557 0 my $arg = $self->read_statement($tok, undef);
1558  
1559 0 push(@args, $arg);
1560 0 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1561 0 last;
1562 }
1563 0 shift @$tok;
1564 }
1565 0 return $self->setstmt(['use', \@args]);
1566 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^(include|include_once|require|require_once)$/i)) {
Condition33%1/3
scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i
!ll&&!rl&&r
034920
MC/DC0%0/2
scalar @$tok > 1 and $tok->[0] =~ /^(include|include_once|require|require_once)$/i
scalar @$tok > 1 $tok->[0] =~ /^(include|include_once|require|require_once)$/i
Truth table33%1/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^(include|include_once|require|require_once)$/i
ABresult
0X0
100
111
1567 0 my $type = lc(shift @$tok);
1568 0 my $arg = $self->read_statement($tok, undef);
1569 0 return $self->setstmt([$type, $arg]);
1570 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'global')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "global"
!ll&&!rl&&r
034866
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "global"
scalar @$tok > 1 lc $tok->[0] eq "global"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "global"
ABresult
0X0
100
111
1571 6 shift @$tok;
1572 6 my @args = ();
1573 6 while (1) {
1574 6 my $arg = $self->read_statement($tok, undef);
1575  
1576 6 push(@args, $arg);
1577 6 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 6 0 6
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
060
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
1578 6 last;
1579 }
1580 0 shift @$tok;
1581 }
1582 6 return $self->setstmt(['global', \@args]);
1583 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'return')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "return"
!ll&&!rl&&r
03368118
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "return"
scalar @$tok > 1 lc $tok->[0] eq "return"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "return"
ABresult
0X0
100
111
1584 118 shift @$tok;
1585 118 my $res = $self->read_statement($tok, undef);
1586 # remove trailing ';' if evaluated as string
1587 #
1588 118 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 99 19 118
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
01999
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1589 99 shift @$tok;
1590 }
1591 118 return $self->setstmt(['return', $res]);
1592 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'goto')) {
Condition66%2/3
scalar @$tok > 1 and lc $tok->[0] eq "goto"
!ll&&!rl&&r
033671
MC/DC50%1/2
scalar @$tok > 1 and lc $tok->[0] eq "goto"
scalar @$tok > 1 lc $tok->[0] eq "goto"
Truth table66%2/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "goto"
ABresult
0X0
100
111
1593 1 shift @$tok;
1594 1 my $res = $self->read_statement($tok, undef);
1595 # remove trailing ';' if evaluated as string
1596 #
1597 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1598 1 shift @$tok;
1599 }
1600 1 return $self->setstmt(['goto', $res]);
1601 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'throw')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "throw"
!ll&&!rl&&r
033670
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "throw"
scalar @$tok > 1 lc $tok->[0] eq "throw"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "throw"
ABresult
0X0
100
111
1602 0 shift @$tok;
1603 0 my $arg = $self->read_statement($tok, undef);
1604 0 return $self->setstmt(['throw', $arg]);
1605 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'break')) {
Condition66%2/3
scalar @$tok > 0 and lc $tok->[0] eq "break"
!ll&&!rl&&r
033652
MC/DC50%1/2
scalar @$tok > 0 and lc $tok->[0] eq "break"
scalar @$tok > 0 lc $tok->[0] eq "break"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "break"
ABresult
0X0
100
111
1606 2 shift @$tok;
1607 2 my $res = $self->read_statement($tok, undef); # optional level
1608 2 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 2 2
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
020
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1609 0 shift @$tok;
1610 }
1611 2 return $self->setstmt(['break', $res]);
1612 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'continue')) {
Condition33%1/3
scalar @$tok > 0 and lc $tok->[0] eq "continue"
!ll&&!rl&&r
033650
MC/DC0%0/2
scalar @$tok > 0 and lc $tok->[0] eq "continue"
scalar @$tok > 0 lc $tok->[0] eq "continue"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "continue"
ABresult
0X0
100
111
1613 0 shift @$tok;
1614 0 my $res = $self->read_statement($tok, undef); # optional level
1615 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1616 0 shift @$tok;
1617 }
1618 0 return $self->setstmt(['continue', $res]);
1619 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/)) {
Condition66%2/3
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
!ll&&!rl&&r
0331055
MC/DC50%1/2
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
scalar @$tok > 0 lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
ABresult
0X0
100
111
1620 55 my $type = shift @$tok;
1621 55 my $pfx = {$type => 1};
1622  
1623 55 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/) 7 48 55
Condition66%2/3
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
!ll&&!rl&&r
0487
MC/DC50%1/2
scalar @$tok > 0 and lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
scalar @$tok > 0 lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
Truth table66%2/3
A and B
A= scalar @$tok > 0B= lc($tok->[0]) =~ /^(var|static|public|protected|private|final|const)$/
ABresult
0X0
100
111
1624 7 $type = shift @$tok;
1625 7 $pfx->{$type} = 1;
1626 }
1627 55 my $k = $self->setpfx($pfx);
1628 55 unshift(@$tok, $k);
1629 55 return $self->read_statement($tok);
1630 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq '__halt_compiler')) {
Condition33%1/3
scalar @$tok > 0 and lc $tok->[0] eq "__halt_compiler"
!ll&&!rl&&r
033100
MC/DC0%0/2
scalar @$tok > 0 and lc $tok->[0] eq "__halt_compiler"
scalar @$tok > 0 lc $tok->[0] eq "__halt_compiler"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "__halt_compiler"
ABresult
0X0
100
111
1631 0 my $k = shift @$tok;
1632 0 @$tok = ();
1633 0 return $k;
1634 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'if') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "if" and $tok->[1] eq "("
!ll&&!rl&&r
31860124
scalar @$tok > 3 and lc $tok->[0] eq "if"
!ll&&!rl&&r
973089124
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "if" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "if" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "if"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1635 124 shift @$tok;
1636 124 shift @$tok;
1637 124 my $expr = $self->read_block($tok, ')', undef);
1638 124 my $then;
1639 my $else;
1640  
1641 124 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 1 123 124
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
01231
MC/DC50%1/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1642 # allow alternative block syntax
1643 # http://php.net/manual/en/control-structures.alternative-syntax.php
1644 #
1645 1 shift @$tok;
1646 1 my $block = $self->read_code_block($tok, 'endif', ';');
1647 1 $then = $self->setblk('std', $block);
1648 } else {
1649 123 $then = $self->read_statement($tok);
1650 123 ▶ if (!is_block($then)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($then)) 16 107 123
1651 16 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 16 16
Condition66%2/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
1150
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table66%2/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1652 0 shift @$tok;
1653 }
1654 # always put '{ .. }' braces around if/else
1655 16 $then = $self->setblk('std', [$then]);
1656 }
1657 }
1658 124 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) eq 'else')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc $tok->[0] eq 'else') { } 17 107 124
elsif (scalar @$tok > 0 and lc $tok->[0] eq 'elseif') { } 6 169 175
Condition100%3/3
scalar @$tok > 0 and lc $tok->[0] eq "else"
!ll&&!rl&&r
683917
MC/DC100%2/2
scalar @$tok > 0 and lc $tok->[0] eq "else"
scalar @$tok > 0 lc $tok->[0] eq "else"
Truth table100%3/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "else"
ABresult
0X0
100
111
1659 17 shift @$tok;
1660 17 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 0 17 17
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0170
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1661 # allow alternative block syntax
1662 # http://php.net/manual/en/control-structures.alternative-syntax.php
1663 #
1664 0 shift @$tok;
1665 0 my $block = $self->read_code_block($tok, 'endif', ';');
1666 0 $else = $self->setblk('std', $block);
1667 } else {
1668 17 $else = $self->read_statement($tok);
1669 17 ▶ if (!is_block($else)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($else)) 1 16 17
1670 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1671 1 shift @$tok;
1672 }
1673 1 $else = $self->setblk('std', [$else]);
1674 }
1675 }
1676 ▶ } elsif ((scalar @$tok > 0) && (lc($tok->[0]) eq 'elseif')) {
Condition100%3/3
scalar @$tok > 0 and lc $tok->[0] eq "elseif"
!ll&&!rl&&r
68336
MC/DC100%2/2
scalar @$tok > 0 and lc $tok->[0] eq "elseif"
scalar @$tok > 0 lc $tok->[0] eq "elseif"
Truth table100%3/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "elseif"
ABresult
0X0
100
111
1677 6 shift @$tok;
1678 6 unshift(@$tok, 'if');
1679 6 $else = $self->read_statement($tok, undef);
1680 6 ▶ if (!is_block($else)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($else)) 6 0 6
1681 6 $else = $self->setblk('std', [$else]);
1682 }
1683 }
1684 124 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 124 124
1685 0 $self->{warn}->('parse', "if: bad cond %s", join(' ', @$expr));
1686 0 my $badcond = $self->setblk('expr', $expr);
1687 0 $expr = [$badcond];
1688 }
1689 124 return $self->setstmt(['if', $expr->[0], $then, $else]);
1690 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'switch') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "switch" and $tok->[1] eq "("
!ll&&!rl&&r
317709
scalar @$tok > 3 and lc $tok->[0] eq "switch"
!ll&&!rl&&r
9730809
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "switch" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "switch" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "switch"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1691 9 shift @$tok;
1692 9 shift @$tok;
1693 9 my $expr = $self->read_block($tok, ')', undef);
1694 9 my $block = [];
1695 9 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 0 9 9
elsif (scalar @$tok > 0 and $tok->[0] eq '{') { } 9 0 9
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
090
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1696 # allow alternative block syntax
1697 # http://php.net/manual/en/control-structures.alternative-syntax.php
1698 #
1699 0 shift @$tok;
1700 0 $block = $self->read_code_block($tok, 'endswitch', ';');
1701 ▶ } elsif ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
009
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1702 9 shift @$tok;
1703 9 $block = $self->read_code_block($tok, '}', ';');
1704 } else {
1705 0 $self->{warn}->('parse', "expected switch block {}");
1706 }
1707 9 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 9 9
1708 0 $self->{warn}->('parse', "switch: bad cond %s", join(' ', @$expr));
1709 0 my $badcond = $self->setblk('expr', $expr);
1710 0 $expr = [$badcond];
1711 }
1712 9 my @cases = ();
1713 9 my $inst;
1714 9 foreach my $e (@$block) {
1715 29 ▶ if ($e =~ /^#stmt\d+$/ && (lc($self->{strmap}->{$e}->[0]) eq 'case')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /^#stmt\d+$/ and lc $self->{'strmap'}{$e}[0] eq 'case') { } 15 14 29
Condition100%3/3
$e =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$e}[0] eq "case"
!ll&&!rl&&r
13115
MC/DC100%2/2
$e =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$e}[0] eq "case"
$e =~ /^#stmt\d+$/ lc $self->{"strmap"}{$e}[0] eq "case"
Truth table100%3/3
A and B
A= $e =~ /^#stmt\d+$/B= lc $self->{"strmap"}{$e}[0] eq "case"
ABresult
0X0
100
111
1716 15 my $c = $self->{strmap}->{$e}->[1]; # undef for default case
1717 15 $inst = [];
1718 15 my $b = $self->setblk('case', $inst); # block content added in next iterations
1719 15 push (@cases, [$c, $b]);
1720 } else {
1721 14 ▶ if (!defined $inst) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inst) 0 14 14
1722 0 $self->{warn}->('parse', "switch: inst w/o case: %s", $e);
1723 0 $inst = [];
1724 }
1725 14 push (@$inst, $e);
1726 }
1727 }
1728 9 return $self->setstmt(['switch', $expr->[0], \@cases]);
1729 ▶ } elsif ((scalar @$tok > 2) && (lc($tok->[0]) eq 'case')) {
Condition100%3/3
scalar @$tok > 2 and lc $tok->[0] eq "case"
!ll&&!rl&&r
4315815
MC/DC100%2/2
scalar @$tok > 2 and lc $tok->[0] eq "case"
scalar @$tok > 2 lc $tok->[0] eq "case"
Truth table100%3/3
A and B
A= scalar @$tok > 2B= lc $tok->[0] eq "case"
ABresult
0X0
100
111
1730 15 shift @$tok;
1731 15 my $expr = $self->read_statement($tok, undef);
1732 # 'case' might also be terminated by ';'
1733 #
1734 15 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':') || ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";") 14 1 15
Condition66%4/6
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
l!l&&r!l&&!r
1401
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0114
MC/DC33%1/3
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ":" $tok->[0] eq ";"
Truth table40%2/5
A and B or C
A= scalar @$tok > 0B= $tok->[0] eq ":"C= $tok->[0] eq ";"
ABCresult
11X1
0X11
1011
0X00
1000
1735 14 shift @$tok;
1736 }
1737 15 ▶ if ($expr =~ /^#stmt\d+$/ && (lc($self->{strmap}->{$expr}->[0]) eq 'label')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label") 1 14 15
Condition66%2/3
$expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label"
!ll&&!rl&&r
1401
MC/DC50%1/2
$expr =~ /^#stmt\d+$/ and lc $self->{"strmap"}{$expr}[0] eq "label"
$expr =~ /^#stmt\d+$/ lc $self->{"strmap"}{$expr}[0] eq "label"
Truth table66%2/3
A and B
A= $expr =~ /^#stmt\d+$/B= lc $self->{"strmap"}{$expr}[0] eq "label"
ABresult
0X0
100
111
1738 1 $expr = $self->{strmap}->{$expr}->[1]; # label -> const
1739 }
1740 15 return $self->setstmt(['case', $expr]);
1741 ▶ } elsif ((scalar @$tok > 1) && (lc($tok->[0]) eq 'default')) {
Condition33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "default"
!ll&&!rl&&r
031620
MC/DC0%0/2
scalar @$tok > 1 and lc $tok->[0] eq "default"
scalar @$tok > 1 lc $tok->[0] eq "default"
Truth table33%1/3
A and B
A= scalar @$tok > 1B= lc $tok->[0] eq "default"
ABresult
0X0
100
111
1742 0 shift @$tok;
1743 # 'case' might also be terminated by ';'
1744 #
1745 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':') || ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";") 0 0 0
Condition0%0/6
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
l!l&&r!l&&!r
000
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @$tok > 0 and $tok->[0] eq ":" or $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ":" $tok->[0] eq ";"
Truth table0%0/5
A and B or C
A= scalar @$tok > 0B= $tok->[0] eq ":"C= $tok->[0] eq ";"
ABCresult
11X1
0X11
1011
0X00
1000
1746 0 shift @$tok;
1747 }
1748 0 return $self->setstmt(['case', undef]);
1749 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'try') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "try" and $tok->[1] eq "{"
!ll&&!rl&&r
316101
scalar @$tok > 3 and lc $tok->[0] eq "try"
!ll&&!rl&&r
9730641
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "try" and $tok->[1] eq "{"
scalar @$tok > 3 lc $tok->[0] eq "try" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "try"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
1750 1 shift @$tok;
1751 1 my $try;
1752 my $finally;
1753  
1754 # https://www.php.net/manual/en/language.exceptions.php
1755 #
1756 1 $try = $self->read_statement($tok);
1757 1 ▶ if (!is_block($try)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($try)) 0 1 1
1758 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1759 0 shift @$tok;
1760 }
1761 # always put '{ .. }' braces around try
1762 0 $try = $self->setblk('std', [$try]);
1763 }
1764 1 my @catches = ();
1765 1 ▶ while ((scalar @$tok > 1) && (lc($tok->[0]) eq 'catch') && ($tok->[1] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "(") 1 1 2
Condition66%4/6
scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "("
!ll&&!rl&&r
101
scalar @$tok > 1 and lc $tok->[0] eq "catch"
!ll&&!rl&&r
011
MC/DC33%1/3
scalar @$tok > 1 and lc $tok->[0] eq "catch" and $tok->[1] eq "("
scalar @$tok > 1 lc $tok->[0] eq "catch" $tok->[1] eq "("
Truth table50%2/4
A and B and C
A= scalar @$tok > 1B= lc $tok->[0] eq "catch"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1766 1 shift @$tok;
1767 1 shift @$tok;
1768 1 my $exception = $self->read_block($tok, ')', undef);
1769 1 my $block= $self->read_statement($tok);
1770  
1771 1 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 1 1
1772 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1773 0 shift @$tok;
1774 }
1775 # always put '{ .. }' braces around catch
1776 0 $block = $self->setblk('std', [$block]);
1777 }
1778 1 push (@catches, [$exception->[0], $block]);
1779 }
1780 1 ▶ if ((scalar @$tok > 0) && (lc($tok->[0]) eq 'finally')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and lc $tok->[0] eq "finally") 1 0 1
Condition33%1/3
scalar @$tok > 0 and lc $tok->[0] eq "finally"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and lc $tok->[0] eq "finally"
scalar @$tok > 0 lc $tok->[0] eq "finally"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= lc $tok->[0] eq "finally"
ABresult
0X0
100
111
1781 1 shift @$tok;
1782 1 $finally= $self->read_statement($tok);
1783  
1784 1 ▶ if (!is_block($finally)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($finally)) 0 1 1
1785 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1786 0 shift @$tok;
1787 }
1788 # always put '{ .. }' braces around finally
1789 0 $finally = $self->setblk('std', [$finally]);
1790 }
1791 }
1792 1 return $self->setstmt(['try', $try, \@catches, $finally]);
1793 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'for') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "for" and $tok->[1] eq "("
!ll&&!rl&&r
3141020
scalar @$tok > 3 and lc $tok->[0] eq "for"
!ll&&!rl&&r
97304420
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "for" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "for" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "for"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1794 # note: just for-loops can take ',' operators in pre- and post-cond.
1795 # All 3 expressions can be empty;
1796 # http://php.net/manual/en/control-structures.for.php
1797 #
1798 20 shift @$tok;
1799 20 shift @$tok;
1800 20 my $expr1 = $self->read_code_block($tok, ';', ',');
1801 20 my $expr2 = $self->read_code_block($tok, ';', ',');
1802 20 my $expr3 = $self->read_code_block($tok, ')', ',');
1803 20 my $block;
1804 20 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 0 20 20
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0200
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1805 # allow alternative block syntax
1806 # http://php.net/manual/en/control-structures.alternative-syntax.php
1807 #
1808 0 shift @$tok;
1809 0 $block = $self->read_code_block($tok, 'endfor', ';');
1810 0 $block = $self->setblk('std', $block);
1811 } else {
1812 20 $block = $self->read_statement($tok);
1813 20 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 20 20
1814 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1815 0 shift @$tok;
1816 }
1817 # always put '{ .. }' braces around if/else
1818 0 $block = $self->setblk('std', [$block]);
1819 }
1820 }
1821 20 my $pre = $self->setblk('expr', $expr1);
1822 20 my $cond = $self->setblk('expr', $expr2);
1823 20 my $post = $self->setblk('expr', $expr3);
1824 20 return $self->setstmt(['for', $pre, $cond, $post, $block]);
1825 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'while') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
!ll&&!rl&&r
3131010
scalar @$tok > 3 and lc $tok->[0] eq "while"
!ll&&!rl&&r
97303410
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "while" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "while"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1826 10 shift @$tok;
1827 10 shift @$tok;
1828 10 my $expr = $self->read_block($tok, ')', ',');
1829 10 my $block;
1830 10 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 0 10 10
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0100
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1831 # allow alternative block syntax
1832 # http://php.net/manual/en/control-structures.alternative-syntax.php
1833 #
1834 0 shift @$tok;
1835 0 $block = $self->read_code_block($tok, 'endwhile', ';');
1836 0 $block = $self->setblk('std', $block);
1837 } else {
1838 10 $block = $self->read_statement($tok);
1839 10 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 1 9 10
1840 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1841 1 shift @$tok;
1842 }
1843 # always put '{ .. }' braces around if/else
1844 1 $block = $self->setblk('std', [$block]);
1845 }
1846 }
1847 10 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 10 10
1848 0 $self->{warn}->('parse', "while: bad cond %s", join(' ', @$expr));
1849 0 my $badcond = $self->setblk('expr', $expr);
1850 0 $expr = [$badcond];
1851 }
1852 10 return $self->setstmt(['while', $expr->[0], $block]);
1853 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'do') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "do" and $tok->[1] eq "{"
!ll&&!rl&&r
312407
scalar @$tok > 3 and lc $tok->[0] eq "do"
!ll&&!rl&&r
9730277
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "do" and $tok->[1] eq "{"
scalar @$tok > 3 lc $tok->[0] eq "do" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "do"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
1854 7 shift @$tok;
1855 7 my $block;
1856 my $expr;
1857  
1858 7 $block = $self->read_statement($tok);
1859 7 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 0 7 7
1860 0 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 0 0 0
Condition0%0/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table0%0/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1861 0 shift @$tok;
1862 }
1863 # always put '{ .. }' braces around do-while block
1864 0 $block = $self->setblk('std', [$block]);
1865 }
1866 7 ▶ if ((scalar @$tok > 3) && (lc($tok->[0]) eq 'while') && ($tok->[1] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 3 and lc $tok->[0] eq 'while' and $tok->[1] eq '(') { } 7 0 7
Condition33%2/6
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
!ll&&!rl&&r
007
scalar @$tok > 3 and lc $tok->[0] eq "while"
!ll&&!rl&&r
007
MC/DC0%0/3
scalar @$tok > 3 and lc $tok->[0] eq "while" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "while" $tok->[1] eq "("
Truth table25%1/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "while"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1867 7 shift @$tok;
1868 7 shift @$tok;
1869 7 $expr = $self->read_block($tok, ')', ',');
1870  
1871 7 ▶ if (scalar @$expr > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$expr > 1) 0 7 7
1872 0 $self->{warn}->('parse', "do-while: bad cond %s", join(' ', @$expr));
1873 0 my $badcond = $self->setblk('expr', $expr);
1874 0 $expr = [$badcond];
1875 }
1876 } else {
1877 0 $self->{warn}->('parse', "do-while: miss while");
1878 0 my $badcond = $self->setblk('expr', undef);
1879 0 $expr = [$badcond];
1880 }
1881 7 return $self->setstmt(['do', $expr->[0], $block]);
1882 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'foreach') && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 3 and lc $tok->[0] eq "foreach" and $tok->[1] eq "("
!ll&&!rl&&r
3106018
scalar @$tok > 3 and lc $tok->[0] eq "foreach"
!ll&&!rl&&r
97300918
MC/DC66%2/3
scalar @$tok > 3 and lc $tok->[0] eq "foreach" and $tok->[1] eq "("
scalar @$tok > 3 lc $tok->[0] eq "foreach" $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= lc $tok->[0] eq "foreach"C= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1883 18 shift @$tok;
1884 18 shift @$tok;
1885 18 my $expr = $self->read_block($tok, ')', ',');
1886 18 my $key;
1887 my $value;
1888  
1889 18 ▶ if ((scalar @$expr == 3) && (lc($expr->[1]) eq 'as')) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$expr == 3 and lc $expr->[1] eq 'as') { } 6 12 18
elsif (scalar @$expr == 5 and lc $expr->[1] eq 'as' and $expr->[3] eq '=>') { } 12 0 12
Condition66%2/3
scalar @$expr == 3 and lc $expr->[1] eq "as"
!ll&&!rl&&r
1206
MC/DC50%1/2
scalar @$expr == 3 and lc $expr->[1] eq "as"
scalar @$expr == 3 lc $expr->[1] eq "as"
Truth table66%2/3
A and B
A= scalar @$expr == 3B= lc $expr->[1] eq "as"
ABresult
0X0
100
111
1890 6 $value = $expr->[2];
1891 ▶ } elsif ((scalar @$expr == 5) && (lc($expr->[1]) eq 'as') && ($expr->[3] eq '=>')) {
Condition33%2/6
scalar @$expr == 5 and lc $expr->[1] eq "as" and $expr->[3] eq "=>"
!ll&&!rl&&r
0012
scalar @$expr == 5 and lc $expr->[1] eq "as"
!ll&&!rl&&r
0012
MC/DC0%0/3
scalar @$expr == 5 and lc $expr->[1] eq "as" and $expr->[3] eq "=>"
scalar @$expr == 5 lc $expr->[1] eq "as" $expr->[3] eq "=>"
Truth table25%1/4
A and B and C
A= scalar @$expr == 5B= lc $expr->[1] eq "as"C= $expr->[3] eq "=>"
ABCresult
0XX0
10X0
1100
1111
1892 12 $key = $expr->[2];
1893 12 $value = $expr->[4];
1894 } else {
1895 0 $self->{warn}->('parse', "foreach: bad expr %s", join(' ', @$expr));
1896 0 my $badcond = $self->setblk('expr', $expr);
1897 0 $expr = [$badcond];
1898 }
1899 18 my $block;
1900 18 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 0 18 18
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0180
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
1901 # allow alternative block syntax
1902 # http://php.net/manual/en/control-structures.alternative-syntax.php
1903 #
1904 0 shift @$tok;
1905 0 $block = $self->read_code_block($tok, 'endforeach', ';');
1906 0 $block = $self->setblk('std', $block);
1907 } else {
1908 18 $block = $self->read_statement($tok);
1909 18 ▶ if (!is_block($block)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_block($block)) 1 17 18
1910 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ";") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ";"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ";"
scalar @$tok > 0 $tok->[0] eq ";"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ";"
ABresult
0X0
100
111
1911 1 shift @$tok;
1912 }
1913 # always put '{ .. }' braces around if/else
1914 1 $block = $self->setblk('std', [$block]);
1915 }
1916 }
1917 18 return $self->setstmt(['foreach', $expr->[0], $key, $value, $block]);
1918 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] =~ /^array$/i) && ($tok->[1] eq '(')) {
Condition83%5/6
scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq "("
!ll&&!rl&&r
29730133
scalar @$tok > 2 and $tok->[0] =~ /^array$/i
!ll&&!rl&&r
42969133
MC/DC66%2/3
scalar @$tok > 2 and $tok->[0] =~ /^array$/i and $tok->[1] eq "("
scalar @$tok > 2 $tok->[0] =~ /^array$/i $tok->[1] eq "("
Truth table75%3/4
A and B and C
A= scalar @$tok > 2B= $tok->[0] =~ /^array$/iC= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
1919 133 shift @$tok;
1920 133 shift @$tok;
1921  
1922 133 my $arr = $self->newarr();
1923 133 $self->read_array($tok, ')', $arr);
1924  
1925 # execute expr & might continue with operation -> 'array(...)[idx]'?
1926 #
1927 133 unshift(@$tok, $arr->{name});
1928 133 return $self->read_statement($tok, $last_op);
1929 ▶ } elsif ((scalar @$tok > 4) && ((lc($tok->[0]) eq 'function') || (($tok->[0] =~ /^#pfx\d+$/) && (lc($tok->[1]) eq 'function')))) {
Condition100%9/9
scalar @$tok > 4 and lc $tok->[0] eq "function" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "function"
!ll&&!rl&&r
3082437228
lc $tok->[0] eq "function" or $tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "function"
l!l&&r!l&&!r
209192437
$tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "function"
!ll&&!rl&&r
24013619
MC/DC100%4/4
scalar @$tok > 4 and lc $tok->[0] eq "function" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "function"
scalar @$tok > 4 lc $tok->[0] eq "function" $tok->[0] =~ /^#pfx\d+$/ lc $tok->[1] eq "function"
Truth table100%5/5
A and B or C and D
A= scalar @$tok > 4B= lc $tok->[0] eq "function"C= $tok->[0] =~ /^#pfx\d+$/D= lc $tok->[1] eq "function"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1930 228 my $pfx = shift @$tok;
1931 228 my $p = {};
1932  
1933 228 ▶ if ($pfx =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pfx =~ /^#pfx\d+$/) 19 209 228
1934 19 $p = $self->{strmap}->{$pfx};
1935 19 shift @$tok;
1936 }
1937 228 my $cmd;
1938  
1939 # also allow anonymous funcs: http://php.net/manual/en/functions.anonymous.php
1940 #
1941 228 ▶ if ($tok->[0] ne '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] ne "(") 212 16 228
1942 212 my $sym = shift @$tok;
1943 212 $cmd = $self->read_statement([$sym], undef);
1944 212 ▶ if (is_strval($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($cmd)) 211 1 212
1945 211 $cmd = $self->{strmap}{$cmd};
1946 }
1947 }
1948 228 my $arglist = [];
1949 228 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq '(') { } 228 0 228
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "("
!ll&&!rl&&r
00228
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "("
scalar @$tok > 0 $tok->[0] eq "("
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "("
ABresult
0X0
100
111
1950 228 shift @$tok;
1951 228 $arglist = $self->read_block($tok, ')', ',');
1952 } else {
1953 0 $self->{warn}->('parse', "expected function arglist ()");
1954 }
1955 228 my $block = [];
1956 228 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq '{') { } 228 0 228
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
00228
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1957 228 shift @$tok;
1958 228 $block = $self->read_code_block($tok, '}', ';');
1959 } else {
1960 0 $self->{warn}->('parse', "expected function block {}");
1961 }
1962 228 $block = $self->setblk('std', $block);
1963  
1964 # function are registered later via registerfun
1965 #
1966 228 my $k = $self->setfun($cmd, $arglist, $block, $p);
1967  
1968 228 ▶ unless (defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmd) 16 212 228
1969 # anonymous functions might be called directly -> 'function () { return 1; }()'
1970 #
1971 16 unshift(@$tok, $k);
1972 16 $k = $self->read_statement($tok, $last_op);
1973 }
1974 228 return $k;
1975 ▶ } elsif ((scalar @$tok > 3) && ((lc($tok->[0]) eq 'class') || (($tok->[0] =~ /^#pfx\d+$/) && (lc($tok->[1]) eq 'class')))) {
Condition77%7/9
scalar @$tok > 3 and lc $tok->[0] eq "class" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "class"
!ll&&!rl&&r
97259256
lc $tok->[0] eq "class" or $tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "class"
l!l&&r!l&&!r
5602592
$tok->[0] =~ /^#pfx\d+$/ and lc $tok->[1] eq "class"
!ll&&!rl&&r
2556360
MC/DC50%2/4
scalar @$tok > 3 and lc $tok->[0] eq "class" || $tok->[0] =~ /^#pfx\d+$/ && lc $tok->[1] eq "class"
scalar @$tok > 3 lc $tok->[0] eq "class" $tok->[0] =~ /^#pfx\d+$/ lc $tok->[1] eq "class"
Truth table80%4/5
A and B or C and D
A= scalar @$tok > 3B= lc $tok->[0] eq "class"C= $tok->[0] =~ /^#pfx\d+$/D= lc $tok->[1] eq "class"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
1976 56 my $pfx = shift @$tok;
1977 56 my $p = {};
1978  
1979 56 ▶ if ($pfx =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pfx =~ /^#pfx\d+$/) 0 56 56
1980 0 $p = $self->{strmap}->{$pfx};
1981 0 shift @$tok;
1982 }
1983 56 my $name = shift @$tok;
1984  
1985 # http://php.net/manual/en/language.oop5.basic.php
1986 #
1987 56 ▶ if ($tok->[0] eq 'extends') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[0] eq "extends") 0 56 56
1988 0 shift @$tok;
1989 0 $p->{parent} = shift @$tok;
1990 }
1991 56 my $block = [];
1992 56 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 56 0 56
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
0056
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
1993 56 shift @$tok;
1994 56 $block = $self->read_block($tok, '}', ';');
1995 }
1996 56 $block = $self->setblk('std', $block);
1997 56 return $self->setclass($name, $block, $p);
1998 ▶ } elsif ((scalar @$tok > 3) && (lc($tok->[0]) eq 'trait')) {
Condition100%3/3
scalar @$tok > 3 and lc $tok->[0] eq "trait"
!ll&&!rl&&r
9725911
MC/DC100%2/2
scalar @$tok > 3 and lc $tok->[0] eq "trait"
scalar @$tok > 3 lc $tok->[0] eq "trait"
Truth table100%3/3
A and B
A= scalar @$tok > 3B= lc $tok->[0] eq "trait"
ABresult
0X0
100
111
1999 1 shift @$tok;
2000 1 my $name = shift @$tok;
2001  
2002 # https://www.php.net/manual/en/language.oop5.traits.php
2003 #
2004 1 my $block = [];
2005 1 ▶ if ((scalar @$tok > 0) && ($tok->[0] eq '{')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq "{") 1 0 1
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq "{"
!ll&&!rl&&r
001
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq "{"
scalar @$tok > 0 $tok->[0] eq "{"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq "{"
ABresult
0X0
100
111
2006 1 shift @$tok;
2007 1 $block = $self->read_block($tok, '}', ';');
2008 }
2009 1 $block = $self->setblk('std', $block);
2010 1 return $self->settrait($name, $block);
2011 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^#pfx\d+$/)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/
!ll&&!rl&&r
0265236
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^#pfx\d+$/
scalar @$tok > 1 $tok->[0] =~ /^#pfx\d+$/
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^#pfx\d+$/
ABresult
0X0
100
111
2012 36 my $sym = shift @$tok;
2013  
2014 # TODO: support const and other visibility modifiers
2015 # https://www.php.net/manual/en/language.oop5.visibility.php
2016 #
2017 36 ▶ if (exists $self->{strmap}->{$sym}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$sym}) 36 0 36
2018 36 my $pfx = $self->{strmap}->{$sym};
2019 36 ▶ if (exists $pfx->{static}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"static"}) 11 25 36
2020 11 my @args = ();
2021 11 while (1) {
2022 11 my $arg = $self->read_statement($tok, undef);
2023  
2024 11 push(@args, $arg);
2025 11 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 11 0 11
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
0110
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
2026 11 last;
2027 }
2028 0 shift @$tok;
2029 }
2030 11 return $self->setstmt(['static', \@args, $pfx]);
2031 }
2032 25 ▶ if (exists $pfx->{const}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"const"}) 9 16 25
2033 9 my @args = ();
2034 9 while (1) {
2035 9 my $arg = $self->read_statement($tok, undef);
2036  
2037 9 push(@args, $arg);
2038 9 ▶ unless ((scalar @$tok > 0) && ($tok->[0] eq ',')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$tok > 0 and $tok->[0] eq ",") 9 0 9
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ","
!ll&&!rl&&r
090
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ","
scalar @$tok > 0 $tok->[0] eq ","
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ","
ABresult
0X0
100
111
2039 9 last;
2040 }
2041 0 shift @$tok;
2042 }
2043 9 return $self->setstmt(['const', \@args, $pfx]);
2044 }
2045 }
2046 16 return $sym;
2047 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] !~ /^([\~\!\+\-\\]|new)$/i) && ($tok->[1] eq '(')) {
Condition100%6/6
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq "("
!ll&&!rl&&r
861845721
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i
!ll&&!rl&&r
4822566
MC/DC100%3/3
scalar @$tok > 2 and not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i and $tok->[1] eq "("
scalar @$tok > 2 not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/i $tok->[1] eq "("
Truth table100%4/4
A and not(B) and C
A= scalar @$tok > 2B= not $tok->[0] =~ /^([\~\!\+\-\\]|new)$/iC= $tok->[1] eq "("
ABCresult
0XX0
10X0
1100
1111
2048 # function call
2049 # (function name might be variable)
2050 #
2051 721 my $sym = shift @$tok;
2052 721 my $cmd = $sym;
2053  
2054 721 ▶ unless (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($sym)) 78 643 721
2055 78 $cmd = $self->read_statement([$sym], undef);
2056 }
2057 721 ▶ if (defined $last_op && ($last_op eq '$')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "\$") 1 720 721
Condition100%3/3
defined $last_op and $last_op eq "\$"
!ll&&!rl&&r
4572631
MC/DC100%2/2
defined $last_op and $last_op eq "\$"
defined $last_op $last_op eq "\$"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "\$"
ABresult
0X0
100
111
2058 # handle case: $$var(x) is ${$var}(x)
2059 1 return $cmd;
2060 }
2061 720 ▶ if (defined $last_op && ($last_op eq '::')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "::") 23 697 720
Condition100%3/3
defined $last_op and $last_op eq "::"
!ll&&!rl&&r
45724023
MC/DC100%2/2
defined $last_op and $last_op eq "::"
defined $last_op $last_op eq "::"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "::"
ABresult
0X0
100
111
2062 # handle case: (class::member)(x)
2063 23 return $cmd;
2064 }
2065 697 ▶ if (defined $last_op && ($last_op eq '->')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "->") 26 671 697
Condition100%3/3
defined $last_op and $last_op eq "->"
!ll&&!rl&&r
45721426
MC/DC100%2/2
defined $last_op and $last_op eq "->"
defined $last_op $last_op eq "->"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "->"
ABresult
0X0
100
111
2066 # handle case: ($obj->method)(x)
2067 26 return $cmd;
2068 }
2069 671 ▶ if (defined $last_op && ($last_op eq '\\')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "\\") 2 669 671
Condition100%3/3
defined $last_op and $last_op eq "\\"
!ll&&!rl&&r
4572122
MC/DC100%2/2
defined $last_op and $last_op eq "\\"
defined $last_op $last_op eq "\\"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "\\"
ABresult
0X0
100
111
2070 # handle case: (ns \\ cmd)(x)
2071 2 return $cmd;
2072 }
2073 669 ▶ if (is_strict_variable($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strict_variable($sym)) 16 653 669
2074 16 $cmd = $sym; # don't insert copy anonymous function here
2075 }
2076 669 shift @$tok;
2077  
2078 669 ▶ if (is_strval($cmd) && !is_null($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($cmd) and not is_null($cmd)) 0 669 669
Condition33%1/3
is_strval($cmd) and not is_null($cmd)
!ll&&!rl&&r
66900
MC/DC0%0/2
is_strval($cmd) and not is_null($cmd)
is_strval($cmd) not is_null($cmd)
Truth table33%1/3
A and not(B)
A= is_strval($cmd)B= not is_null($cmd)
ABresult
0X0
100
111
2079 0 $cmd = $self->{strmap}{$cmd};
2080 }
2081 669 ▶ if ($cmd =~ /^\@(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^\@(.*)$/) 0 669 669
2082 # remove optional '@' error suppress operator
2083 0 $cmd = $1;
2084 }
2085 # get arglist so that ref-params are not resolved to value
2086 # (need function definition to decide how to resolve variables)
2087 #
2088 669 my $arglist = $self->read_block($tok, ')', ',');
2089 669 my $k;
2090 669 ▶ if ($cmd eq 'unset') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd eq 'unset') { } 5 664 669
elsif ($cmd eq 'list') { } 2 662 664
2091 5 $k = $self->setstmt(['unset', $arglist]);
2092 } elsif ($cmd eq 'list') {
2093 2 my $arr = $self->newarr();
2094 2 foreach my $val (@$arglist) {
2095 4 $arr->set(undef, $val);
2096 }
2097 2 $k = $arr->{name};
2098 } else {
2099 662 $k = $self->setcall($cmd, $arglist);
2100 }
2101 669 unshift(@$tok, $k);
2102 669 return $self->read_statement($tok, $last_op);
2103 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '$') && (is_symbol($tok->[1]))) {
Condition66%4/6
scalar @$tok > 1 and $tok->[0] eq "\$" and is_symbol($tok->[1])
!ll&&!rl&&r
1847840
scalar @$tok > 1 and $tok->[0] eq "\$"
!ll&&!rl&&r
0184784
MC/DC0%0/3
scalar @$tok > 1 and $tok->[0] eq "\$" and is_symbol($tok->[1])
scalar @$tok > 1 $tok->[0] eq "\$" is_symbol($tok->[1])
Truth table50%2/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "\$"C= is_symbol($tok->[1])
ABCresult
0XX0
10X0
1100
1111
2104 # variable reference via $ val => $val
2105 #
2106 0 shift @$tok;
2107 0 my $sym = shift @$tok;
2108  
2109 0 my $str = $self->get_strval_or_str($sym);
2110 0 my $var = '$' . $str;
2111 0 unshift(@$tok, $var);
2112 0 return $self->read_statement($tok, $last_op);
2113 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] eq '$') && ($tok->[1] =~ /^\$/)) {
Condition83%5/6
scalar @$tok > 1 and $tok->[0] eq "\$" and $tok->[1] =~ /^\$/
!ll&&!rl&&r
1847786
scalar @$tok > 1 and $tok->[0] eq "\$"
!ll&&!rl&&r
0184784
MC/DC66%2/3
scalar @$tok > 1 and $tok->[0] eq "\$" and $tok->[1] =~ /^\$/
scalar @$tok > 1 $tok->[0] eq "\$" $tok->[1] =~ /^\$/
Truth table75%3/4
A and B and C
A= scalar @$tok > 1B= $tok->[0] eq "\$"C= $tok->[1] =~ /^\$/
ABCresult
0XX0
10X0
1100
1111
2114 # variable variable via $ $var => $<string-in-var>
2115 # Attention:
2116 # - $$var[x] is ${$var[x]}
2117 # - $$var(x) is ${$var}(x)
2118 #
2119 6 shift @$tok;
2120 6 my $res = $self->read_statement($tok, '$');
2121 6 my $k = $self->setexpr('$', undef, $res);
2122  
2123 6 unshift(@$tok, $k);
2124 6 return $self->read_statement($tok, $last_op);
2125 #} elsif ((scalar @$tok > 1) && ($tok->[0] eq '#') && ($tok->[1] =~ /^(str|num)\d+$/)) {
2126 # # for re-eval: literal reference via # str/num => #str
2127 # #
2128 # shift @$tok;
2129 # my $sym = shift @$tok;
2130 #
2131 # my $var = '#' . $sym;
2132 # unshift(@$tok, $var);
2133 # return $self->read_statement($tok, $last_op);
2134 ▶ } elsif ((scalar @$tok > 3) && ($tok->[0] eq '$') && ($tok->[1] eq '{')) {
Condition83%5/6
scalar @$tok > 3 and $tok->[0] eq "\$" and $tok->[1] eq "{"
!ll&&!rl&&r
1847078
scalar @$tok > 3 and $tok->[0] eq "\$"
!ll&&!rl&&r
70177778
MC/DC66%2/3
scalar @$tok > 3 and $tok->[0] eq "\$" and $tok->[1] eq "{"
scalar @$tok > 3 $tok->[0] eq "\$" $tok->[1] eq "{"
Truth table75%3/4
A and B and C
A= scalar @$tok > 3B= $tok->[0] eq "\$"C= $tok->[1] eq "{"
ABCresult
0XX0
10X0
1100
1111
2135 # variable variable via $ { string } => $string
2136 # variable variable via $ { func(xxx) } is also allowed
2137 #
2138 78 shift @$tok;
2139 78 shift @$tok;
2140  
2141 78 my $arglist = $self->read_block($tok, '}', undef);
2142 78 my $k;
2143 78 ▶ if (scalar @$arglist == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist == 1) { } 78 0 78
2144 78 my $res = $arglist->[0];
2145 78 ▶ if (is_strval($res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($res)) 21 57 78
2146 21 my $str = $self->{strmap}{$res};
2147 21 ▶ if (is_symbol($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_symbol($str)) 16 5 21
2148 16 my $var = '$' . $str;
2149 16 unshift(@$tok, $var);
2150 16 return $self->read_statement($tok, $last_op);
2151 }
2152 }
2153 62 $k = $self->setexpr('$', undef, $res);
2154 } else {
2155 0 $self->{warn}->('parse', "bad arglist \$ { %s }", join(' ', @$arglist));
2156 0 my $res = $self->setblk('std', $arglist);
2157 0 $k = $self->setexpr('$', undef, $res);
2158 }
2159 62 unshift(@$tok, $k);
2160 62 return $self->read_statement($tok, $last_op);
2161 ▶ } elsif ((scalar @$tok > 3) && (is_strict_variable($tok->[0]) || ($tok->[0] =~ /^#/)) && (($tok->[1] eq '[') || ($tok->[1] eq '{'))) {
Condition100%12/12
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq "[" || $tok->[1] eq "{"
!ll&&!rl&&r
2291198420
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/
!ll&&!rl&&r
701591618
is_strict_variable($tok->[0]) or $tok->[0] =~ /^#/
l!l&&r!l&&!r
1187431159
$tok->[1] eq "[" or $tok->[1] eq "{"
l!l&&r!l&&!r
41821198
MC/DC100%5/5
scalar @$tok > 3 and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#/ and $tok->[1] eq "[" || $tok->[1] eq "{"
scalar @$tok > 3 is_strict_variable($tok->[0]) $tok->[0] =~ /^#/ $tok->[1] eq "[" $tok->[1] eq "{"
Truth table87%7/8
A and B or C and D or E
A= scalar @$tok > 3B= is_strict_variable($tok->[0])C= $tok->[0] =~ /^#/D= $tok->[1] eq "["E= $tok->[1] eq "{"
ABCDEresult
0XXXX0
100XX0
11X000
101000
11X1X1
11X011
1011X1
101011
2162 # array reference via $var['string']
2163 # or: variable $GLOBALS['string'] -> $string
2164 # or: $strvar[idx] -> char
2165 #
2166 # or: $var[string] -> string
2167 # (old: php autoconverts bare string into string const which
2168 # contains the string - not always the same as the 'str' index
2169 # see: http://php.net/manual/en/language.types.array.php
2170 # see: define('const', 'val')
2171 # )
2172 #
2173 # http://php.net/manual/de/language.types.string.php
2174 # - Strings may also be accessed using braces, as in $str{42},
2175 # for the same purpose. However, this syntax is deprecated as
2176 # of php7.4 and disabled in php8. Use square brackets instead.
2177 #
2178 420 my $sym = shift @$tok;
2179  
2180 420 ▶ if (defined $last_op && ($last_op eq '::')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "::") 4 416 420
Condition100%3/3
defined $last_op and $last_op eq "::"
!ll&&!rl&&r
354624
MC/DC100%2/2
defined $last_op and $last_op eq "::"
defined $last_op $last_op eq "::"
Truth table100%3/3
A and B
A= defined $last_opB= $last_op eq "::"
ABresult
0X0
100
111
2181 # handle case: (class::$var)(x)
2182 4 return $sym;
2183 }
2184 416 ▶ if (defined $last_op && ($last_op eq '->')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op and $last_op eq "->") 0 416 416
Condition66%2/3
defined $last_op and $last_op eq "->"
!ll&&!rl&&r
354620
MC/DC0%0/2
defined $last_op and $last_op eq "->"
defined $last_op $last_op eq "->"
Truth table66%2/3
A and B
A= defined $last_opB= $last_op eq "->"
ABresult
0X0
100
111
2185 # handle case: ($obj->var)(x)
2186 0 return $sym;
2187 }
2188 416 my $bracket = shift @$tok;
2189 416 my $arglist;
2190  
2191 416 ▶ if ($bracket eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bracket eq '[') { } 414 2 416
2192 414 $arglist = $self->read_index_block($tok, ']', undef);
2193 } else {
2194 2 $arglist = $self->read_index_block($tok, '}', undef);
2195 }
2196 416 ▶ if (scalar @$arglist > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arglist > 1) 0 416 416
2197 0 $self->{warn}->('parse', "bad arglist %s [ %s ]", $sym, join(' ', @$arglist));
2198 0 unshift(@$tok, ('[', @$arglist, ']'));
2199 0 return $sym;
2200 }
2201 416 ▶ if ((scalar @$arglist == 1) && is_strval($arglist->[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$arglist == 1 and is_strval($arglist->[0])) { } 320 96 416
elsif (scalar @$arglist == 1 and is_symbol($arglist->[0])) { } 0 112 112
Condition100%3/3
scalar @$arglist == 1 and is_strval($arglist->[0])
!ll&&!rl&&r
1680320
MC/DC100%2/2
scalar @$arglist == 1 and is_strval($arglist->[0])
scalar @$arglist == 1 is_strval($arglist->[0])
Truth table100%3/3
A and B
A= scalar @$arglist == 1B= is_strval($arglist->[0])
ABresult
0X0
100
111
2202 320 my $str = $arglist->[0];
2203 320 if (0) {
2204 if ($sym =~ /^\$GLOBALS$/) {
2205 my $val = $self->get_strval($str);
2206 my $var = '$' . $val;
2207 unshift(@$tok, $var);
2208 my $res = $self->read_statement($tok, $last_op);
2209 return $res;
2210 }
2211 }
2212 ▶ } elsif ((scalar @$arglist == 1) && (is_symbol($arglist->[0]))) {
Condition66%2/3
scalar @$arglist == 1 and is_symbol($arglist->[0])
!ll&&!rl&&r
16800
MC/DC0%0/2
scalar @$arglist == 1 and is_symbol($arglist->[0])
scalar @$arglist == 1 is_symbol($arglist->[0])
Truth table66%2/3
A and B
A= scalar @$arglist == 1B= is_symbol($arglist->[0])
ABresult
0X0
100
111
2213 # bare string
2214 0 my $str = $arglist->[0];
2215 0 my $k = $self->setstr($str);
2216 0 unshift(@$tok, ($sym, '[', $k, ']'));
2217 0 my $res = $self->read_statement($tok, $last_op);
2218 0 return $res;
2219 }
2220 416 my $k = $self->setelem($sym, $arglist->[0]);
2221  
2222 # execute expr & might continue with lower prio operation
2223 #
2224 416 unshift(@$tok, $k);
2225 416 return $self->read_statement($tok, $last_op);
2226 ▶ } elsif ((scalar @$tok > 2) && ($tok->[0] =~ /^(\+|\-)$/) && ($tok->[1] eq $tok->[0])) {
Condition100%6/6
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]
!ll&&!rl&&r
1409612
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/
!ll&&!rl&&r
2140718
MC/DC100%3/3
scalar @$tok > 2 and $tok->[0] =~ /^(\+|\-)$/ and $tok->[1] eq $tok->[0]
scalar @$tok > 2 $tok->[0] =~ /^(\+|\-)$/ $tok->[1] eq $tok->[0]
Truth table100%4/4
A and B and C
A= scalar @$tok > 2B= $tok->[0] =~ /^(\+|\-)$/C= $tok->[1] eq $tok->[0]
ABCresult
0XX0
10X0
1100
1111
2227 # ++$var
2228 # --$var
2229 #
2230 12 my $op = shift @$tok;
2231 12 shift @$tok;
2232  
2233 12 my $var = $self->read_statement($tok, "$op$op");
2234 12 my $k = $self->setexpr($op.$op, undef, $var);
2235  
2236 # execute expr & might continue with lower prio operation
2237 #
2238 12 unshift(@$tok, $k);
2239 12 return $self->read_statement($tok, $last_op);
2240 ▶ } elsif ((scalar @$tok > 3) && ($tok->[0] eq '.') && ($tok->[1] eq '.') && ($tok->[2] eq '.')) {
Condition44%4/9
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "." and $tok->[2] eq "."
!ll&&!rl&&r
141500
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "."
!ll&&!rl&&r
141500
scalar @$tok > 3 and $tok->[0] eq "."
!ll&&!rl&&r
6813470
MC/DC0%0/4
scalar @$tok > 3 and $tok->[0] eq "." and $tok->[1] eq "." and $tok->[2] eq "."
scalar @$tok > 3 $tok->[0] eq "." $tok->[1] eq "." $tok->[2] eq "."
Truth table40%2/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[0] eq "."C= $tok->[1] eq "."D= $tok->[2] eq "."
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2241 # ...$var
2242 #
2243 0 shift @$tok;
2244 0 shift @$tok;
2245 0 shift @$tok;
2246  
2247 0 my $var = $self->read_statement($tok, '...');
2248 0 my $k = $self->setexpr('...', undef, $var);
2249  
2250 # execute expr & might continue with lower prio operation
2251 #
2252 0 unshift(@$tok, $k);
2253 0 return $self->read_statement($tok, $last_op);
2254 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^\\$/)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^\\$/
!ll&&!rl&&r
014087
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^\\$/
scalar @$tok > 1 $tok->[0] =~ /^\\$/
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^\\$/
ABresult
0X0
100
111
2255 # \val
2256 #
2257 7 my $op = shift @$tok;
2258  
2259 7 my $val = $self->read_statement($tok, $op);
2260 7 my $k = $self->setns(undef, $val); # toplevel namespace
2261  
2262 # execute expr & might continue with lower prio operation
2263 #
2264 7 unshift(@$tok, $k);
2265 7 return $self->read_statement($tok, $last_op);
2266 ▶ } elsif ((scalar @$tok > 1) && ($tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i)) {
Condition66%2/3
scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
!ll&&!rl&&r
0134266
MC/DC50%1/2
scalar @$tok > 1 and $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
scalar @$tok > 1 $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
Truth table66%2/3
A and B
A= scalar @$tok > 1B= $tok->[0] =~ /^([\~\!\+\-]|new|exception)$/i
ABresult
0X0
100
111
2267 # ~val
2268 # !val
2269 # +val
2270 # -val
2271 # new val
2272 #
2273 66 my $op = shift @$tok;
2274 66 my $val;
2275  
2276 66 ▶ if (($op eq '+') || ($op eq '-')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+' or $op eq '-') { } 7 59 66
elsif (lc $op eq 'new') { } 39 20 59
Condition100%3/3
$op eq "+" or $op eq "-"
l!l&&r!l&&!r
1659
MC/DC100%2/2
$op eq "+" or $op eq "-"
$op eq "+" $op eq "-"
Truth table100%3/3
A or B
A= $op eq "+"B= $op eq "-"
ABresult
1X1
011
000
2277 7 $val = $self->read_statement($tok, '+-');
2278 } elsif (lc($op) eq 'new') {
2279 # add optional parenthesis for 'new a' if necessary
2280 # -> with parenthesis $val is parsed as #call
2281 #
2282 39 $val = $self->read_statement($tok, $op);
2283 39 ▶ if ($val =~ /^#(str|const)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^#(str|const)/) 7 32 39
2284 7 $val = $self->setcall($self->{strmap}->{$val}, []);
2285 }
2286 } else {
2287 20 $val = $self->read_statement($tok, $op);
2288 }
2289 66 my $k = $self->setexpr($op, undef, $val);
2290  
2291 # execute expr & might continue with lower prio operation
2292 #
2293 66 unshift(@$tok, $k);
2294 66 return $self->read_statement($tok, $last_op);
2295 ▶ } elsif ((scalar @$tok > 2) && ($tok->[1] =~ /^([\.\+\-\*\/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$/i)) {
Condition66%2/3
scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
!ll&&!rl&&r
0131329
MC/DC50%1/2
scalar @$tok > 2 and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
scalar @$tok > 2 $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
Truth table66%2/3
A and B
A= scalar @$tok > 2B= $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%<>\?\:]|=|\!|==|\!=|<>|<=|>=|<<|>>|===|\!==|<=>|\?\:|\?\?|\&\&|\|\||\+\+|\-\-|and|or|xor|instanceof|\->|::|\\)$]i
ABresult
0X0
100
111
2296 # val1 . val2
2297 # val1 + val2
2298 # val1 - val2
2299 # val1 ^ val2
2300 # ...
2301 #
2302 1329 ▶ if (($tok->[1] =~ /^[<>\&\|\*\?]$/) && ($tok->[2] eq $tok->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]) 16 1313 1329
Condition100%3/3
$tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]
!ll&&!rl&&r
12506316
MC/DC100%2/2
$tok->[1] =~ /^[<>\&\|\*\?]$/ and $tok->[2] eq $tok->[1]
$tok->[1] =~ /^[<>\&\|\*\?]$/ $tok->[2] eq $tok->[1]
Truth table100%3/3
A and B
A= $tok->[1] =~ /^[<>\&\|\*\?]$/B= $tok->[2] eq $tok->[1]
ABresult
0X0
100
111
2303 # val1 << val2 (also: <<=)
2304 # val1 >> val2 (also: >>=)
2305 # val1 ** val2 (also: **=)
2306 # val1 ?? val2 (also: ??=)
2307 # val1 || val2
2308 # val1 && val2
2309 #
2310 16 my $sym = shift @$tok;
2311 16 my $op = shift @$tok;
2312 16 shift @$tok;
2313 16 unshift(@$tok, ($sym, $op.$op));
2314 # fall through
2315 }
2316 1329 ▶ if (($tok->[2] eq '=') && ($tok->[1] =~ /^([\.\+\-\*\/\^\&\|\%]|<<|>>|\*\*|\?\?)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]) 29 1300 1329
Condition100%3/3
$tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
!ll&&!rl&&r
12722829
MC/DC100%2/2
$tok->[2] eq "=" and $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
$tok->[2] eq "=" $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
Truth table100%3/3
A and B
A= $tok->[2] eq "="B= $tok->[1] =~ m[^([\.\+\-\*/\^\&\|\%]|<<|>>|\*\*|\?\?)$]
ABresult
0X0
100
111
2317 # num += ...
2318 # num .= ...
2319 #
2320 29 my $sym = shift @$tok;
2321 29 my $op = shift @$tok;
2322 29 shift @$tok;
2323  
2324 # keep in_block flag for '='
2325 29 my $op2 = $self->read_statement($tok, undef);
2326  
2327 # keep precedence of $op against following expr
2328 29 my $k2 = $self->setexpr($op, $sym, $op2);
2329 29 unshift(@$tok, ($sym, '=', $k2));
2330 29 return $self->read_statement($tok, $last_op);
2331 }
2332 1300 ▶ if (($tok->[1] eq '=') && ($tok->[2] eq '>')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->[1] eq "=" and $tok->[2] eq ">") 45 1255 1300
Condition100%3/3
$tok->[1] eq "=" and $tok->[2] eq ">"
!ll&&!rl&&r
38487145
MC/DC100%2/2
$tok->[1] eq "=" and $tok->[2] eq ">"
$tok->[1] eq "=" $tok->[2] eq ">"
Truth table100%3/3
A and B
A= $tok->[1] eq "="B= $tok->[2] eq ">"
ABresult
0X0
100
111
2333 # $expr1 =>
2334 #
2335 45 my $sym = shift @$tok;
2336 45 shift @$tok;
2337 45 shift @$tok;
2338 45 unshift(@$tok, ($sym, '=>'));
2339  
2340 45 return $self->read_statement($tok, $last_op);
2341 }
2342 1255 ▶ if (($tok->[1] =~ /^(\+|\-)$/) && ($tok->[2] eq $tok->[1]) && (is_strict_variable($tok->[0]) || ($tok->[0] =~ /^#(scope|inst)\d+$/))) {
Branch: 9 branches
BranchTrueFalseTotal
if ($tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/) { } 35 1220 1255
elsif (scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq '=' and $tok->[3] eq '=') { } 5 1215 1220
elsif (scalar @$tok > 3 and $tok->[1] eq '<' and $tok->[2] eq '=' and $tok->[3] eq '>') { } 3 1212 1215
elsif ($tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq '=') { } 20 1192 1212
elsif ($tok->[1] eq '<' and $tok->[2] eq '>') { } 0 1192 1192
elsif ($tok->[1] =~ /^[=\!]$/ and $tok->[2] eq '==') { } 0 1192 1192
elsif ($tok->[1] eq '-' and $tok->[2] eq '>') { } 52 1140 1192
elsif ($tok->[1] eq ':' and $tok->[2] eq ':') { } 41 1099 1140
elsif ($tok->[1] eq '?' and $tok->[2] eq ':') { } 3 2176 2179
Condition88%8/9
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/
!ll&&!rl&&r
1219135
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1]
!ll&&!rl&&r
11249536
is_strict_variable($tok->[0]) or $tok->[0] =~ /^#(scope|inst)\d+$/
l!l&&r!l&&!r
3501
MC/DC75%3/4
$tok->[1] =~ /^(\+|\-)$/ and $tok->[2] eq $tok->[1] and is_strict_variable($tok->[0]) || $tok->[0] =~ /^#(scope|inst)\d+$/
$tok->[1] =~ /^(\+|\-)$/ $tok->[2] eq $tok->[1] is_strict_variable($tok->[0]) $tok->[0] =~ /^#(scope|inst)\d+$/
Truth table80%4/5
A and B and C or D
A= $tok->[1] =~ /^(\+|\-)$/B= $tok->[2] eq $tok->[1]C= is_strict_variable($tok->[0])D= $tok->[0] =~ /^#(scope|inst)\d+$/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2343 # $var++
2344 # $var--
2345 #
2346 35 my $sym = shift @$tok;
2347 35 my $op = shift @$tok;
2348 35 shift @$tok;
2349 35 unshift(@$tok, ($sym, $op.$op));
2350 # fall through
2351 ▶ } elsif ((scalar @$tok > 3) && ($tok->[1] =~ /^[=\!]$/) && ($tok->[2] eq '=') && ($tok->[3] eq '=')) {
Condition100%9/9
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=" and $tok->[3] eq "="
!ll&&!rl&&r
1199165
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "="
!ll&&!rl&&r
37382621
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/
!ll&&!rl&&r
63310847
MC/DC100%4/4
scalar @$tok > 3 and $tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=" and $tok->[3] eq "="
scalar @$tok > 3 $tok->[1] =~ /^[=\!]$/ $tok->[2] eq "=" $tok->[3] eq "="
Truth table100%5/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[1] =~ /^[=\!]$/C= $tok->[2] eq "="D= $tok->[3] eq "="
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2352 # val1 === val2
2353 # val1 !== val2
2354 #
2355 5 my $sym = shift @$tok;
2356 5 my $op = shift @$tok;
2357 5 shift @$tok;
2358 5 shift @$tok;
2359 5 unshift(@$tok, ($sym, $op.'=='));
2360 # fall through
2361 ▶ } elsif ((scalar @$tok > 3) && ($tok->[1] eq '<') && ($tok->[2] eq '=') && ($tok->[3] eq '>')) {
Condition100%9/9
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "=" and $tok->[3] eq ">"
!ll&&!rl&&r
120933
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "="
!ll&&!rl&&r
1184256
scalar @$tok > 3 and $tok->[1] eq "<"
!ll&&!rl&&r
63112131
MC/DC100%4/4
scalar @$tok > 3 and $tok->[1] eq "<" and $tok->[2] eq "=" and $tok->[3] eq ">"
scalar @$tok > 3 $tok->[1] eq "<" $tok->[2] eq "=" $tok->[3] eq ">"
Truth table100%5/5
A and B and C and D
A= scalar @$tok > 3B= $tok->[1] eq "<"C= $tok->[2] eq "="D= $tok->[3] eq ">"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2362 # val1 <=> val2
2363 #
2364 3 my $sym = shift @$tok;
2365 3 my $op = shift @$tok;
2366 3 shift @$tok;
2367 3 shift @$tok;
2368 3 unshift(@$tok, ($sym, '<=>'));
2369 # fall through
2370 ▶ } elsif (($tok->[1] =~ /^[=\!<>]$/) && ($tok->[2] eq '=')) {
Condition100%3/3
$tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq "="
!ll&&!rl&&r
31387920
MC/DC100%2/2
$tok->[1] =~ /^[=\!<>]$/ and $tok->[2] eq "="
$tok->[1] =~ /^[=\!<>]$/ $tok->[2] eq "="
Truth table100%3/3
A and B
A= $tok->[1] =~ /^[=\!<>]$/B= $tok->[2] eq "="
ABresult
0X0
100
111
2371 # val1 == val2
2372 # val1 != val2
2373 # val1 <= val2
2374 # val1 >= val2
2375 #
2376 20 my $sym = shift @$tok;
2377 20 my $op = shift @$tok;
2378 20 shift @$tok;
2379 20 unshift(@$tok, ($sym, $op.'='));
2380 # fall through
2381 ▶ } elsif (($tok->[1] eq '<') && ($tok->[2] eq '>')) {
Condition66%2/3
$tok->[1] eq "<" and $tok->[2] eq ">"
!ll&&!rl&&r
1167250
MC/DC0%0/2
$tok->[1] eq "<" and $tok->[2] eq ">"
$tok->[1] eq "<" $tok->[2] eq ">"
Truth table66%2/3
A and B
A= $tok->[1] eq "<"B= $tok->[2] eq ">"
ABresult
0X0
100
111
2382 # val1 <> val2 (diamond operator work as !=)
2383 #
2384 0 my $sym = shift @$tok;
2385 0 my $op = shift @$tok;
2386 0 shift @$tok;
2387 0 unshift(@$tok, ($sym, '!='));
2388 # fall through
2389 ▶ } elsif (($tok->[1] =~ /^[=\!]$/) && ($tok->[2] eq '==')) { # TODO: does this occur?
Condition66%2/3
$tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=="
!ll&&!rl&&r
3408520
MC/DC0%0/2
$tok->[1] =~ /^[=\!]$/ and $tok->[2] eq "=="
$tok->[1] =~ /^[=\!]$/ $tok->[2] eq "=="
Truth table66%2/3
A and B
A= $tok->[1] =~ /^[=\!]$/B= $tok->[2] eq "=="
ABresult
0X0
100
111
2390 # val1 === val2
2391 # val1 !== val2
2392 #
2393 0 my $sym = shift @$tok;
2394 0 my $op = shift @$tok;
2395 0 shift @$tok;
2396 0 unshift(@$tok, ($sym, $op.'=='));
2397 # fall through
2398 ▶ } elsif (($tok->[1] eq '-') && ($tok->[2] eq '>')) {
Condition100%3/3
$tok->[1] eq "-" and $tok->[2] eq ">"
!ll&&!rl&&r
1136452
MC/DC100%2/2
$tok->[1] eq "-" and $tok->[2] eq ">"
$tok->[1] eq "-" $tok->[2] eq ">"
Truth table100%3/3
A and B
A= $tok->[1] eq "-"B= $tok->[2] eq ">"
ABresult
0X0
100
111
2399 # $obj -> member
2400 #
2401 52 my $sym = shift @$tok;
2402 52 shift @$tok;
2403 52 shift @$tok;
2404 52 unshift(@$tok, ($sym, '->')); # for operator precedence
2405 # fall through
2406 ▶ } elsif (($tok->[1] eq ':') && ($tok->[2] eq ':')) {
Condition66%2/3
$tok->[1] eq ":" and $tok->[2] eq ":"
!ll&&!rl&&r
1099041
MC/DC50%1/2
$tok->[1] eq ":" and $tok->[2] eq ":"
$tok->[1] eq ":" $tok->[2] eq ":"
Truth table66%2/3
A and B
A= $tok->[1] eq ":"B= $tok->[2] eq ":"
ABresult
0X0
100
111
2407 # class :: elem
2408 #
2409 41 my $sym = shift @$tok;
2410 41 shift @$tok;
2411 41 shift @$tok;
2412 41 unshift(@$tok, ($sym, '::'));
2413 # fall through
2414 ▶ } elsif (($tok->[1] eq '?') && ($tok->[2] eq ':')) {
Condition100%3/3
$tok->[1] eq "?" and $tok->[2] eq ":"
!ll&&!rl&&r
1080163
MC/DC100%2/2
$tok->[1] eq "?" and $tok->[2] eq ":"
$tok->[1] eq "?" $tok->[2] eq ":"
Truth table100%3/3
A and B
A= $tok->[1] eq "?"B= $tok->[2] eq ":"
ABresult
0X0
100
111
2415 # ternary: $expr1 ?: $expr3
2416 #
2417 3 my $sym = shift @$tok;
2418 3 shift @$tok;
2419 3 shift @$tok;
2420 3 unshift(@$tok, ($sym, '?:'));
2421 # fall through
2422 }
2423 # remaining binary ops
2424 # variable assignment
2425 #
2426 1255 my $sym = shift @$tok;
2427 1255 my $op = shift @$tok;
2428 1255 my $op1;
2429 1255 $op = lc($op);
2430  
2431 1255 ▶ if (($op eq '->') || ($op eq '::') || ($op eq '\\')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '->' or $op eq '::' or $op eq '\\') { } 103 1152 1255
Condition100%6/6
$op eq "->" or $op eq "::" or $op eq "\\"
l!l&&r!l&&!r
9491152
$op eq "->" or $op eq "::"
l!l&&r!l&&!r
52421161
MC/DC100%3/3
$op eq "->" or $op eq "::" or $op eq "\\"
$op eq "->" $op eq "::" $op eq "\\"
Truth table100%4/4
A or B or C
A= $op eq "->"B= $op eq "::"C= $op eq "\\"
ABCresult
1XX1
01X1
0011
0000
2432 103 $op1 = $sym; # don't evaluate lefthand side variable
2433 } else {
2434 1152 $op1 = $self->read_statement([$sym], undef);
2435 }
2436 1255 ▶ if (defined $last_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_op) 175 1080 1255
2437 175 ▶ unless (exists $op_prio{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $op_prio{$op}) 0 175 175
2438 0 $self->{warn}->('parse', "missing op_prio(%s) [last %s]", $op, $last_op);
2439 }
2440 175 ▶ unless (exists $op_prio{$last_op}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $op_prio{$last_op}) 0 175 175
2441 0 $self->{warn}->('parse', "op_prio(%s) [op %s]", $last_op, $op);
2442 }
2443 175 ▶ $self->{debug}->('parse', "SYM $sym OP %s LAST %s", $op, $last_op) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 175 175
2444 175 ▶ if ($op_prio{$op} >= $op_prio{$last_op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op_prio{$op} >= $op_prio{$last_op}) 66 109 175
2445 # - for right associative ops like '=' continue to parse left-hand side.
2446 # - but for identical ops like '$a=$b=1' parse right-hand side first.
2447 # - there is a special case for unary op and '=' ('!$x=2' is same as '!($x=2)')
2448 #
2449 66 ▶ if (($op ne $last_op) || !exists $op_right{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne $last_op or not exists $op_right{$op}) 62 4 66
Condition100%3/3
$op ne $last_op or not exists $op_right{$op}
l!l&&r!l&&!r
27354
MC/DC100%2/2
$op ne $last_op or not exists $op_right{$op}
$op ne $last_op not exists $op_right{$op}
Truth table100%3/3
A or not(B)
A= $op ne $last_opB= not exists $op_right{$op}
ABresult
1X1
011
000
2450 62 ▶ unless (($op eq '=') && (exists $op_unary{$last_op} || !exists $op_right{$last_op})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}) 58 4 62
Condition100%6/6
$op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}
!ll&&!rl&&r
46124
exists $op_unary{$last_op} or not exists $op_right{$last_op}
l!l&&r!l&&!r
3112
MC/DC100%3/3
$op eq "=" and exists $op_unary{$last_op} || !exists $op_right{$last_op}
$op eq "=" exists $op_unary{$last_op} not exists $op_right{$last_op}
Truth table100%4/4
A and B or not(C)
A= $op eq "="B= exists $op_unary{$last_op}C= not exists $op_right{$last_op}
ABCresult
0XX0
1000
11X1
1011
2451 58 ▶ $self->{log}->('parse', "curr %s %s has higher/equal prio than last %s", $op1, $op, $last_op) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 58 58
2452 58 unshift(@$tok, $op);
2453 58 return $op1;
2454 }
2455 }
2456 }
2457 }
2458 1197 my $k;
2459 1197 ▶ if ($op eq '?') {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '?') { } 15 1182 1197
elsif ($op eq '->') { } 52 1130 1182
elsif ($op eq '::') { } 41 1089 1130
elsif ($op eq '\\') { } 5 1084 1089
elsif ($op eq '++' or $op eq '--') { } 35 1049 1084
2460 # ternary: $op1 ? $expr2 : $expr3
2461 #
2462 15 my $expr2 = $self->read_statement($tok, $op);
2463 15 ▶ if ((scalar @$tok > 0) && $tok->[0] eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0 and $tok->[0] eq ':') { } 15 0 15
Condition33%1/3
scalar @$tok > 0 and $tok->[0] eq ":"
!ll&&!rl&&r
0015
MC/DC0%0/2
scalar @$tok > 0 and $tok->[0] eq ":"
scalar @$tok > 0 $tok->[0] eq ":"
Truth table33%1/3
A and B
A= scalar @$tok > 0B= $tok->[0] eq ":"
ABresult
0X0
100
111
2464 15 shift @$tok;
2465 } else {
2466 0 $self->{warn}->('parse', "ternary: missing : [%s ? %s]", $sym, $expr2);
2467 }
2468 15 my $expr3 = $self->read_statement($tok, ':');
2469 15 my $op2 = $self->setexpr(':', $expr2, $expr3);
2470 15 $k = $self->setexpr('?', $op1, $op2);
2471 } elsif ($op eq '->') {
2472 # $obj -> member
2473 #
2474 52 my $op2 = $self->read_statement($tok, $op);
2475  
2476 52 ▶ if (is_block($op2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($op2)) 2 50 52
2477 # $obj -> {'member'}
2478 #
2479 2 my ($type, $a) = @{$self->{strmap}->{$op2}};
2480 2 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) 2 0 2
2481 2 $op2 = $a->[0];
2482 }
2483 }
2484 52 $op2 = $self->get_strval_or_str($op2);
2485  
2486 52 $k = $self->setobj($op1, $op2);
2487 } elsif ($op eq '::') {
2488 # class :: member
2489 #
2490 41 my $class = $sym;
2491 41 ▶ unless (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($sym)) 1 40 41
2492 1 $class = $self->read_statement([$sym], undef);
2493 1 $class = $self->get_strval_or_str($class);
2494 }
2495 41 my $elem = $self->read_statement($tok, $op);
2496 41 $elem = $self->get_strval_or_str($elem);
2497  
2498 41 $k = $self->setscope($class, $elem);
2499 } elsif ($op eq '\\') {
2500 # ns/elem
2501 #
2502 5 my $op2 = $self->read_statement($tok, $op);
2503 5 $op1 = $self->get_strval_or_str($op1);
2504  
2505 5 $k = $self->setns($op1, $op2);
2506 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition100%3/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
3411049
MC/DC100%2/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table100%3/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
2507 # $var++
2508 # $var--
2509 #
2510 35 $k = $self->setexpr($op, $op1, undef);
2511 } else {
2512 1049 if (1) {
2513 # optimize long concat chains to avoid memory exhaustion
2514 # (sometimes hundreds of strings get concatted)
2515 #
2516 1049 ▶ if (($op eq '.') && is_strval($op1) && (scalar @$tok > 2) && is_strval($tok->[0]) && ($tok->[1] eq '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq ".") 0 1049 1049
Condition75%9/12
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
!ll&&!rl&&r
104900
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0])
!ll&&!rl&&r
1020290
$op eq "." and is_strval($op1) and scalar @$tok > 2
!ll&&!rl&&r
1016429
$op eq "." and is_strval($op1)
!ll&&!rl&&r
9684833
MC/DC0%0/5
$op eq "." and is_strval($op1) and scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
$op eq "." is_strval($op1) scalar @$tok > 2 is_strval($tok->[0]) $tok->[1] eq "."
Truth table66%4/6
A and B and C and D and E
A= $op eq "."B= is_strval($op1)C= scalar @$tok > 2D= is_strval($tok->[0])E= $tok->[1] eq "."
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
2517 0 my @list;
2518 0 push(@list, $op1);
2519 0 ▶ while ((scalar @$tok > 2) && is_strval($tok->[0]) && ($tok->[1] eq '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq ".") 0 0 0
Condition0%0/6
scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
!ll&&!rl&&r
000
scalar @$tok > 2 and is_strval($tok->[0])
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @$tok > 2 and is_strval($tok->[0]) and $tok->[1] eq "."
scalar @$tok > 2 is_strval($tok->[0]) $tok->[1] eq "."
Truth table0%0/4
A and B and C
A= scalar @$tok > 2B= is_strval($tok->[0])C= $tok->[1] eq "."
ABCresult
0XX0
10X0
1100
1111
2520 0 my $s = shift @$tok;
2521 0 shift @$tok;
2522 0 push(@list, $s);
2523 }
2524 0 $self->{warn}->('parse', "optimize concat chain here: %s", join(' ', @list));
2525 0 my $line = join('', map { $self->{strmap}->{$_} } @list);
2526 0 $op1 = $self->setstr($line);
2527 }
2528 }
2529 1049 my $op2 = $self->read_statement($tok, $op);
2530 1049 $k = $self->setexpr($op, $op1, $op2);
2531 }
2532 # execute expr & might continue with lower prio operation
2533 #
2534 1197 unshift(@$tok, $k);
2535 1197 return $self->read_statement($tok, $last_op);
2536 }
2537  
2538 13 ▶ if (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 13 0 13
2539 13 my $sym = shift @$tok;
2540  
2541 # some symbols are pushed back into token-stream and might be passed through here
2542 #
2543 13 ▶ $self->{log}->('parse', "skip symbol %s", $sym) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 13 13
2544 13 return $sym;
2545 }
2546 0 return;
2547 }
2548  
2549 # last_op & in_block are optional params
2550 #
2551 13401 ▶sub read_statement {
Subroutine read_statement: called CC=6 SCAR=18.1
Pod undocumented
2552 13401 my ($self, $tok, $last_op) = @_;
2553 13401 my $level = 0;
2554  
2555 13401 ▶ if (exists $self->{strmap}->{_LEVEL}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{'_LEVEL'}) { } 12681 720 13401
2556 12681 $self->{strmap}->{_LEVEL} += 1;
2557 } else {
2558 720 $self->{strmap}->{_LEVEL} = 1;
2559 }
2560 13401 $level = $self->{strmap}->{_LEVEL};
2561  
2562 # show next 10 tokens to process
2563 #
2564 13401 ▶ my $tl = (scalar @$tok > 10) ? 10 : scalar @$tok;
Branch: 1 branch
BranchTrueFalseTotal
scalar @$tok > 10 ? : 5084 8317 13401
2565 #$self->{log}->('PARSE', "[%d:%d] %s %s", $level, scalar @$tok, join(' ', @$tok[0..$tl-1]), (scalar @$tok > 10) ? '...' : '') if $self->{log};
2566 13401 ▶ my $tab = ($level <= 1) ? '' : ('....' x ($level-2)) . '... ';
Branch: 1 branch
BranchTrueFalseTotal
$level <= 1 ? : 2186 11215 13401
2567 13401 ▶ $self->{log}->('PARSE', "$tab%s%s", join(' ', @$tok[0..$tl-1]), (scalar @$tok > 10) ? ' ..['.(scalar @$tok - 10).']' : '') if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 13401 13401
scalar @$tok > 10 ? : 0 0 0
2568  
2569 13401 my $ret = $self->_read_statement($tok, $last_op);
2570 13401 $self->{strmap}->{_LEVEL} -= 1;
2571 13401 return $ret;
2572 }
2573  
2574 3544 ▶sub filter_bad_brace {
Subroutine filter_bad_brace: called CC=2 SCAR=7.6
Pod undocumented
2575 3544 my ($stmt) = @_;
2576  
2577 3544 ▶ if ($stmt =~ /^[\)\]\}]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^[\)\]\}]$/) 0 3544 3544
2578 0 $stmt = "<BAD_BRACE_$stmt>";
2579 }
2580 3544 return $stmt;
2581 }
2582  
2583 416 ▶sub read_index_block {
Subroutine read_index_block: called CC=7 SCAR=21.1
Pod undocumented
2584 416 my ($self, $tok, $close, $separator) = @_;
2585 416 my @out = ();
2586  
2587 416 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 416 416
2588  
2589 416 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 816 0 816
2590 # always resolve assignment in index to value
2591 #
2592 816 my $stmt = $self->read_statement($tok, undef);
2593  
2594 816 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 816 816
2595  
2596 816 ▶ if ($stmt eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt eq $close) { } 416 400 816
elsif (defined $separator and $stmt eq $separator) { } 0 400 400
2597 # block end
2598 #
2599 416 return \@out;
2600 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition33%1/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
40000
MC/DC0%0/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table33%1/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2601 #push(@out, $separator);
2602 } else {
2603 400 $stmt = filter_bad_brace($stmt);
2604 400 push(@out, $stmt);
2605 }
2606 }
2607 0 return \@out;
2608 }
2609  
2610 1261 ▶sub read_block {
Subroutine read_block: called CC=9 SCAR=23.2
Pod undocumented
2611 1261 my ($self, $tok, $close, $separator) = @_;
2612 1261 my @out = ();
2613 1261 my $last;
2614  
2615 1261 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1261 1261
2616  
2617 1261 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 2526 0 2526
2618 2526 my $stmt = $self->read_statement($tok, undef);
2619  
2620 2526 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2526 2526
2621  
2622 2526 ▶ if ($stmt eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt eq $close) { } 1261 1265 2526
elsif (defined $separator and $stmt eq $separator) { } 147 1118 1265
2623 # block end
2624 #
2625 1261 return \@out;
2626 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition100%3/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
272846147
MC/DC100%2/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table100%3/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2627 147 ▶ if (defined $last && ($last eq $separator)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last and $last eq $separator) 0 147 147
Condition33%1/3
defined $last and $last eq $separator
!ll&&!rl&&r
01470
MC/DC0%0/2
defined $last and $last eq $separator
defined $last $last eq $separator
Truth table33%1/3
A and B
A= defined $lastB= $last eq $separator
ABresult
0X0
100
111
2628 0 push(@out, undef); # allow empty field
2629 }
2630 #push(@out, $separator);
2631 } else {
2632 1118 $stmt = filter_bad_brace($stmt);
2633 1118 push(@out, $stmt);
2634 }
2635 1265 $last = $stmt;
2636 }
2637 0 return \@out;
2638 }
2639  
2640 1269 ▶sub read_code_block {
Subroutine read_code_block: called CC=7 SCAR=19.6
Pod undocumented
2641 1269 my ($self, $tok, $close, $separator) = @_;
2642 1269 my @out = ();
2643  
2644 1269 ▶ $self->{debug}->('parse', "B+$close") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1269 1269
2645  
2646 1269 ▶ while (scalar @$tok > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$tok > 0) 3558 793 4351
2647 3558 my $stmt = $self->read_statement($tok, undef);
2648  
2649 3558 ▶ $self->{debug}->('parse', "B-$close $stmt") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 3558 3558
2650  
2651 3558 ▶ if ($stmt eq $close) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt eq $close) { } 476 3082 3558
elsif (defined $separator and $stmt eq $separator) { } 1056 2026 3082
2652 # block end
2653 #
2654 476 return \@out;
2655 ▶ } elsif (defined $separator && ($stmt eq $separator)) {
Condition66%2/3
defined $separator and $stmt eq $separator
!ll&&!rl&&r
020261056
MC/DC50%1/2
defined $separator and $stmt eq $separator
defined $separator $stmt eq $separator
Truth table66%2/3
A and B
A= defined $separatorB= $stmt eq $separator
ABresult
0X0
100
111
2656 #push(@out, $separator);
2657 } else {
2658 2026 $stmt = filter_bad_brace($stmt);
2659 2026 push(@out, $stmt);
2660 }
2661 }
2662 793 return \@out;
2663 }
2664  
2665 1 ▶sub tokens {
Subroutine tokens: called CC=1 SCAR=0.0
Pod undocumented
2666 1 my ($self) = @_;
2667 1 return $self->{tok};
2668 }
2669  
2670 785 ▶sub read_code {
Subroutine read_code: called CC=2 SCAR=6.9
Pod documented
2671 785 my ($self, $tok) = @_;
2672 785 my $in;
2673 785 my @out = ();
2674  
2675 785 $in = unspace_list($tok);
2676  
2677 785 my $stmts = $self->read_code_block($in, '?>', ';');
2678 785 ▶ if (scalar @$stmts == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$stmts == 1) 331 454 785
2679 331 return $stmts->[0];
2680 }
2681 454 my $k = $self->setblk('flat', $stmts);
2682 454 return $k;
2683 }
2684  
2685 3116 ▶sub map_stmt {
Subroutine map_stmt: called CC=165 SCAR=87.8
Pod undocumented
2686 3116 my ($self, $s, $cb, @params) = @_;
2687  
2688 #$self->{log}->('MAP', "$s") if $self->{log};
2689  
2690 3116 my $k = $cb->($s, @params);
2691 3116 ▶ if (defined $k) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) 286 2830 3116
2692 286 return $k;
2693 }
2694 2830 my $s0 = $s;
2695  
2696 2830 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 2830 2830
elsif ($s =~ /^#null$/) { } 22 2808 2830
elsif ($s =~ /^#num\d+$/) { } 164 2644 2808
elsif ($s =~ /^#const\d+$/) { } 0 2644 2644
elsif ($s =~ /^#str\d+$/) { } 484 2160 2644
elsif ($s =~ /^#arr\d+$/) { } 133 2027 2160
elsif ($s =~ /^#fun\d+$/) { } 14 2013 2027
elsif ($s =~ /^#call\d+$/) { } 87 1926 2013
elsif ($s =~ /^#elem\d+$/) { } 50 1876 1926
elsif ($s =~ /^#expr\d+$/) { } 282 1594 1876
elsif ($s =~ /^#pfx\d+$/) { } 0 1594 1594
elsif ($s =~ /^#obj\d+$/) { } 12 1582 1594
elsif ($s =~ /^#scope\d+$/) { } 0 1582 1582
elsif ($s =~ /^#ns\d+$/) { } 0 1582 1582
elsif ($s =~ /^#inst\d+$/) { } 0 1582 1582
elsif ($s =~ /^#ref\d+$/) { } 0 1582 1582
elsif ($s =~ /^#class\d+$/) { } 0 1582 1582
elsif ($s =~ /^#trait\d+$/) { } 0 1582 1582
elsif ($s =~ /^#fh\d+$/) { } 0 1582 1582
elsif ($s =~ /^#blk\d+$/) { } 602 980 1582
elsif ($s =~ /^#stmt\d+$/) { } 529 451 980
elsif (is_variable($s)) { } 352 99 451
2697 0 $self->{warn}->('map', "undefined symbol");
2698 # keep
2699 } elsif ($s =~ /^#null$/) {
2700 # keep
2701 } elsif ($s =~ /^#num\d+$/) {
2702 # keep
2703 } elsif ($s =~ /^#const\d+$/) {
2704 # keep
2705 } elsif ($s =~ /^#str\d+$/) {
2706 # keep
2707 } elsif ($s =~ /^#arr\d+$/) {
2708 133 my $arr = $self->{strmap}{$s};
2709 133 my $keys = $arr->get_keys();
2710 133 my %newmap;
2711 133 my @newkeys = ();
2712 133 my $changed = 0;
2713  
2714 133 foreach my $k (@$keys) {
2715 236 my $val = $arr->val($k);
2716 236 ▶ if ((is_int_index($k) || is_strval($k)) && (!defined $val
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)) { } 236 0 236
Condition33%4/12
is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)
!ll&&!rl&&r
00236
is_int_index($k) or is_strval($k)
l!l&&r!l&&!r
23600
not defined $val or defined $val and is_strval($val)
l!l&&r!l&&!r
02360
defined $val and is_strval($val)
!ll&&!rl&&r
00236
MC/DC0%0/5
is_int_index($k) || is_strval($k) and !defined($val) || defined $val && is_strval($val)
is_int_index($k) is_strval($k) not defined $val defined $val is_strval($val)
Truth table11%1/9
A or B and not(C) or D and E
A= is_int_index($k)B= is_strval($k)C= not defined $valD= defined $valE= is_strval($val)
ABCDEresult
00XXX0
1X00X0
1X0100
0100X0
010100
1X1XX1
1X0111
011XX1
010111
2717 || (defined $val && is_strval($val)))) {
2718 236 push(@newkeys, $k);
2719 236 $newmap{$k} = $val;
2720 } else {
2721 0 my $k2 = $k;
2722 0 ▶ unless (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_int_index($k)) 0 0 0
2723 0 $k2 = $self->map_stmt($k, $cb, @params);
2724 }
2725 0 push(@newkeys, $k2);
2726 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
2727 0 my $v = $self->map_stmt($val, $cb, @params);
2728 0 $newmap{$k2} = $v;
2729 } else {
2730 0 $newmap{$k2} = undef;
2731 }
2732 0 ▶ if (($k ne $k2) || ($val ne $newmap{$k2})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k ne $k2 or $val ne $newmap{$k2}) 0 0 0
Condition0%0/3
$k ne $k2 or $val ne $newmap{$k2}
l!l&&r!l&&!r
000
MC/DC0%0/2
$k ne $k2 or $val ne $newmap{$k2}
$k ne $k2 $val ne $newmap{$k2}
Truth table0%0/3
A or B
A= $k ne $k2B= $val ne $newmap{$k2}
ABresult
1X1
011
000
2733 0 $changed = 1;
2734 }
2735 }
2736 }
2737 133 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 0 133 133
2738 0 $arr = $self->newarr();
2739 0 foreach my $k (@newkeys) {
2740 0 $arr->set($k, $newmap{$k});
2741 }
2742 0 $s = $arr->{name};
2743 }
2744 } elsif ($s =~ /^#fun\d+$/) {
2745 14 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
2746 # no context change here
2747 } elsif ($s =~ /^#call\d+$/) {
2748 87 my ($f, $a) = @{$self->{strmap}->{$s}};
2749 87 my @args = ();
2750 87 my $arg_changed = 0;
2751 87 my $name = $f;
2752  
2753 87 ▶ if ($f =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /^#fun\d+$/) { } 0 87 87
2754 # no context change here
2755 #$name = $self->map_stmt($f, $cb, @params);
2756 } else {
2757 87 $name = $self->map_stmt($f, $cb, @params);
2758 }
2759 87 foreach my $k (@$a) {
2760 65 my $v = $self->map_stmt($k, $cb, @params);
2761 65 push(@args, $v);
2762 65 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 65 65
2763 0 $arg_changed = 1;
2764 }
2765 }
2766 87 ▶ if (($name ne $f) || $arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne $f or $arg_changed) 0 87 87
Condition33%1/3
$name ne $f or $arg_changed
l!l&&r!l&&!r
0087
MC/DC0%0/2
$name ne $f or $arg_changed
$name ne $f $arg_changed
Truth table33%1/3
A or B
A= $name ne $fB= $arg_changed
ABresult
1X1
011
000
2767 0 $s = $self->setcall($name, \@args);
2768 }
2769 } elsif ($s =~ /^#elem\d+$/) {
2770 50 my ($v, $i) = @{$self->{strmap}->{$s}};
2771 50 my $vv = $self->map_stmt($v, $cb, @params);
2772 50 my $ii = $i;
2773  
2774 50 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 50 0 50
2775 50 $ii = $self->map_stmt($i, $cb, @params);
2776 }
2777 50 ▶ if (($v ne $vv) || (defined $i && ($i ne $ii))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $vv or defined $i and $i ne $ii) 0 50 50
Condition33%2/6
$v ne $vv or defined $i and $i ne $ii
l!l&&r!l&&!r
0050
defined $i and $i ne $ii
!ll&&!rl&&r
0500
MC/DC0%0/3
$v ne $vv or defined $i and $i ne $ii
$v ne $vv defined $i $i ne $ii
Truth table25%1/4
A or B and C
A= $v ne $vvB= defined $iC= $i ne $ii
ABCresult
1XX1
0111
00X0
0100
2778 0 $s = $self->setelem($vv, $ii);
2779 }
2780 } elsif ($s =~ /^#expr\d+$/) {
2781 # if v1 missing: prefix op
2782 # if v2 missing: postfix op
2783 282 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
2784 282 my $vv1 = $v1;
2785 282 my $vv2 = $v2;
2786  
2787 282 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 276 6 282
2788 276 $vv1 = $self->map_stmt($v1, $cb, @params);
2789 }
2790 282 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 282 0 282
2791 282 $vv2 = $self->map_stmt($v2, $cb, @params);
2792 }
2793 282 ▶ if ((defined $v1 && ($v1 ne $vv1)) || (defined $v2 && ($v2 ne $vv2))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2) 10 272 282
Condition66%6/9
defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2
l!l&&r!l&&!r
100272
defined $v1 and $v1 ne $vv1
!ll&&!rl&&r
626610
defined $v2 and $v2 ne $vv2
!ll&&!rl&&r
02720
MC/DC50%2/4
defined $v1 and $v1 ne $vv1 or defined $v2 and $v2 ne $vv2
defined $v1 $v1 ne $vv1 defined $v2 $v2 ne $vv2
Truth table42%3/7
A and B or C and D
A= defined $v1B= $v1 ne $vv1C= defined $v2D= $v2 ne $vv2
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2794 10 $s = $self->setexpr($op, $vv1, $vv2);
2795 }
2796 } elsif ($s =~ /^#pfx\d+$/) {
2797 # keep
2798 } elsif ($s =~ /^#obj\d+$/) {
2799 12 my ($o, $m) = @{$self->{strmap}->{$s}};
2800 12 my $oo = $o;
2801 12 my $mm = $m;
2802  
2803 12 ▶ unless ($o =~ /^#call\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o =~ /^#call\d+$/) 12 0 12
2804 # not 'new'
2805 12 $oo = $self->map_stmt($o, $cb, @params);
2806 }
2807 12 ▶ unless (exists $self->{strmap}->{$m} && is_symbol($self->{strmap}->{$m})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})) 12 0 12
Condition33%1/3
exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})
!ll&&!rl&&r
1200
MC/DC0%0/2
exists $self->{"strmap"}{$m} and is_symbol($self->{"strmap"}{$m})
exists $self->{"strmap"}{$m} is_symbol($self->{"strmap"}{$m})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$m}B= is_symbol($self->{"strmap"}{$m})
ABresult
0X0
100
111
2808 # not 'sym'
2809 12 $mm = $self->map_stmt($m, $cb, @params);
2810 }
2811 12 ▶ if (($o ne $oo) || ($m ne $mm)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o ne $oo or $m ne $mm) 0 12 12
Condition33%1/3
$o ne $oo or $m ne $mm
l!l&&r!l&&!r
0012
MC/DC0%0/2
$o ne $oo or $m ne $mm
$o ne $oo $m ne $mm
Truth table33%1/3
A or B
A= $o ne $ooB= $m ne $mm
ABresult
1X1
011
000
2812 0 $s = $self->setobj($oo, $mm);
2813 }
2814 } elsif ($s =~ /^#scope\d+$/) {
2815 0 my ($c, $e) = @{$self->{strmap}->{$s}};
2816 0 my $cc = $c;
2817 0 my $ee = $e;
2818  
2819 0 ▶ unless (exists $self->{strmap}->{$c} && is_symbol($self->{strmap}->{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
exists $self->{"strmap"}{$c} is_symbol($self->{"strmap"}{$c})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$c}B= is_symbol($self->{"strmap"}{$c})
ABresult
0X0
100
111
2820 # not 'class'
2821 0 $cc = $self->map_stmt($c, $cb, @params);
2822 }
2823 0 ▶ unless (exists $self->{strmap}->{$e} && is_symbol($self->{strmap}->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
exists $self->{"strmap"}{$e} is_symbol($self->{"strmap"}{$e})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$e}B= is_symbol($self->{"strmap"}{$e})
ABresult
0X0
100
111
2824 # not 'sym'
2825 0 $ee = $self->map_stmt($e, $cb, @params);
2826 }
2827 0 ▶ if (($c ne $cc) || ($e ne $ee)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne $cc or $e ne $ee) 0 0 0
Condition0%0/3
$c ne $cc or $e ne $ee
l!l&&r!l&&!r
000
MC/DC0%0/2
$c ne $cc or $e ne $ee
$c ne $cc $e ne $ee
Truth table0%0/3
A or B
A= $c ne $ccB= $e ne $ee
ABresult
1X1
011
000
2828 0 $s = $self->setscope($cc, $ee);
2829 }
2830 } elsif ($s =~ /^#ns\d+$/) {
2831 0 my ($n, $e) = @{$self->{strmap}->{$s}};
2832 0 my $nn = $n;
2833 0 my $ee = $self->map_stmt($e, $cb, @params);
2834  
2835 0 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 0 0 0
2836 # non-sym should be error
2837 0 ▶ unless (exists $self->{strmap}->{$n} && is_symbol($self->{strmap}->{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})) 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
exists $self->{"strmap"}{$n} is_symbol($self->{"strmap"}{$n})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$n}B= is_symbol($self->{"strmap"}{$n})
ABresult
0X0
100
111
2838 0 $nn = $self->map_stmt($n, $cb, @params);
2839 }
2840 }
2841 0 ▶ if ((defined $n && ($n ne $nn)) || ($e ne $ee)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and $n ne $nn or $e ne $ee) 0 0 0
Condition0%0/6
defined $n and $n ne $nn or $e ne $ee
l!l&&r!l&&!r
000
defined $n and $n ne $nn
!ll&&!rl&&r
000
MC/DC0%0/3
defined $n and $n ne $nn or $e ne $ee
defined $n $n ne $nn $e ne $ee
Truth table0%0/5
A and B or C
A= defined $nB= $n ne $nnC= $e ne $ee
ABCresult
11X1
0X11
1011
0X00
1000
2842 0 $s = $self->setobj($nn, $ee);
2843 }
2844 } elsif ($s =~ /^#inst\d+$/) {
2845 0 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
2846 } elsif ($s =~ /^#ref\d+$/) {
2847 0 my ($v) = @{$self->{strmap}->{$s}};
2848 } elsif ($s =~ /^#class\d+$/) {
2849 0 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
2850 # no context change here
2851 } elsif ($s =~ /^#trait\d+$/) {
2852 0 my ($t, $b) = @{$self->{strmap}->{$s}};
2853 # no context change here
2854 } elsif ($s =~ /^#fh\d+$/) {
2855 0 my $f = $self->{strmap}->{$s}{name};
2856 0 my $m = $self->{strmap}->{$s}{mode};
2857 0 my $p = $self->{strmap}->{$s}{pos};
2858 } elsif ($s =~ /^#blk\d+$/) {
2859 602 my ($type, $a) = @{$self->{strmap}->{$s}};
2860 602 my @args = ();
2861 602 my $arg_changed = 0;
2862  
2863 602 foreach my $k (@$a) {
2864 698 my $v = $self->map_stmt($k, $cb, @params);
2865 698 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) { } 93 605 698
2866 93 ▶ unless ($self->is_empty_block($v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_empty_block($v)) 18 75 93
2867 18 push(@args, $v);
2868 }
2869 93 $arg_changed = 1;
2870 } else {
2871 605 push(@args, $v);
2872 }
2873 }
2874 602 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 85 517 602
2875 85 $s = $self->setblk($type, \@args);
2876 }
2877 } elsif ($s =~ /^#stmt\d+$/) {
2878 529 my $cmd = $self->{strmap}->{$s}->[0];
2879 529 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 108 421 529
elsif ($cmd eq 'print') { } 0 421 421
elsif ($cmd eq 'namespace') { } 0 421 421
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 421 421
elsif ($cmd eq 'use') { } 0 421 421
elsif ($cmd eq 'global') { } 8 413 421
elsif ($cmd eq 'static') { } 8 405 413
elsif ($cmd eq 'const') { } 0 405 405
elsif ($cmd eq 'unset') { } 0 405 405
elsif ($cmd eq 'return') { } 386 19 405
elsif ($cmd eq 'goto') { } 0 19 19
elsif ($cmd eq 'label') { } 0 19 19
elsif ($cmd eq 'throw') { } 0 19 19
elsif ($cmd eq 'if') { } 15 4 19
elsif ($cmd eq 'while') { } 0 4 4
elsif ($cmd eq 'do') { } 0 4 4
elsif ($cmd eq 'for') { } 0 4 4
elsif ($cmd eq 'foreach') { } 4 0 4
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'case') { } 0 0 0
elsif ($cmd eq 'try') { } 0 0 0
2880 108 my $a = $self->{strmap}->{$s}->[1];
2881 108 my @args = ();
2882 108 my $arg_changed = 0;
2883  
2884 108 foreach my $k (@$a) {
2885 108 my $v = $self->map_stmt($k, $cb, @params);
2886 108 push(@args, $v);
2887 108 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 108 108
2888 0 $arg_changed = 1;
2889 }
2890 }
2891 108 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 108 108
2892 0 $s = $self->setstmt(['echo', \@args]);
2893 }
2894 } elsif ($cmd eq 'print') {
2895 0 my $arg = $self->{strmap}->{$s}->[1];
2896 0 my $v = $self->map_stmt($arg, $cb, @params);
2897  
2898 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
2899 0 $s = $self->setstmt(['print', $v]);
2900 }
2901 } elsif ($cmd eq 'namespace') {
2902 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
2903 0 my $v = $arg;
2904 0 my $block1 = $block;
2905  
2906 0 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 0 0 0
2907 0 $block1 = $self->map_stmt($block, $cb, @params);
2908 }
2909 0 ▶ if (($v ne $arg) || ($block1 ne $block)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg or $block1 ne $block) 0 0 0
Condition0%0/3
$v ne $arg or $block1 ne $block
l!l&&r!l&&!r
000
MC/DC0%0/2
$v ne $arg or $block1 ne $block
$v ne $arg $block1 ne $block
Truth table0%0/3
A or B
A= $v ne $argB= $block1 ne $block
ABresult
1X1
011
000
2910 0 $s = $self->setstmt(['namespace', $v, $block1]);
2911 }
2912 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
2913 0 my $arg = $self->{strmap}->{$s}->[1];
2914 0 my $v = $self->map_stmt($arg, $cb, @params);
2915  
2916 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
2917 0 $s = $self->setstmt([$cmd, $v]);
2918 }
2919 } elsif ($cmd eq 'use') {
2920 0 my $a = $self->{strmap}->{$s}->[1];
2921 0 my @args = ();
2922 0 my $arg_changed = 0;
2923  
2924 0 foreach my $k (@$a) {
2925 0 my $v = $self->map_stmt($k, $cb, @params);
2926 0 push(@args, $v);
2927 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2928 0 $arg_changed = 1;
2929 }
2930 }
2931 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
2932 0 $s = $self->setstmt(['use', \@args]);
2933 }
2934 } elsif ($cmd eq 'global') {
2935 8 my $a = $self->{strmap}->{$s}->[1];
2936 8 my @args = ();
2937 8 my $arg_changed = 0;
2938  
2939 8 foreach my $k (@$a) {
2940 8 my $v = $self->map_stmt($k, $cb, @params);
2941 8 push(@args, $v);
2942 8 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 8 8
2943 0 $arg_changed = 1;
2944 }
2945 }
2946 8 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 8 8
2947 0 $s = $self->setstmt(['global', \@args]);
2948 }
2949 } elsif ($cmd eq 'static') {
2950 8 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
2951 8 my @args = ();
2952 8 my $arg_changed = 0;
2953  
2954 8 foreach my $k (@$a) {
2955 8 my $v = $self->map_stmt($k, $cb, @params);
2956 8 push(@args, $v);
2957 8 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 8 8
2958 0 $arg_changed = 1;
2959 }
2960 }
2961 8 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 8 8
2962 0 $s = $self->setstmt(['static', \@args, $p]);
2963 }
2964 } elsif ($cmd eq 'const') {
2965 0 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
2966 0 my @args = ();
2967 0 my $arg_changed = 0;
2968  
2969 0 foreach my $k (@$a) {
2970 0 my $v = $self->map_stmt($k, $cb, @params);
2971 0 push(@args, $v);
2972 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2973 0 $arg_changed = 1;
2974 }
2975 }
2976 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
2977 0 $s = $self->setstmt(['const', \@args, $p]);
2978 }
2979 } elsif ($cmd eq 'unset') {
2980 0 my $a = $self->{strmap}->{$s}->[1];
2981 0 my @args = ();
2982 0 my $arg_changed = 0;
2983  
2984 0 foreach my $k (@$a) {
2985 0 my $v = $self->map_stmt($k, $cb, @params);
2986 0 push(@args, $v);
2987 0 ▶ if ($v ne $k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $k) 0 0 0
2988 0 $arg_changed = 1;
2989 }
2990 }
2991 0 ▶ if ($arg_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_changed) 0 0 0
2992 0 $s = $self->setstmt(['unset', \@args]);
2993 }
2994 } elsif ($cmd eq 'return') {
2995 386 my $arg = $self->{strmap}->{$s}->[1];
2996 386 my $v = $arg;
2997  
2998 386 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 386 0 386
2999 386 $v = $self->map_stmt($arg, $cb, @params);
3000 }
3001 386 ▶ if (defined $v && ($v ne $arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and $v ne $arg) 0 386 386
Condition33%1/3
defined $v and $v ne $arg
!ll&&!rl&&r
03860
MC/DC0%0/2
defined $v and $v ne $arg
defined $v $v ne $arg
Truth table33%1/3
A and B
A= defined $vB= $v ne $arg
ABresult
0X0
100
111
3002 0 $s = $self->setstmt(['return', $v]);
3003 }
3004 } elsif ($cmd eq 'goto') {
3005 0 my $arg = $self->{strmap}->{$s}->[1];
3006 0 my $v = $self->map_stmt($arg, $cb, @params);
3007  
3008 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3009 0 $s = $self->setstmt(['goto', $v]);
3010 }
3011 } elsif ($cmd eq 'label') {
3012 0 my $arg = $self->{strmap}->{$s}->[1];
3013 0 my $v = $self->map_stmt($arg, $cb, @params);
3014  
3015 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3016 0 $s = $self->setstmt(['label', $v]);
3017 }
3018 } elsif ($cmd eq 'throw') {
3019 0 my $arg = $self->{strmap}->{$s}->[1];
3020 0 my $v = $self->map_stmt($arg, $cb, @params);
3021  
3022 0 ▶ if ($v ne $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $arg) 0 0 0
3023 0 $s = $self->setstmt(['throw', $v]);
3024 }
3025 } elsif ($cmd eq 'if') {
3026 15 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
3027 15 my $cond1 = $self->map_stmt($cond, $cb, @params);
3028 15 my $then1 = $self->map_stmt($then, $cb, @params);
3029 15 my $else1 = $else;
3030  
3031 15 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 0 15 15
3032 0 $else1 = $self->map_stmt($else, $cb, @params);
3033 }
3034 15 ▶ if (($cond ne $cond1) || ($then ne $then1) || (defined $else && ($else ne $else1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1) 2 13 15
Condition55%5/9
$cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1
l!l&&r!l&&!r
2013
$cond ne $cond1 or $then ne $then1
l!l&&r!l&&!r
0213
defined $else and $else ne $else1
!ll&&!rl&&r
1300
MC/DC25%1/4
$cond ne $cond1 or $then ne $then1 or defined $else and $else ne $else1
$cond ne $cond1 $then ne $then1 defined $else $else ne $else1
Truth table40%2/5
A or B or C and D
A= $cond ne $cond1B= $then ne $then1C= defined $elseD= $else ne $else1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3035 2 ▶ if ($self->is_empty_block($then1) && (!defined $else || $self->is_empty_block($else1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)) { } 2 0 2
Condition33%2/6
$self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)
!ll&&!rl&&r
002
not defined $else or $self->is_empty_block($else1)
l!l&&r!l&&!r
200
MC/DC0%0/3
$self->is_empty_block($then1) and !defined($else) || $self->is_empty_block($else1)
$self->is_empty_block($then1) not defined $else $self->is_empty_block($else1)
Truth table25%1/4
A and not(B) or C
A= $self->is_empty_block($then1)B= not defined $elseC= $self->is_empty_block($else1)
ABCresult
0XX0
1000
11X1
1011
3036 2 $s = $cond1;
3037 } else {
3038 0 $s = $self->setstmt(['if', $cond1, $then1, $else1]);
3039 }
3040 }
3041 } elsif ($cmd eq 'while') {
3042 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3043 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3044 0 my $block1 = $self->map_stmt($block, $cb, @params);
3045  
3046 0 ▶ if (($cond ne $cond1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $block ne $block1) 0 0 0
Condition0%0/3
$cond ne $cond1 or $block ne $block1
l!l&&r!l&&!r
000
MC/DC0%0/2
$cond ne $cond1 or $block ne $block1
$cond ne $cond1 $block ne $block1
Truth table0%0/3
A or B
A= $cond ne $cond1B= $block ne $block1
ABresult
1X1
011
000
3047 0 $s = $self->setstmt(['while', $cond1, $block1]);
3048 }
3049 } elsif ($cmd eq 'do') {
3050 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3051 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3052 0 my $block1 = $self->map_stmt($block, $cb, @params);
3053  
3054 0 ▶ if (($cond ne $cond1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond ne $cond1 or $block ne $block1) 0 0 0
Condition0%0/3
$cond ne $cond1 or $block ne $block1
l!l&&r!l&&!r
000
MC/DC0%0/2
$cond ne $cond1 or $block ne $block1
$cond ne $cond1 $block ne $block1
Truth table0%0/3
A or B
A= $cond ne $cond1B= $block ne $block1
ABresult
1X1
011
000
3055 0 $s = $self->setstmt(['do', $cond1, $block1]);
3056 }
3057 } elsif ($cmd eq 'for') {
3058 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
3059 0 my $pre1 = $self->map_stmt($pre, $cb, @params);
3060 0 my $cond1 = $self->map_stmt($cond, $cb, @params);
3061 0 my $post1 = $self->map_stmt($post, $cb, @params);
3062 0 my $block1 = $self->map_stmt($block, $cb, @params);
3063  
3064 0 ▶ if (($pre ne $pre1) || ($cond ne $cond1) || ($post ne $post1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1) 0 0 0
Condition0%0/9
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1
l!l&&r!l&&!r
000
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1
l!l&&r!l&&!r
000
$pre ne $pre1 or $cond ne $cond1
l!l&&r!l&&!r
000
MC/DC0%0/4
$pre ne $pre1 or $cond ne $cond1 or $post ne $post1 or $block ne $block1
$pre ne $pre1 $cond ne $cond1 $post ne $post1 $block ne $block1
Truth table0%0/5
A or B or C or D
A= $pre ne $pre1B= $cond ne $cond1C= $post ne $post1D= $block ne $block1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3065 0 $s = $self->setstmt(['for', $pre1, $cond1, $post1, $block1]);
3066 }
3067 } elsif ($cmd eq 'foreach') {
3068 4 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
3069 4 my $expr1 = $self->map_stmt($expr, $cb, @params);
3070 4 my $key1 = $key;
3071  
3072 4 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 4 0 4
3073 4 $key1 = $self->map_stmt($key, $cb, @params);
3074 }
3075 4 my $value1 = $self->map_stmt($value, $cb, @params);
3076 4 my $block1 = $self->map_stmt($block, $cb, @params);
3077  
3078 4 ▶ if (($expr ne $expr1) || (defined $key && ($key ne $key1)) || ($value ne $value1) || ($block ne $block1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1) 1 3 4
Condition41%5/12
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1
l!l&&r!l&&!r
013
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1
l!l&&r!l&&!r
004
$expr ne $expr1 or defined $key and $key ne $key1
l!l&&r!l&&!r
004
defined $key and $key ne $key1
!ll&&!rl&&r
040
MC/DC20%1/5
$expr ne $expr1 or defined $key and $key ne $key1 or $value ne $value1 or $block ne $block1
$expr ne $expr1 defined $key $key ne $key1 $value ne $value1 $block ne $block1
Truth table25%2/8
A or B and C or D or E
A= $expr ne $expr1B= defined $keyC= $key ne $key1D= $value ne $value1E= $block ne $block1
ABCDEresult
1XXXX1
011XX1
00X1X1
0101X1
00X011
010011
00X000
010000
3079 1 $s = $self->setstmt(['foreach', $expr1, $key1, $value1, $block1]);
3080 }
3081 } elsif ($cmd eq 'switch') {
3082 0 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
3083 0 my $expr1 = $self->map_stmt($expr, $cb, @params);
3084 0 my @cnew = ();
3085 0 my $changed = 0;
3086  
3087 0 foreach my $e (@$cases) {
3088 0 my $c = $e->[0];
3089 0 my $b = $e->[1];
3090 0 my $c1 = $c;
3091  
3092 0 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 0 0 0
3093 0 $c1 = $self->map_stmt($c, $cb, @params);
3094 }
3095 0 my $b1 = $self->map_stmt($b, $cb, @params);
3096  
3097 0 ▶ if ((defined $c1 && ($c ne $c1)) || ($b ne $b1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c1 and $c ne $c1 or $b ne $b1) 0 0 0
Condition0%0/6
defined $c1 and $c ne $c1 or $b ne $b1
l!l&&r!l&&!r
000
defined $c1 and $c ne $c1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c1 and $c ne $c1 or $b ne $b1
defined $c1 $c ne $c1 $b ne $b1
Truth table0%0/5
A and B or C
A= defined $c1B= $c ne $c1C= $b ne $b1
ABCresult
11X1
0X11
1011
0X00
1000
3098 0 $changed = 1;
3099 }
3100 0 push (@cnew, [$c1, $b1]);
3101 }
3102 0 ▶ if (($expr ne $expr1) || $changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr ne $expr1 or $changed) 0 0 0
Condition0%0/3
$expr ne $expr1 or $changed
l!l&&r!l&&!r
000
MC/DC0%0/2
$expr ne $expr1 or $changed
$expr ne $expr1 $changed
Truth table0%0/3
A or B
A= $expr ne $expr1B= $changed
ABresult
1X1
011
000
3103 0 $s = $self->setstmt(['switch', $expr1, \@cnew]);
3104 }
3105 } elsif ($cmd eq 'case') {
3106 0 my $expr = $self->{strmap}->{$s}->[1];
3107 0 my $expr1 = $expr;
3108  
3109 0 ▶ if (!defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expr) 0 0 0
3110 0 $expr1 = $self->map_stmt($expr, $cb, @params);
3111 }
3112 0 ▶ if (defined $expr && ($expr ne $expr1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr and $expr ne $expr1) 0 0 0
Condition0%0/3
defined $expr and $expr ne $expr1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $expr and $expr ne $expr1
defined $expr $expr ne $expr1
Truth table0%0/3
A and B
A= defined $exprB= $expr ne $expr1
ABresult
0X0
100
111
3113 0 $s = $self->setstmt(['case', $expr1]);
3114 }
3115 } elsif ($cmd eq 'try') {
3116 0 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
3117 0 my $try1 = $self->map_stmt($try, $cb, @params);
3118 0 my $finally1 = $finally;
3119 0 my @cnew = ();
3120 0 my $changed = 0;
3121  
3122 0 foreach my $c (@$catches) {
3123 0 my $e = $c->[0];
3124 0 my $b = $c->[1];
3125  
3126 0 my $e1 = $self->map_stmt($e, $cb, @params);
3127 0 my $b1 = $self->map_stmt($b, $cb, @params);
3128  
3129 0 ▶ if ((defined $e1 && ($e ne $e1)) || ($b ne $b1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e1 and $e ne $e1 or $b ne $b1) 0 0 0
Condition0%0/6
defined $e1 and $e ne $e1 or $b ne $b1
l!l&&r!l&&!r
000
defined $e1 and $e ne $e1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $e1 and $e ne $e1 or $b ne $b1
defined $e1 $e ne $e1 $b ne $b1
Truth table0%0/5
A and B or C
A= defined $e1B= $e ne $e1C= $b ne $b1
ABCresult
11X1
0X11
1011
0X00
1000
3130 0 $changed = 1;
3131 }
3132 0 push (@cnew, [$e1, $b1]);
3133 }
3134 0 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 0 0 0
3135 0 $finally1 = $self->map_stmt($finally, $cb, @params);
3136 }
3137 0 ▶ if (($try ne $try1) || $changed || (defined $finally && ($finally ne $finally1))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try ne $try1 or $changed or defined $finally and $finally ne $finally1) 0 0 0
Condition0%0/9
$try ne $try1 or $changed or defined $finally and $finally ne $finally1
l!l&&r!l&&!r
000
$try ne $try1 or $changed
l!l&&r!l&&!r
000
defined $finally and $finally ne $finally1
!ll&&!rl&&r
000
MC/DC0%0/4
$try ne $try1 or $changed or defined $finally and $finally ne $finally1
$try ne $try1 $changed defined $finally $finally ne $finally1
Truth table0%0/5
A or B or C and D
A= $try ne $try1B= $changedC= defined $finallyD= $finally ne $finally1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3138 0 $s = $self->setstmt(['try', $try1, \@cnew, $finally1]);
3139 }
3140 }
3141 } elsif (is_variable($s)) {
3142 # keep
3143 }
3144 2830 ▶ if ($s ne $s0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne $s0) 98 2732 2830
3145 98 ▶ $self->{debug}->('map', "map %s -> %s", $s0, $s) if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 98 98
3146 }
3147 2830 return $s;
3148 }
3149  
3150 1173 ▶sub escape_str {
Subroutine escape_str: called CC=2 SCAR=7.1
Pod undocumented
3151 1173 my ($s, $fmt) = @_;
3152  
3153 # escape string (keep newlines as newline like php does)
3154 # http://php.net/manual/de/language.types.string.php
3155 # - php single quoted strings suppport backslash escapes
3156 # for literal backslash & single quote.
3157 # - use single quotes to avoid string interpolation on
3158 # re-evaluation.
3159 #
3160 1173 $s =~ s/\\/\\\\/sg;
3161 1173 $s =~ s/'/\\'/sg;
3162  
3163 1173 ▶ if (exists $fmt->{escape_ctrl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{'escape_ctrl'}) { } 0 1173 1173
3164 # convert controls other than \t\r\n to "\xNN"
3165 0 $s = escape_ctrl($s, "\x00-\x08\x0b\x0c\x0e-\x1f\x7f");
3166 } else {
3167 1173 $s = "'" . $s . "'";
3168 }
3169 1173 return $s;
3170 }
3171  
3172 8423 ▶sub expand_stmt {
Subroutine expand_stmt: called CC=166 SCAR=60.4
Pod undocumented
3173 8423 my ($self, $out, $s, $fmt) = @_;
3174  
3175 #$self->{log}->('EXPAND', "$s") if $self->{log};
3176  
3177 8423 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 8423 8423
elsif ($s =~ /^#null$/) { } 30 8393 8423
elsif ($s =~ /^#num\d+$/) { } 570 7823 8393
elsif ($s =~ /^#const\d+$/) { } 23 7800 7823
elsif ($s =~ /^#str\d+$/) { } 1172 6628 7800
elsif ($s =~ /^#arr\d+$/) { } 186 6442 6628
elsif ($s =~ /^#fun\d+$/) { } 239 6203 6442
elsif ($s =~ /^#call\d+$/) { } 370 5833 6203
elsif ($s =~ /^#elem\d+$/) { } 275 5558 5833
elsif ($s =~ /^#expr\d+$/) { } 1323 4235 5558
elsif ($s =~ /^#pfx\d+$/) { } 16 4219 4235
elsif ($s =~ /^#obj\d+$/) { } 34 4185 4219
elsif ($s =~ /^#scope\d+$/) { } 4 4181 4185
elsif ($s =~ /^#ns\d+$/) { } 0 4181 4181
elsif ($s =~ /^#inst\d+$/) { } 21 4160 4181
elsif ($s =~ /^#ref\d+$/) { } 8 4152 4160
elsif ($s =~ /^#class\d+$/) { } 56 4096 4152
elsif ($s =~ /^#trait\d+$/) { } 1 4095 4096
elsif ($s =~ /^#fh\d+$/) { } 0 4095 4095
elsif ($s =~ /^#blk\d+$/) { } 1099 2996 4095
elsif ($s =~ /^#stmt\d+$/) { } 537 2459 2996
elsif (is_variable($s)) { } 1827 632 2459
3178 0 $self->{warn}->('expand', "undefined symbol");
3179 0 push(@$out, '<UNDEF>');
3180 } elsif ($s =~ /^#null$/) {
3181 30 push(@$out, 'null');
3182 } elsif ($s =~ /^#num\d+$/) {
3183 570 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 570 0 570
3184 570 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 570 0 570
3185 570 $s = $self->{strmap}->{$s};
3186 }
3187 }
3188 570 push(@$out, $s);
3189 } elsif ($s =~ /^#const\d+$/) {
3190 23 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 23 0 23
3191 23 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 23 0 23
3192 23 $s = $self->{strmap}->{$s};
3193 }
3194 }
3195 23 push(@$out, $s);
3196 } elsif ($s =~ /^#str\d+$/) {
3197 1172 ▶ if (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"strmap"}{$s}) 1172 0 1172
3198 1172 ▶ unless (exists $fmt->{unified}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $fmt->{"unified"}) 1172 0 1172
3199 1172 $s = $self->{strmap}->{$s};
3200 1172 ▶ if (exists $fmt->{mask_eval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"mask_eval"}) 0 1172 1172
3201 # substitute 'eval' in strings on output
3202 0 $s =~ s/(^|\W)eval(\s*\()/$1$fmt->{mask_eval}$2/g;
3203 }
3204 1172 ▶ if (exists $fmt->{max_strlen} && (length($s) > $fmt->{max_strlen})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}) 0 1172 1172
Condition33%1/3
exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}
!ll&&!rl&&r
117200
MC/DC0%0/2
exists $fmt->{"max_strlen"} and length $s > $fmt->{"max_strlen"}
exists $fmt->{"max_strlen"} length $s > $fmt->{"max_strlen"}
Truth table33%1/3
A and B
A= exists $fmt->{"max_strlen"}B= length $s > $fmt->{"max_strlen"}
ABresult
0X0
100
111
3205 0 $s = substr($s, 0, $fmt->{max_strlen}-2).'..';
3206 }
3207 1172 $s = escape_str($s, $fmt);
3208 }
3209 }
3210 1172 push(@$out, $s);
3211 } elsif ($s =~ /^#arr\d+$/) {
3212 186 my $arr = $self->{strmap}{$s};
3213 186 my $keys = $arr->get_keys();
3214 186 push(@$out, 'array');
3215 186 push(@$out, '(');
3216  
3217 186 foreach my $k (@$keys) {
3218 278 my $val = $arr->val($k);
3219 278 $self->expand_stmt($out, $k, $fmt);
3220 278 push(@$out, '=>');
3221 278 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 278 0 278
3222 278 $self->expand_stmt($out, $val, $fmt);
3223 }
3224 278 push(@$out, ',');
3225 }
3226 186 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 162 24 186
3227 162 pop(@$out);
3228 }
3229 186 push(@$out, ')');
3230 } elsif ($s =~ /^#fun\d+$/) {
3231 239 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
3232  
3233 239 foreach my $k (sort grep { exists $php_modifiers{$_} } keys %$p) {
3234 25 push(@$out, $k);
3235 }
3236 239 push(@$out, 'function');
3237 239 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 213 26 239
3238 213 push(@$out, $f);
3239 }
3240 239 push(@$out, '(');
3241 239 foreach my $k (@$a) {
3242 #push(@$out, $k);
3243 104 $self->expand_stmt($out, $k, $fmt);
3244 104 push(@$out, ',');
3245 }
3246 239 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 100 139 239
3247 100 pop(@$out);
3248 }
3249 239 push(@$out, ')');
3250 239 $self->expand_stmt($out, $b, $fmt);
3251 #push(@$out, '{');
3252 #foreach my $k (@$b) {
3253 # $self->expand_stmt($out, $k, $fmt);
3254 # push(@$out, ';');
3255 #}
3256 #if (scalar @$b > 0) {
3257 # pop(@$out);
3258 #}
3259 #push(@$out, '}');
3260 } elsif ($s =~ /^#call\d+$/) {
3261 370 my ($f, $a) = @{$self->{strmap}->{$s}};
3262  
3263 370 ▶ if ($f =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /^#fun\d+$/) { } 4 366 370
3264 # anonymous function call requires braces around func
3265 4 push(@$out, '(');
3266 4 $self->expand_stmt($out, $f, $fmt);
3267 4 push(@$out, ')');
3268 } else {
3269 366 $self->expand_stmt($out, $f, $fmt);
3270 }
3271 370 push(@$out, '(');
3272 370 foreach my $k (@$a) {
3273 198 $self->expand_stmt($out, $k, $fmt);
3274 198 push(@$out, ',');
3275 }
3276 370 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 169 201 370
3277 169 pop(@$out);
3278 }
3279 370 push(@$out, ')');
3280 } elsif ($s =~ /^#elem\d+$/) {
3281 275 my ($v, $i) = @{$self->{strmap}->{$s}};
3282  
3283 275 $self->expand_stmt($out, $v, $fmt);
3284 275 push(@$out, '[');
3285 275 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 254 21 275
3286 254 $self->expand_stmt($out, $i, $fmt);
3287 }
3288 275 push(@$out, ']');
3289 } elsif ($s =~ /^#expr\d+$/) {
3290 # if v1 missing: prefix op
3291 # if v2 missing: postfix op
3292 1323 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
3293  
3294 1323 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 1272 51 1323
3295 1272 ▶ if ($v1 =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v1 =~ /^#expr\d+$/) { } 30 1242 1272
elsif ($op eq '=' and $v1 =~ /^#arr\d+$/) { } 6 1236 1242
3296 30 my ($vop, $vv1, $vv2) = @{$self->{strmap}->{$v1}};
3297 30 my $add_brace = 0;
3298 30 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 6 24 30
Condition100%3/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
6186
MC/DC100%2/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table100%3/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
3299 6 $add_brace = 1;
3300 }
3301 30 ▶ if (exists $op_unary{$vop} && ($vop ne 'new') && (is_variable($vv2) || ($vv2 =~ /^#elem\d+$/) || ($vv2 =~ /^#call\d+$/))) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/) 0 30 30
Condition16%2/12
exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
!ll&&!rl&&r
3000
exists $op_unary{$vop} and $vop ne "new"
!ll&&!rl&&r
3000
is_variable($vv2) or $vv2 =~ /^#elem\d+$/ or $vv2 =~ /^#call\d+$/
l!l&&r!l&&!r
000
is_variable($vv2) or $vv2 =~ /^#elem\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/5
exists $op_unary{$vop} and $vop ne "new" and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
exists $op_unary{$vop} $vop ne "new" is_variable($vv2) $vv2 =~ /^#elem\d+$/ $vv2 =~ /^#call\d+$/
Truth table16%1/6
A and B and C or D or E
A= exists $op_unary{$vop}B= $vop ne "new"C= is_variable($vv2)D= $vv2 =~ /^#elem\d+$/E= $vv2 =~ /^#call\d+$/
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
3302 0 $add_brace = 0;
3303 }
3304 30 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 6 24 30
3305 6 push(@$out, '(');
3306 }
3307 30 $self->expand_stmt($out, $v1, $fmt);
3308 30 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 6 24 30
3309 6 push(@$out, ')');
3310 }
3311 ▶ } elsif (($op eq '=') && ($v1 =~ /^#arr\d+$/)) {
Condition100%3/3
$op eq "=" and $v1 =~ /^#arr\d+$/
!ll&&!rl&&r
19610406
MC/DC100%2/2
$op eq "=" and $v1 =~ /^#arr\d+$/
$op eq "=" $v1 =~ /^#arr\d+$/
Truth table100%3/3
A and B
A= $op eq "="B= $v1 =~ /^#arr\d+$/
ABresult
0X0
100
111
3312 # output lhs array() as list() and allow empty elems
3313 #
3314 6 my $arr = $self->{strmap}{$v1};
3315 6 my $keys = $arr->get_keys();
3316 6 my $numerical = $arr->is_numerical();
3317 6 push(@$out, 'list');
3318 6 push(@$out, '(');
3319  
3320 6 foreach my $k (@$keys) {
3321 13 my $val = $arr->val($k);
3322 13 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 12 1 13
3323 12 ▶ unless ($numerical) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($numerical) 0 12 12
3324 0 $self->expand_stmt($out, $k, $fmt);
3325 0 push(@$out, '=>');
3326 }
3327 12 $self->expand_stmt($out, $val, $fmt);
3328 }
3329 13 push(@$out, ',');
3330 }
3331 6 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 6 0 6
3332 6 pop(@$out);
3333 }
3334 6 push(@$out, ')');
3335 } else {
3336 1236 $self->expand_stmt($out, $v1, $fmt);
3337 }
3338 }
3339 1323 push(@$out, $op);
3340 1323 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 1288 35 1323
3341 1288 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 24 1264 1288
3342 24 push(@$out, '{');
3343 }
3344 1288 ▶ if ($v2 =~ /^#expr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2 =~ /^#expr\d+$/) { } 96 1192 1288
3345 96 my ($vop, $vv1, $vv2) = @{$self->{strmap}->{$v2}};
3346 96 my $add_brace = 0;
3347 96 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 8 88 96
Condition100%6/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
8628
$op ne "?" and $op ne "="
!ll&&!rl&&r
87810
MC/DC100%3/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table100%4/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
3348 8 $add_brace = 1;
3349 }
3350 96 ▶ if (exists $op_unary{$vop} && (is_variable($vv2) || ($vv2 =~ /^#elem\d+$/) || ($vv2 =~ /^#call\d+$/))) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/) 8 88 96
Condition66%6/9
exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
!ll&&!rl&&r
75138
is_variable($vv2) or $vv2 =~ /^#elem\d+$/ or $vv2 =~ /^#call\d+$/
l!l&&r!l&&!r
0813
is_variable($vv2) or $vv2 =~ /^#elem\d+$/
l!l&&r!l&&!r
0021
MC/DC50%2/4
exists $op_unary{$vop} and is_variable($vv2) || $vv2 =~ /^#elem\d+$/ || $vv2 =~ /^#call\d+$/
exists $op_unary{$vop} is_variable($vv2) $vv2 =~ /^#elem\d+$/ $vv2 =~ /^#call\d+$/
Truth table60%3/5
A and B or C or D
A= exists $op_unary{$vop}B= is_variable($vv2)C= $vv2 =~ /^#elem\d+$/D= $vv2 =~ /^#call\d+$/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
3351 8 $add_brace = 0;
3352 }
3353 96 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 7 89 96
3354 7 push(@$out, '(');
3355 }
3356 96 $self->expand_stmt($out, $v2, $fmt);
3357 96 ▶ if ($add_brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_brace) 7 89 96
3358 7 push(@$out, ')');
3359 }
3360 } else {
3361 1192 $self->expand_stmt($out, $v2, $fmt);
3362 }
3363 1288 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 24 1264 1288
3364 24 push(@$out, '}');
3365 }
3366 }
3367 } elsif ($s =~ /^#pfx\d+$/) {
3368 16 my $pfx = $self->{strmap}->{$s};
3369 16 foreach my $k (sort keys %$pfx) {
3370 16 push(@$out, $k);
3371 }
3372 } elsif ($s =~ /^#obj\d+$/) {
3373 34 my ($o, $m) = @{$self->{strmap}->{$s}};
3374  
3375 34 ▶ if ($o =~ /^#call\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /^#call\d+$/) { } 0 34 34
3376 0 push(@$out, '(');
3377 0 $self->expand_stmt($out, $o, $fmt);
3378 0 push(@$out, ')');
3379 } else {
3380 34 $self->expand_stmt($out, $o, $fmt);
3381 }
3382 34 push(@$out, '->');
3383 34 ▶ if (exists $self->{strmap}->{$m} && is_strval($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$m} and is_strval($m)) { } 0 34 34
Condition33%1/3
exists $self->{"strmap"}{$m} and is_strval($m)
!ll&&!rl&&r
3400
MC/DC0%0/2
exists $self->{"strmap"}{$m} and is_strval($m)
exists $self->{"strmap"}{$m} is_strval($m)
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$m}B= is_strval($m)
ABresult
0X0
100
111
3384 0 my $sym = $self->{strmap}->{$m};
3385 0 ▶ if (is_symbol($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_symbol($sym)) { } 0 0 0
3386 0 push(@$out, $sym);
3387 } else {
3388 0 $sym = escape_str($sym, $fmt);
3389  
3390 0 push(@$out, '{');
3391 0 push(@$out, $sym);
3392 0 push(@$out, '}');
3393 }
3394 } else {
3395 34 $self->expand_stmt($out, $m, $fmt);
3396 }
3397 } elsif ($s =~ /^#scope\d+$/) {
3398 4 my ($c, $e) = @{$self->{strmap}->{$s}};
3399  
3400 4 ▶ if (exists $self->{strmap}->{$c} && is_symbol($self->{strmap}->{$c})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$c} and is_symbol($self->{'strmap'}{$c})) { } 0 4 4
Condition33%1/3
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
!ll&&!rl&&r
400
MC/DC0%0/2
exists $self->{"strmap"}{$c} and is_symbol($self->{"strmap"}{$c})
exists $self->{"strmap"}{$c} is_symbol($self->{"strmap"}{$c})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$c}B= is_symbol($self->{"strmap"}{$c})
ABresult
0X0
100
111
3401 0 push(@$out, $self->{strmap}->{$c});
3402 } else {
3403 4 $self->expand_stmt($out, $c, $fmt);
3404 }
3405 4 push(@$out, '::');
3406 4 ▶ if (exists $self->{strmap}->{$e} && is_symbol($self->{strmap}->{$e})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$e} and is_symbol($self->{'strmap'}{$e})) { } 0 4 4
Condition33%1/3
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
!ll&&!rl&&r
400
MC/DC0%0/2
exists $self->{"strmap"}{$e} and is_symbol($self->{"strmap"}{$e})
exists $self->{"strmap"}{$e} is_symbol($self->{"strmap"}{$e})
Truth table33%1/3
A and B
A= exists $self->{"strmap"}{$e}B= is_symbol($self->{"strmap"}{$e})
ABresult
0X0
100
111
3407 0 push(@$out, $self->{strmap}->{$e});
3408 } else {
3409 4 $self->expand_stmt($out, $e, $fmt);
3410 }
3411 } elsif ($s =~ /^#ns\d+$/) {
3412 0 my ($n, $e) = @{$self->{strmap}->{$s}};
3413  
3414 0 ▶ if (defined $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n) 0 0 0
3415 0 ▶ if (exists $self->{strmap}->{$n} && is_symbol($self->{strmap}->{$n})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'strmap'}{$n} and is_symbol($self->{'strmap'}{$n})) { } 0 0 0
Condition0%0/3
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"strmap"}{$n} and is_symbol($self->{"strmap"}{$n})
exists $self->{"strmap"}{$n} is_symbol($self->{"strmap"}{$n})
Truth table0%0/3
A and B
A= exists $self->{"strmap"}{$n}B= is_symbol($self->{"strmap"}{$n})
ABresult
0X0
100
111
3416 0 push(@$out, $self->{strmap}->{$n});
3417 } else {
3418 0 $self->expand_stmt($out, $n, $fmt);
3419 }
3420 }
3421 0 push(@$out, '\\');
3422 0 $self->expand_stmt($out, $e, $fmt);
3423 } elsif ($s =~ /^#inst\d+$/) {
3424 21 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
3425  
3426 21 push(@$out, 'new');
3427 21 $self->expand_stmt($out, $f, $fmt);
3428 } elsif ($s =~ /^#ref\d+$/) {
3429 8 my ($v) = @{$self->{strmap}->{$s}};
3430  
3431 8 push(@$out, '&');
3432 8 $self->expand_stmt($out, $v, $fmt);
3433 } elsif ($s =~ /^#class\d+$/) {
3434 56 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
3435  
3436 56 foreach my $k (sort grep { exists $php_modifiers{$_} } keys %$p) {
3437 0 push(@$out, $k);
3438 }
3439 56 push(@$out, 'class');
3440 56 push(@$out, $c);
3441  
3442 56 ▶ if (exists $p->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"parent"}) 0 56 56
3443 0 push(@$out, 'extends');
3444 0 push(@$out, $p->{parent});
3445 }
3446 56 $self->expand_stmt($out, $b, $fmt);
3447 } elsif ($s =~ /^#trait\d+$/) {
3448 1 my ($t, $b) = @{$self->{strmap}->{$s}};
3449  
3450 1 push(@$out, 'trait');
3451 1 push(@$out, $t);
3452 1 $self->expand_stmt($out, $b, $fmt);
3453 } elsif ($s =~ /^#fh\d+$/) {
3454 0 my $f = $self->{strmap}->{$s}{name};
3455 0 my $m = $self->{strmap}->{$s}{mode};
3456 0 my $p = $self->{strmap}->{$s}{pos};
3457 0 push(@$out, 'FH');
3458 0 push(@$out, '(');
3459 0 push(@$out, $f);
3460 0 push(@$out, ',');
3461 0 push(@$out, $m);
3462 0 push(@$out, ')');
3463 } elsif ($s =~ /^#blk\d+$/) {
3464 1099 my ($type, $a) = @{$self->{strmap}->{$s}};
3465 1099 ▶ if ($type eq 'expr') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'expr') { } 93 1006 1099
elsif ($type eq 'flat') { } 500 506 1006
elsif ($type eq 'case') { } 8 498 506
elsif ($type eq 'brace') { } 1 497 498
3466 93 foreach my $k (@$a) {
3467 86 $self->expand_stmt($out, $k, $fmt);
3468 86 push(@$out, ',');
3469 }
3470 93 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 82 11 93
3471 82 pop(@$out);
3472 }
3473 } elsif ($type eq 'flat') {
3474 500 foreach my $k (@$a) {
3475 1295 $self->expand_stmt($out, $k, $fmt);
3476 1295 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 1295 1295
3477 0 next; # avoid ;
3478 }
3479 1295 ▶ if (($out->[-1] ne '}') && ($out->[-1] ne ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}" and $out->[-1] ne ":") 1040 255 1295
Condition100%3/3
$out->[-1] ne "}" and $out->[-1] ne ":"
!ll&&!rl&&r
25411040
MC/DC100%2/2
$out->[-1] ne "}" and $out->[-1] ne ":"
$out->[-1] ne "}" $out->[-1] ne ":"
Truth table100%3/3
A and B
A= $out->[-1] ne "}"B= $out->[-1] ne ":"
ABresult
0X0
100
111
3480 1040 push(@$out, ';');
3481 }
3482 }
3483 500 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 433 67 500
Condition100%3/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
463433
MC/DC100%2/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table100%3/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3484 433 ▶ pop(@$out) if $fmt->{avoid_semicolon};
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->{"avoid_semicolon"} 0 433 433
3485 }
3486 } elsif ($type eq 'case') {
3487 8 foreach my $k (@$a) {
3488 8 $self->expand_stmt($out, $k, $fmt);
3489 8 push(@$out, ';');
3490 }
3491 8 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 8 0 8
3492 8 pop(@$out);
3493 }
3494 } elsif ($type eq 'brace') {
3495 1 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) { } 1 0 1
3496 1 $self->expand_stmt($out, $a->[0], $fmt);
3497 } else {
3498 0 push(@$out, '(');
3499 0 foreach my $k (@$a) {
3500 0 $self->expand_stmt($out, $k, $fmt);
3501 0 ▶ if ($out->[-1] ne ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne ")") 0 0 0
3502 0 push(@$out, ';');
3503 }
3504 }
3505 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3506 0 pop(@$out);
3507 }
3508 0 push(@$out, ')');
3509 }
3510 } else {
3511 497 push(@$out, '{');
3512 497 foreach my $k (@$a) {
3513 665 $self->expand_stmt($out, $k, $fmt);
3514 665 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 16 649 665
3515 16 next; # avoid ;
3516 }
3517 649 ▶ if (($out->[-1] ne '}') && ($out->[-1] ne ':')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}" and $out->[-1] ne ":") 533 116 649
Condition66%2/3
$out->[-1] ne "}" and $out->[-1] ne ":"
!ll&&!rl&&r
1160533
MC/DC50%1/2
$out->[-1] ne "}" and $out->[-1] ne ":"
$out->[-1] ne "}" $out->[-1] ne ":"
Truth table66%2/3
A and B
A= $out->[-1] ne "}"B= $out->[-1] ne ":"
ABresult
0X0
100
111
3518 533 push(@$out, ';');
3519 }
3520 }
3521 497 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 382 115 497
Condition100%3/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
1897382
MC/DC100%2/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table100%3/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
3522 382 ▶ pop(@$out) if $fmt->{avoid_semicolon};
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->{"avoid_semicolon"} 0 382 382
3523 }
3524 497 push(@$out, '}');
3525 }
3526 } elsif ($s =~ /^#stmt\d+$/) {
3527 537 my $cmd = $self->{strmap}->{$s}->[0];
3528 537 ▶ if ($cmd eq 'echo') {
Branch: 21 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 183 354 537
elsif ($cmd eq 'print') { } 0 354 354
elsif ($cmd eq 'namespace') { } 10 344 354
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 344 344
elsif ($cmd eq 'use') { } 0 344 344
elsif ($cmd eq 'global') { } 6 338 344
elsif ($cmd eq 'static') { } 11 327 338
elsif ($cmd eq 'const') { } 9 318 327
elsif ($cmd eq 'unset') { } 5 313 318
elsif ($cmd eq 'return') { } 116 197 313
elsif ($cmd eq 'goto') { } 1 196 197
elsif ($cmd eq 'label') { } 1 195 196
elsif ($cmd eq 'throw') { } 0 195 195
elsif ($cmd eq 'if') { } 103 92 195
elsif ($cmd eq 'while') { } 16 76 92
elsif ($cmd eq 'do') { } 8 68 76
elsif ($cmd eq 'for') { } 31 37 68
elsif ($cmd eq 'foreach') { } 29 8 37
elsif ($cmd eq 'switch') { } 6 2 8
elsif ($cmd eq 'case') { } 0 2 2
elsif ($cmd eq 'try') { } 1 1 2
3529 183 my $a = $self->{strmap}->{$s}->[1];
3530 183 push(@$out, $cmd);
3531 183 foreach my $k (@$a) {
3532 186 $self->expand_stmt($out, $k, $fmt);
3533 186 push(@$out, ',');
3534 }
3535 183 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 183 0 183
3536 183 pop(@$out);
3537 }
3538 #push(@$out, ';');
3539 } elsif ($cmd eq 'print') {
3540 0 my $arg = $self->{strmap}->{$s}->[1];
3541 0 push(@$out, $cmd);
3542 0 $self->expand_stmt($out, $arg, $fmt);
3543 } elsif ($cmd eq 'namespace') {
3544 10 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
3545 10 push(@$out, $cmd);
3546 10 ▶ if ($arg ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne "") 9 1 10
3547 9 push(@$out, $arg);
3548 }
3549 10 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 2 8 10
3550 2 $self->expand_stmt($out, $block, $fmt);
3551 }
3552 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
3553 0 my $arg = $self->{strmap}->{$s}->[1];
3554 0 push(@$out, $cmd);
3555 0 $self->expand_stmt($out, $arg, $fmt);
3556 } elsif ($cmd eq 'use') {
3557 0 my $a = $self->{strmap}->{$s}->[1];
3558 0 push(@$out, $cmd);
3559 0 foreach my $k (@$a) {
3560 0 $self->expand_stmt($out, $k, $fmt);
3561 0 push(@$out, ',');
3562 }
3563 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
3564 0 pop(@$out);
3565 }
3566 } elsif ($cmd eq 'global') {
3567 6 my $a = $self->{strmap}->{$s}->[1];
3568 6 push(@$out, $cmd);
3569 6 foreach my $k (@$a) {
3570 6 $self->expand_stmt($out, $k, $fmt);
3571 6 push(@$out, ',');
3572 }
3573 6 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 6 0 6
3574 6 pop(@$out);
3575 }
3576 } elsif ($cmd eq 'static') {
3577 11 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
3578  
3579 #push(@$out, join(' ', sort keys %$p));
3580 11 push(@$out, join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd));
3581 #push(@$out, $cmd);
3582 11 foreach my $k (@$a) {
3583 11 $self->expand_stmt($out, $k, $fmt);
3584 11 push(@$out, ',');
3585 }
3586 11 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 11 0 11
3587 11 pop(@$out);
3588 }
3589 } elsif ($cmd eq 'const') {
3590 9 my ($a, $p) = @{$self->{strmap}->{$s}}[1..2];
3591  
3592 #push(@$out, join(' ', sort keys %$p));
3593 9 push(@$out, join(' ', (grep { $_ ne $cmd } sort keys %$p), $cmd));
3594 #push(@$out, $cmd);
3595 9 foreach my $k (@$a) {
3596 9 $self->expand_stmt($out, $k, $fmt);
3597 9 push(@$out, ',');
3598 }
3599 9 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 9 0 9
3600 9 pop(@$out);
3601 }
3602 } elsif ($cmd eq 'unset') {
3603 5 my $a = $self->{strmap}->{$s}->[1];
3604 5 push(@$out, $cmd);
3605 5 push(@$out, '(');
3606 5 foreach my $k (@$a) {
3607 5 $self->expand_stmt($out, $k, $fmt);
3608 5 push(@$out, ',');
3609 }
3610 5 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 5 0 5
3611 5 pop(@$out);
3612 }
3613 5 push(@$out, ')');
3614 } elsif ($cmd eq 'return') {
3615 116 my $a = $self->{strmap}->{$s}->[1];
3616 116 push(@$out, $cmd);
3617 116 $self->expand_stmt($out, $a, $fmt);
3618 } elsif ($cmd eq 'goto') {
3619 1 my $a = $self->{strmap}->{$s}->[1];
3620 1 push(@$out, $cmd);
3621 1 $self->expand_stmt($out, $a, $fmt);
3622 } elsif ($cmd eq 'label') {
3623 1 my $a = $self->{strmap}->{$s}->[1];
3624 1 $self->expand_stmt($out, $a, $fmt);
3625 1 push(@$out, ':');
3626 } elsif ($cmd eq 'throw') {
3627 0 my $arg = $self->{strmap}->{$s}->[1];
3628 0 push(@$out, $cmd);
3629 0 $self->expand_stmt($out, $arg, $fmt);
3630 } elsif ($cmd eq 'if') {
3631 103 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
3632  
3633 103 push(@$out, $cmd);
3634 103 push(@$out, '(');
3635 103 $self->expand_stmt($out, $cond, $fmt);
3636 103 push(@$out, ')');
3637 103 $self->expand_stmt($out, $then, $fmt);
3638 103 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 14 89 103
3639 14 push(@$out, 'else');
3640  
3641 # remove block around 'if else'
3642 #
3643 14 ▶ my $stmts = is_block($else) ? $self->{strmap}->{$else}->[1] : [];
Branch: 1 branch
BranchTrueFalseTotal
is_block($else) ? : 14 0 14
3644 14 ▶ if ((@$stmts == 1) && ($stmts->[0] =~ /#stmt\d+$/) && ($self->{strmap}->{$stmts->[0]}->[0] eq 'if')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{'strmap'}{$stmts->[0]}[0] eq 'if') { } 5 9 14
Condition100%6/6
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{"strmap"}{$stmts->[0]}[0] eq "if"
!ll&&!rl&&r
635
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/
!ll&&!rl&&r
158
MC/DC100%3/3
@$stmts == 1 and $stmts->[0] =~ /#stmt\d+$/ and $self->{"strmap"}{$stmts->[0]}[0] eq "if"
@$stmts == 1 $stmts->[0] =~ /#stmt\d+$/ $self->{"strmap"}{$stmts->[0]}[0] eq "if"
Truth table100%4/4
A and B and C
A= @$stmts == 1B= $stmts->[0] =~ /#stmt\d+$/C= $self->{"strmap"}{$stmts->[0]}[0] eq "if"
ABCresult
0XX0
10X0
1100
1111
3645 5 $self->expand_stmt($out, $stmts->[0], $fmt);
3646 } else {
3647 9 $self->expand_stmt($out, $else, $fmt);
3648 }
3649 }
3650 } elsif ($cmd eq 'while') {
3651 16 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3652  
3653 16 push(@$out, $cmd);
3654 16 push(@$out, '(');
3655 16 $self->expand_stmt($out, $cond, $fmt);
3656 16 push(@$out, ')');
3657 16 $self->expand_stmt($out, $block, $fmt);
3658 } elsif ($cmd eq 'do') {
3659 8 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
3660  
3661 8 push(@$out, $cmd);
3662 8 $self->expand_stmt($out, $block, $fmt);
3663 8 push(@$out, 'while');
3664 8 push(@$out, '(');
3665 8 $self->expand_stmt($out, $cond, $fmt);
3666 8 push(@$out, ')');
3667 } elsif ($cmd eq 'for') {
3668 31 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
3669  
3670 31 push(@$out, $cmd);
3671 31 push(@$out, '(');
3672 31 $self->expand_stmt($out, $pre, $fmt);
3673 31 push(@$out, ';');
3674 31 $self->expand_stmt($out, $cond, $fmt);
3675 31 push(@$out, ';');
3676 31 $self->expand_stmt($out, $post, $fmt);
3677 31 push(@$out, ')');
3678 31 $self->expand_stmt($out, $block, $fmt);
3679 } elsif ($cmd eq 'foreach') {
3680 29 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
3681  
3682 29 push(@$out, $cmd);
3683 29 push(@$out, '(');
3684 29 $self->expand_stmt($out, $expr, $fmt);
3685 29 push(@$out, 'as');
3686 29 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 19 10 29
3687 19 $self->expand_stmt($out, $key, $fmt);
3688 19 push(@$out, '=>');
3689 }
3690 29 $self->expand_stmt($out, $value, $fmt);
3691 29 push(@$out, ')');
3692 29 $self->expand_stmt($out, $block, $fmt);
3693 } elsif ($cmd eq 'switch') {
3694 6 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
3695  
3696 6 push(@$out, $cmd);
3697 6 push(@$out, '(');
3698 6 $self->expand_stmt($out, $expr, $fmt);
3699 6 push(@$out, ')');
3700 6 push(@$out, '{');
3701 6 foreach my $e (@$cases) {
3702 8 my $c = $e->[0];
3703 8 my $b = $e->[1];
3704 8 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) { } 8 0 8
3705 8 push(@$out, 'case');
3706 8 $self->expand_stmt($out, $c, $fmt);
3707 8 push(@$out, ':');
3708 } else {
3709 0 push(@$out, 'default');
3710 0 push(@$out, ':');
3711 }
3712 8 $self->expand_stmt($out, $b, $fmt);
3713 8 push(@$out, ';');
3714 }
3715 6 push(@$out, '}');
3716 } elsif ($cmd eq 'case') {
3717 0 my $expr = $self->{strmap}->{$s}->[1];
3718 0 ▶ if (!defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $expr) { } 0 0 0
3719 0 push(@$out, 'default');
3720 0 push(@$out, ':');
3721 } else {
3722 0 push(@$out, 'case');
3723 0 $self->expand_stmt($out, $expr, $fmt);
3724 0 push(@$out, ':');
3725 }
3726 } elsif ($cmd eq 'try') {
3727 1 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
3728  
3729 1 push(@$out, $cmd);
3730 1 $self->expand_stmt($out, $try, $fmt);
3731 1 foreach my $c (@$catches) {
3732 1 my $e = $c->[0];
3733 1 my $b = $c->[1];
3734 1 push(@$out, 'catch');
3735 1 push(@$out, '(');
3736 1 $self->expand_stmt($out, $e, $fmt);
3737 1 push(@$out, ')');
3738 1 $self->expand_stmt($out, $b, $fmt);
3739 }
3740 1 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 1 0 1
3741 1 push(@$out, 'finally');
3742 1 $self->expand_stmt($out, $finally, $fmt);
3743 }
3744 } else {
3745 1 push(@$out, $cmd);
3746 }
3747 } elsif (is_variable($s)) {
3748 1827 my ($global) = global_split($s);
3749 1827 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) { } 35 1792 1827
3750 35 my ($sym) = $global =~ /^\$(.*)$/;
3751 35 push(@$out, '$GLOBALS');
3752 35 push(@$out, '[');
3753 35 push(@$out, '\'' . $sym . '\'');
3754 35 push(@$out, ']');
3755 } else {
3756 1792 my ($class, $sym) = inst_split($s);
3757 1792 ▶ if (defined $class) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $class) { } 14 1778 1792
elsif ($s eq '$') { } 4 1774 1778
elsif (not is_strict_variable($s)) { } 1 1773 1774
3758 14 push(@$out, $class);
3759 14 push(@$out, '::');
3760 14 push(@$out, $sym);
3761 } elsif ($s eq '$') {
3762 4 push(@$out, '$');
3763 4 push(@$out, '{');
3764 4 push(@$out, 'null');
3765 4 push(@$out, '}');
3766 } elsif (!is_strict_variable($s)) {
3767 1 ($sym) = $s =~ /^\$(.*)$/;
3768 1 $sym = escape_str($sym, $fmt);
3769  
3770 1 push(@$out, '$');
3771 1 push(@$out, '{');
3772 1 push(@$out, $sym);
3773 1 push(@$out, '}');
3774 } else {
3775 1773 push(@$out, $s);
3776 }
3777 }
3778 } else {
3779 632 my ($class, $sym) = method_split($s);
3780 632 ▶ if (defined $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) { } 12 620 632
3781 12 ▶ if ($class =~ /^(#inst\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^(#inst\d+)$/) { } 0 12 12
3782 0 $self->expand_stmt($out, $class, $fmt);
3783 0 push(@$out, '->');
3784 0 push(@$out, $sym);
3785 } else {
3786 12 push(@$out, $class);
3787 12 push(@$out, '::');
3788 12 push(@$out, $sym);
3789 }
3790 } else {
3791 620 push(@$out, $s);
3792 }
3793 }
3794 8423 return;
3795 }
3796  
3797 0 ▶sub expand_formatted {
Subroutine expand_formatted: not called CC=29 SCAR=67.7
Pod undocumented
3798 0 my ($out, $in, $tabs) = @_;
3799 0 my $orgtabs = $tabs;
3800 0 my $spc = "\t" x $tabs;
3801 0 my $val;
3802 my $lastval;
3803 0 my $varblk = 0;
3804  
3805 # insert newlines and indent {}-blocks
3806 #
3807 0 while (1) {
3808 0 my $val = shift @$in;
3809 0 my $isfor = 0;
3810 0 my $isswitch = 0;
3811 0 my $iscase = 0;
3812 0 my $isfunc = 0;
3813 0 my $exprblk = 0;
3814  
3815 0 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
3816 0 return;
3817 }
3818 0 ▶ if ($val eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "}") 0 0 0
3819 0 return;
3820 }
3821 0 push(@$out, $spc);
3822 0 ▶ STMT: while(defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
3823 0 ▶ if ($val =~ /^(case|default)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(case|default)$/) { } 0 0 0
elsif ($val =~ /^(function|class)$/) { } 0 0 0
3824 0 $iscase = 1;
3825 } elsif ($val =~ /^(function|class)$/) {
3826 0 $isfunc = 1;
3827 }
3828 0 ▶ if ((scalar @$in > 0) && ($in->[0] =~ /^(case|default)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$in > 0 and $in->[0] =~ /^(case|default)$/) 0 0 0
Condition0%0/3
scalar @$in > 0 and $in->[0] =~ /^(case|default)$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$in > 0 and $in->[0] =~ /^(case|default)$/
scalar @$in > 0 $in->[0] =~ /^(case|default)$/
Truth table0%0/3
A and B
A= scalar @$in > 0B= $in->[0] =~ /^(case|default)$/
ABresult
0X0
100
111
3829 0 $tabs = $orgtabs;
3830 0 $spc = "\t" x $tabs;
3831 }
3832 0 push(@$out, $val);
3833 0 ▶ if (($val eq '{') && defined $lastval && ($lastval eq '$')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($val eq '{' and defined $lastval and $lastval eq '$') { } 0 0 0
elsif ($val eq '(') { } 0 0 0
elsif ($val eq '{') { } 0 0 0
elsif ($val eq ';') { } 0 0 0
elsif ($val eq ':') { } 0 0 0
Condition0%0/6
$val eq "{" and defined $lastval and $lastval eq "\$"
!ll&&!rl&&r
000
$val eq "{" and defined $lastval
!ll&&!rl&&r
000
MC/DC0%0/3
$val eq "{" and defined $lastval and $lastval eq "\$"
$val eq "{" defined $lastval $lastval eq "\$"
Truth table0%0/4
A and B and C
A= $val eq "{"B= defined $lastvalC= $lastval eq "\$"
ABCresult
0XX0
10X0
1100
1111
3834 0 $varblk++;
3835 } elsif ($val eq '(') {
3836 0 ▶ if (defined $lastval && ($lastval eq 'for')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $lastval and $lastval eq 'for') { } 0 0 0
elsif (defined $lastval and $lastval eq 'switch') { } 0 0 0
Condition0%0/3
defined $lastval and $lastval eq "for"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lastval and $lastval eq "for"
defined $lastval $lastval eq "for"
Truth table0%0/3
A and B
A= defined $lastvalB= $lastval eq "for"
ABresult
0X0
100
111
3837 0 $isfor = 1;
3838 ▶ } elsif (defined $lastval && ($lastval eq 'switch')) {
Condition0%0/3
defined $lastval and $lastval eq "switch"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lastval and $lastval eq "switch"
defined $lastval $lastval eq "switch"
Truth table0%0/3
A and B
A= defined $lastvalB= $lastval eq "switch"
ABresult
0X0
100
111
3839 0 $isswitch = 1;
3840 }
3841 0 $exprblk++;
3842 } elsif ($val eq '{') {
3843 0 push(@$out, "\n");
3844 0 ▶ if ($isswitch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isswitch) { } 0 0 0
3845 0 &expand_formatted($out, $in, $tabs);
3846 } else {
3847 0 &expand_formatted($out, $in, $tabs+1);
3848 }
3849 0 push(@$out, $spc);
3850 0 push(@$out, "}");
3851 0 ▶ if ((scalar @$in > 0) && !($in->[0] =~ /^(else|catch|finally|\))$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/) 0 0 0
Condition0%0/3
scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$in > 0 and not $in->[0] =~ /^(else|catch|finally|\))$/
scalar @$in > 0 not $in->[0] =~ /^(else|catch|finally|\))$/
Truth table0%0/3
A and not(B)
A= scalar @$in > 0B= not $in->[0] =~ /^(else|catch|finally|\))$/
ABresult
0X0
100
111
3852 0 push(@$out, "\n");
3853 #push(@$out, "\n") if $isfunc; # blank line after function?
3854 0 last STMT;
3855 }
3856 } elsif ($val eq ';') {
3857 0 ▶ if (!$isfor) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isfor) 0 0 0
3858 0 push(@$out, "\n");
3859 0 last STMT;
3860 }
3861 } elsif ($val eq ':') {
3862 0 ▶ if ($iscase) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iscase) 0 0 0
3863 0 push(@$out, "\n");
3864 0 $iscase = 0;
3865 0 $tabs++;
3866 0 $spc .= "\t";
3867 0 last STMT;
3868 }
3869 }
3870 0 $lastval = $val;
3871 0 $val = shift @$in;
3872  
3873 0 ▶ if (defined $val && ($val eq '}')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq "}") 0 0 0
Condition0%0/3
defined $val and $val eq "}"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val eq "}"
defined $val $val eq "}"
Truth table0%0/3
A and B
A= defined $valB= $val eq "}"
ABresult
0X0
100
111
3874 0 ▶ if ($varblk == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($varblk == 0) 0 0 0
3875 0 return;
3876 }
3877 0 $varblk--;
3878 }
3879 0 ▶ if (defined $val && ($val eq ')')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq ")") 0 0 0
Condition0%0/3
defined $val and $val eq ")"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val eq ")"
defined $val $val eq ")"
Truth table0%0/3
A and B
A= defined $valB= $val eq ")"
ABresult
0X0
100
111
3880 0 $exprblk--;
3881 }
3882 }
3883 }
3884 0 return;
3885 }
3886  
3887 0 ▶sub insert_blanks {
Subroutine insert_blanks: not called CC=16 SCAR=56.1
Pod undocumented
3888 0 my ($in) = @_;
3889 0 my @out = ();
3890 0 my $lastval;
3891  
3892 0 while (1) {
3893 0 my $val = shift @$in;
3894 0 ▶ if (!defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
3895 0 last;
3896 }
3897 # - no blanks in parenthesis or square brackets
3898 # - blank after semicolon or comma
3899 # - blank after most php keywords
3900 # - no blank after function calls
3901 # - no blank after unary ops
3902 # - no blank in pre/post inc/decrement
3903 # - no blank in object/scope reference
3904 #
3905 0 ▶ if (defined $lastval && ($lastval ne "\n") && ($lastval !~ /^\t*$/)) { # zero or more tabs
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/) 0 0 0
Condition0%0/6
defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/
!ll&&!rl&&r
000
defined $lastval and $lastval ne "\n"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $lastval and $lastval ne "\n" and not $lastval =~ /^\t*$/
defined $lastval $lastval ne "\n" not $lastval =~ /^\t*$/
Truth table0%0/4
A and B and not(C)
A= defined $lastvalB= $lastval ne "\n"C= not $lastval =~ /^\t*$/
ABCresult
0XX0
10X0
1100
1111
3906 0 ▶ if ($val !~ /^(\[|\]|\(|\)|\;|\,|\\n|->|::)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $val =~ /^(\[|\]|\(|\)|\;|\,|\\n|->|::)$/) { } 0 0 0
elsif ($val eq '(' and exists $php_keywords{lc $lastval}) { } 0 0 0
elsif ($val eq '(' and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/) { } 0 0 0
3907 0 ▶ if ($lastval !~ /^(\[|\(|\!|\~|->|::)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lastval =~ /^(\[|\(|\!|\~|->|::)$/) 0 0 0
3908 0 ▶ unless ((($val eq '++') || ($val eq '--')) && is_strict_variable($lastval)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val eq "++" || $val eq "--" and is_strict_variable($lastval)) 0 0 0
Condition0%0/6
$val eq "++" || $val eq "--" and is_strict_variable($lastval)
!ll&&!rl&&r
000
$val eq "++" or $val eq "--"
l!l&&r!l&&!r
000
MC/DC0%0/3
$val eq "++" || $val eq "--" and is_strict_variable($lastval)
$val eq "++" $val eq "--" is_strict_variable($lastval)
Truth table0%0/5
A or B and C
A= $val eq "++"B= $val eq "--"C= is_strict_variable($lastval)
ABCresult
00X0
1X00
0100
1X11
0111
3909 0 push(@out, ' ');
3910 }
3911 }
3912 ▶ } elsif (($val eq '(') && exists $php_keywords{lc($lastval)}) {
Condition0%0/3
$val eq "(" and exists $php_keywords{lc $lastval}
!ll&&!rl&&r
000
MC/DC0%0/2
$val eq "(" and exists $php_keywords{lc $lastval}
$val eq "(" exists $php_keywords{lc $lastval}
Truth table0%0/3
A and B
A= $val eq "("B= exists $php_keywords{lc $lastval}
ABresult
0X0
100
111
3913 0 ▶ unless ($lastval =~ /^(array|empty|isset|unset|list)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lastval =~ /^(array|empty|isset|unset|list)$/) 0 0 0
3914 0 push(@out, ' ');
3915 }
3916 ▶ } elsif (($val eq '(') && !is_symbol($lastval) && ($lastval !~ /^(\[|\]|\(|\))$/)) {
Condition0%0/6
$val eq "(" and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/
!ll&&!rl&&r
000
$val eq "(" and not is_symbol($lastval)
!ll&&!rl&&r
000
MC/DC0%0/3
$val eq "(" and not is_symbol($lastval) and not $lastval =~ /^(\[|\]|\(|\))$/
$val eq "(" not is_symbol($lastval) not $lastval =~ /^(\[|\]|\(|\))$/
Truth table0%0/4
A and not(B) and not(C)
A= $val eq "("B= not is_symbol($lastval)C= not $lastval =~ /^(\[|\]|\(|\))$/
ABCresult
0XX0
10X0
1100
1111
3917 0 push(@out, ' ');
3918 }
3919 }
3920 0 push(@out, $val);
3921 0 $lastval = $val;
3922 }
3923 0 return @out;
3924 }
3925  
3926 # convert statements to code (flags are optional)
3927 # {indent} - output indented multiline code
3928 # {unified} - unified #str/#num output
3929 # {mask_eval} - mask eval in strings with pattern
3930 # {escape_ctrl} - escape control characters in output strings
3931 # {avoid_semicolon} - avoid semicolons after braces
3932 # {max_strlen} - max length for strings in output
3933 #
3934 783 ▶sub format_stmt {
Subroutine format_stmt: called CC=7 SCAR=19.7
Pod documented
3935 783 my ($self, $line, $fmt) = @_;
3936 783 my @out = ();
3937 783 ▶ $fmt = {} unless defined $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt 781 2 783
3938  
3939 783 $self->expand_stmt(\@out, $line, $fmt);
3940  
3941 783 ▶ if (!$fmt->{avoid_semicolon} && (scalar @out > 0) && ($out[-1] ne '}') && ($out[-1] ne ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";") 175 608 783
Condition100%9/9
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";"
!ll&&!rl&&r
175433175
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}"
!ll&&!rl&&r
5170608
not $fmt->{"avoid_semicolon"} and scalar @out > 0
!ll&&!rl&&r
14778
MC/DC100%4/4
not $fmt->{"avoid_semicolon"} and scalar @out > 0 and $out[-1] ne "}" and $out[-1] ne ";"
not $fmt->{"avoid_semicolon"} scalar @out > 0 $out[-1] ne "}" $out[-1] ne ";"
Truth table100%5/5
not(A) and B and C and D
A= not $fmt->{"avoid_semicolon"}B= scalar @out > 0C= $out[-1] ne "}"D= $out[-1] ne ";"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3942 175 push(@out, ';');
3943 }
3944 783 ▶ if (exists $fmt->{indent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fmt->{"indent"}) 0 783 783
3945 0 my @tmp = ();
3946 0 expand_formatted(\@tmp, \@out, 0);
3947 0 return join('', insert_blanks(\@tmp));
3948 }
3949 783 return join(' ', @out);
3950 }
3951  
3952 6 ▶use constant HINT_ASSIGN => 0x10000; # variable is assigned to
Subroutine BEGIN: called CC=1 SCAR=0.0
3953 6 ▶use constant HINT_UNSET => 0x20000; # variable is unset
Subroutine BEGIN: called CC=1 SCAR=0.0
3954  
3955 # if expression in block contains an unresolvable variable, then return it
3956 #
3957 5471 ▶sub stmt_info {
Subroutine stmt_info: called CC=107 SCAR=58.1
Pod undocumented
3958 5471 my ($self, $s, $info, $hint) = @_;
3959  
3960 5471 ▶ if ($s =~ /^#blk\d+$/) {
Branch: 18 branches
BranchTrueFalseTotal
if ($s =~ /^#blk\d+$/) { } 681 4790 5471
elsif ($s =~ /^#const\d+$/) { } 12 4778 4790
elsif ($s =~ /^#arr\d+$/) { } 286 4492 4778
elsif ($s =~ /^#fun\d+$/) { } 23 4469 4492
elsif ($s =~ /^#expr\d+$/) { } 482 3987 4469
elsif ($s =~ /^#elem\d+$/) { } 174 3813 3987
elsif ($s =~ /^#obj\d+$/) { } 9 3804 3813
elsif ($s =~ /^#inst\d+$/) { } 19 3785 3804
elsif ($s =~ /^#scope\d+$/) { } 0 3785 3785
elsif ($s =~ /^#ns\d+$/) { } 0 3785 3785
elsif ($s =~ /^#ref\d+$/) { } 0 3785 3785
elsif ($s =~ /^#call\d+$/) { } 295 3490 3785
elsif ($s =~ /^#pfx\d+$/) { } 0 3490 3490
elsif ($s =~ /^#class\d+$/) { } 19 3471 3490
elsif ($s =~ /^#trait\d+$/) { } 0 3471 3471
elsif ($s =~ /^#fh\d+$/) { } 0 3471 3471
elsif ($s =~ /^#stmt\d+$/) { } 582 2889 3471
elsif (is_variable($s)) { } 750 2139 2889
3961 681 my ($type, $a) = @{$self->{strmap}->{$s}};
3962 681 foreach my $stmt (@$a) {
3963 894 $self->stmt_info($stmt, $info);
3964 }
3965 #} elsif ($s =~ /^#num\d+$/) {
3966 # my $v = $self->{strmap}->{$s};
3967 # $info->{nums}{$s} = $v;
3968 #} elsif ($s =~ /^#str\d+$/) {
3969 # my $v = $self->{strmap}->{$s};
3970 # $info->{strs}{$s} = $v;
3971 } elsif ($s =~ /^#const\d+$/) {
3972 12 $s = $self->{strmap}->{$s};
3973 12 $info->{consts}{$s} = 1;
3974 } elsif ($s =~ /^#arr\d+$/) {
3975 286 my $arr = $self->{strmap}{$s};
3976 286 my $keys = $arr->get_keys();
3977 286 my $haskey = 0;
3978  
3979 286 foreach my $k (@$keys) {
3980 457 my $val = $arr->val($k);
3981 457 ▶ unless (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_int_index($k)) 21 436 457
3982 21 $self->stmt_info($k, $info);
3983 }
3984 457 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 457 0 457
3985 457 $self->stmt_info($val, $info);
3986 457 $haskey = 1;
3987 }
3988 }
3989 286 ▶ if ($haskey) {
Branch: 1 branch
BranchTrueFalseTotal
if ($haskey) { } 264 22 286
3990 264 $info->{arrays}{$s} = 'map';
3991 } else {
3992 22 $info->{arrays}{$s} = 'array';
3993 }
3994 } elsif ($s =~ /^#fun\d+$/) {
3995 23 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
3996 23 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) { } 8 15 23
3997 8 $info->{funcs}{$f} = 1;
3998 } else {
3999 15 $info->{funcs}{$s} = 1; # anon func
4000 }
4001 } elsif ($s =~ /^#expr\d+$/) {
4002 482 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
4003 482 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 450 32 482
4004 450 ▶ if (($op eq '=') && ($v1 =~ /^#elem\d+$/) && defined $v2) {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq '=' and $v1 =~ /^#elem\d+$/ and defined $v2) { } 51 399 450
elsif ($op eq '=' and defined $v2 and $v2 =~ /^#call\d+$/) { } 14 385 399
elsif ($op eq '=' and defined $v2) { } 283 102 385
elsif ($op eq '.') { } 30 72 102
elsif ($op eq '++' or $op eq '--') { } 14 58 72
Condition83%5/6
$op eq "=" and $v1 =~ /^#elem\d+$/ and defined $v2
!ll&&!rl&&r
399051
$op eq "=" and $v1 =~ /^#elem\d+$/
!ll&&!rl&&r
10229751
MC/DC66%2/3
$op eq "=" and $v1 =~ /^#elem\d+$/ and defined $v2
$op eq "=" $v1 =~ /^#elem\d+$/ defined $v2
Truth table75%3/4
A and B and C
A= $op eq "="B= $v1 =~ /^#elem\d+$/C= defined $v2
ABCresult
0XX0
10X0
1100
1111
4005 51 my ($v, $i) = @{$self->{strmap}->{$v1}};
4006  
4007 51 ▶ unless (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 34 17 51
4008 17 $self->stmt_info($v1, $info, T_ARRAY|HINT_ASSIGN);
4009 } else {
4010 34 $self->stmt_info($v1, $info, HINT_ASSIGN);
4011 }
4012 ▶ } elsif (($op eq '=') && defined $v2 && ($v2 =~ /^#call\d+$/)) {
Condition83%5/6
$op eq "=" and defined $v2 and $v2 =~ /^#call\d+$/
!ll&&!rl&&r
10228314
$op eq "=" and defined $v2
!ll&&!rl&&r
1020297
MC/DC66%2/3
$op eq "=" and defined $v2 and $v2 =~ /^#call\d+$/
$op eq "=" defined $v2 $v2 =~ /^#call\d+$/
Truth table75%3/4
A and B and C
A= $op eq "="B= defined $v2C= $v2 =~ /^#call\d+$/
ABCresult
0XX0
10X0
1100
1111
4013 14 my ($f, $a) = @{$self->{strmap}->{$v2}};
4014  
4015 14 ▶ if ($f eq 'range') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq 'range') { } 0 14 14
4016 0 $self->stmt_info($v1, $info, T_ARRAY|HINT_ASSIGN);
4017 } else {
4018 14 $self->stmt_info($v1, $info, HINT_ASSIGN);
4019 }
4020 ▶ } elsif (($op eq '=') && defined $v2) {
Condition66%2/3
$op eq "=" and defined $v2
!ll&&!rl&&r
1020283
MC/DC50%1/2
$op eq "=" and defined $v2
$op eq "=" defined $v2
Truth table66%2/3
A and B
A= $op eq "="B= defined $v2
ABresult
0X0
100
111
4021 283 $self->stmt_info($v1, $info, HINT_ASSIGN);
4022 } elsif ($op eq '.') {
4023 30 $self->stmt_info($v1, $info, T_STR);
4024 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition66%2/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
14058
MC/DC50%1/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table66%2/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
4025 14 $self->stmt_info($v1, $info, HINT_ASSIGN);
4026 } else {
4027 58 $self->stmt_info($v1, $info);
4028 }
4029 450 ▶ if ($op eq '=') {
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq '=') { } 348 102 450
elsif ($op eq '++') { } 14 88 102
elsif ($op eq '--') { } 0 88 88
4030 348 my $vb = $self->elem_base($v1);
4031 348 $info->{assigns}{$vb} = 1;
4032 } elsif ($op eq '++') {
4033 14 my $vb = $self->elem_base($v1);
4034 14 $info->{assigns}{$vb} = 1;
4035 } elsif ($op eq '--') {
4036 0 my $vb = $self->elem_base($v1);
4037 0 $info->{assigns}{$vb} = 1;
4038 }
4039 }
4040 482 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 468 14 482
4041 468 ▶ if ($op eq '.') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '.') { } 30 438 468
elsif ($op eq '++' or $op eq '--') { } 1 437 438
4042 30 $self->stmt_info($v2, $info, T_STR);
4043 ▶ } elsif (($op eq '++') || ($op eq '--')) {
Condition66%2/3
$op eq "++" or $op eq "--"
l!l&&r!l&&!r
01437
MC/DC50%1/2
$op eq "++" or $op eq "--"
$op eq "++" $op eq "--"
Truth table66%2/3
A or B
A= $op eq "++"B= $op eq "--"
ABresult
1X1
011
000
4044 1 $self->stmt_info($v2, $info, HINT_ASSIGN);
4045 } else {
4046 437 $self->stmt_info($v2, $info);
4047 }
4048 468 ▶ if ($op eq '++') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '++') { } 0 468 468
elsif ($op eq '--') { } 1 467 468
4049 0 my $vb = $self->elem_base($v2);
4050 0 $info->{assigns}{$vb} = 1;
4051 } elsif ($op eq '--') {
4052 1 my $vb = $self->elem_base($v2);
4053 1 $info->{assigns}{$vb} = 1;
4054 }
4055 }
4056 } elsif ($s =~ /^#elem\d+$/) {
4057 174 my ($v, $i) = @{$self->{strmap}->{$s}};
4058 174 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 174 0 174
4059 174 my $hint_assign = 0;
4060 174 ▶ $hint_assign = HINT_ASSIGN if (defined $hint && ($hint & HINT_ASSIGN));
Branch: 1 branch
BranchTrueFalseTotal
if defined $hint and $hint & 65536 54 120 174
Condition100%3/3
defined $hint and $hint & 65536
!ll&&!rl&&r
982254
MC/DC100%2/2
defined $hint and $hint & 65536
defined $hint $hint & 65536
Truth table100%3/3
A and B
A= defined $hintB= $hint & 65536
ABresult
0X0
100
111
4061 174 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 157 17 174
4062 157 $self->stmt_info($v, $info, $hint_assign);
4063 } else {
4064 17 $self->stmt_info($v, $info, T_STR|T_ARRAY|$hint_assign);
4065 }
4066 }
4067 174 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 157 17 174
4068 157 $self->stmt_info($i, $info);
4069  
4070 # add resolvable globals
4071 #
4072 157 my $g = $self->globalvar_to_var($v, $i);
4073 157 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) 22 135 157
4074 22 $info->{globals}{$g} = 1;
4075 }
4076 }
4077 } elsif ($s =~ /^#obj\d+$/) {
4078 9 my ($o, $m) = @{$self->{strmap}->{$s}};
4079 9 ▶ if (lc($o) ne '$this') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $o ne "\$this") 4 5 9
4080 4 $self->stmt_info($o, $info);
4081 }
4082 9 ▶ if (defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m) 9 0 9
4083 9 $self->stmt_info($m, $info);
4084 }
4085 } elsif ($s =~ /^#inst\d+$/) {
4086 19 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
4087 19 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 19 0 19
4088 19 $self->stmt_info($c, $info);
4089 }
4090 } elsif ($s =~ /^#scope\d+$/) {
4091 0 my ($c, $e) = @{$self->{strmap}->{$s}};
4092 0 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
4093 0 $self->stmt_info($e, $info);
4094 }
4095 } elsif ($s =~ /^#ns\d+$/) {
4096 0 my ($n, $e) = @{$self->{strmap}->{$s}};
4097 0 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
4098 0 $self->stmt_info($e, $info);
4099 }
4100 } elsif ($s =~ /^#ref\d+$/) {
4101 0 my $v = $self->{strmap}->{$s}->[0];
4102 0 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
4103 0 $self->stmt_info($v, $info);
4104 }
4105 } elsif ($s =~ /^#call\d+$/) {
4106 295 my ($f, $a) = @{$self->{strmap}->{$s}};
4107 295 my $narg = scalar @$a;
4108 295 ▶ if (exists $info->{state} && $info->{state}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'state'} and $info->{'state'}) { } 14 281 295
Condition66%2/3
exists $info->{"state"} and $info->{"state"}
!ll&&!rl&&r
281014
MC/DC50%1/2
exists $info->{"state"} and $info->{"state"}
exists $info->{"state"} $info->{"state"}
Truth table66%2/3
A and B
A= exists $info->{"state"}B= $info->{"state"}
ABresult
0X0
100
111
4109 14 $info->{calls}{$f} = $info->{state};
4110 } else {
4111 281 $info->{calls}{$f} = 1;
4112 }
4113 295 $info->{callargs}{$f}{$narg} = 1; # track args count
4114  
4115 295 foreach my $k (@$a) {
4116 183 ▶ if ($f eq 'strlen') {
Branch: 3 branches
BranchTrueFalseTotal
if ($f eq 'strlen') { } 3 180 183
elsif ($f eq 'base64_decode') { } 2 178 180
elsif ($f eq 'gzinflate') { } 0 178 178
4117 3 $self->stmt_info($k, $info, T_STR);
4118 } elsif ($f eq 'base64_decode') {
4119 2 $self->stmt_info($k, $info, T_STR);
4120 } elsif ($f eq 'gzinflate') {
4121 0 $self->stmt_info($k, $info, T_STR);
4122 } else {
4123 178 $self->stmt_info($k, $info);
4124 }
4125 }
4126 } elsif ($s =~ /^#pfx\d+$/) {
4127 0 my $pfx = $self->{strmap}->{$s};
4128 } elsif ($s =~ /^#class\d+$/) {
4129 19 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
4130 19 $info->{classes}{$c} = 1;
4131 } elsif ($s =~ /^#trait\d+$/) {
4132 0 my ($t, $b) = @{$self->{strmap}->{$s}};
4133 0 $info->{traits}{$t} = 1;
4134 } elsif ($s =~ /^#fh\d+$/) {
4135 0 my $f = $self->{strmap}->{$s}{name};
4136 0 my $m = $self->{strmap}->{$s}{mode};
4137 0 my $p = $self->{strmap}->{$s}{pos};
4138 0 $info->{fhs}{$f} = 1;
4139 } elsif ($s =~ /^#stmt\d+$/) {
4140 582 my $cmd = $self->{strmap}->{$s}->[0];
4141 582 ▶ if ($cmd eq 'echo') {
Branch: 23 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 128 454 582
elsif ($cmd eq 'print') { } 0 454 454
elsif ($cmd eq 'namespace') { } 0 454 454
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 454 454
elsif ($cmd eq 'use') { } 0 454 454
elsif ($cmd eq 'global') { } 9 445 454
elsif ($cmd eq 'static') { } 6 439 445
elsif ($cmd eq 'const') { } 0 439 439
elsif ($cmd eq 'unset') { } 0 439 439
elsif ($cmd eq 'return') { } 276 163 439
elsif ($cmd eq 'goto') { } 0 163 163
elsif ($cmd eq 'label') { } 0 163 163
elsif ($cmd eq 'throw') { } 0 163 163
elsif ($cmd eq 'if') { } 129 34 163
elsif ($cmd eq 'while') { } 6 28 34
elsif ($cmd eq 'do') { } 1 27 28
elsif ($cmd eq 'for') { } 8 19 27
elsif ($cmd eq 'foreach') { } 11 8 19
elsif ($cmd eq 'switch') { } 7 1 8
elsif ($cmd eq 'case') { } 0 1 1
elsif ($cmd eq 'try') { } 0 1 1
elsif ($cmd eq 'break') { } 1 0 1
elsif ($cmd eq 'continue') { } 0 0 0
4142 128 my $a = $self->{strmap}->{$s}->[1];
4143 128 foreach my $k (@$a) {
4144 128 $self->stmt_info($k, $info);
4145 }
4146 128 $info->{stmts}{$s} = 1;
4147 } elsif ($cmd eq 'print') {
4148 0 my $arg = $self->{strmap}->{$s}->[1];
4149 0 $self->stmt_info($arg, $info);
4150 0 $info->{stmts}{$s} = 1;
4151 } elsif ($cmd eq 'namespace') {
4152 0 my ($arg, $block) = @{$self->{strmap}->{$s}}[1..2];
4153 0 ▶ if (defined $block) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block) 0 0 0
4154 0 $self->stmt_info($block, $info);
4155 }
4156 0 $info->{stmts}{$s} = 1;
4157 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
4158 0 my $arg = $self->{strmap}->{$s}->[1];
4159 0 $info->{includes}{$arg} = 1;
4160 0 $self->stmt_info($arg, $info);
4161 } elsif ($cmd eq 'use') {
4162 0 my $a = $self->{strmap}->{$s}->[1];
4163 0 foreach my $v (@$a) {
4164 0 $self->stmt_info($v, $info);
4165 }
4166 0 $info->{stmts}{$s} = 1;
4167 } elsif ($cmd eq 'global') {
4168 9 my $a = $self->{strmap}->{$s}->[1];
4169 9 foreach my $v (@$a) {
4170 9 $info->{globals}{$v} = 1;
4171 9 $self->stmt_info($v, $info);
4172 }
4173 } elsif ($cmd eq 'static') {
4174 6 my $a = $self->{strmap}->{$s}->[1];
4175 6 foreach my $v (@$a) {
4176 6 $info->{statics}{$v} = 1;
4177 6 $self->stmt_info($v, $info);
4178 }
4179 } elsif ($cmd eq 'const') {
4180 0 my $a = $self->{strmap}->{$s}->[1];
4181 0 foreach my $v (@$a) {
4182 0 $info->{const}{$v} = 1;
4183 0 $self->stmt_info($v, $info);
4184 }
4185 } elsif ($cmd eq 'unset') {
4186 0 my $a = $self->{strmap}->{$s}->[1];
4187 0 foreach my $v (@$a) {
4188 0 $info->{assigns}{$v} = 1;
4189 0 $self->stmt_info($v, $info, HINT_ASSIGN|HINT_UNSET);
4190 }
4191 } elsif ($cmd eq 'return') {
4192 276 my $a = $self->{strmap}->{$s}->[1];
4193 276 my $old;
4194 276 ▶ $old = $info->{state} if exists $info->{state};
Branch: 1 branch
BranchTrueFalseTotal
if exists $info->{"state"} 1 275 276
4195 276 $info->{state} = 'return';
4196 276 $self->stmt_info($a, $info);
4197 276 $info->{state} = $old;
4198 276 $info->{returns}{$a} = 1;
4199 } elsif ($cmd eq 'goto') {
4200 0 my $arg = $self->{strmap}->{$s}->[1];
4201 0 $self->stmt_info($arg, $info);
4202 0 $info->{stmts}{$s} = 1;
4203 } elsif ($cmd eq 'label') {
4204 0 my $arg = $self->{strmap}->{$s}->[1];
4205 0 $self->stmt_info($arg, $info);
4206 0 $info->{stmts}{$s} = 1;
4207 } elsif ($cmd eq 'throw') {
4208 0 my $arg = $self->{strmap}->{$s}->[1];
4209 0 $self->stmt_info($arg, $info);
4210 0 $info->{stmts}{$s} = 1;
4211 } elsif ($cmd eq 'if') {
4212 129 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
4213  
4214 129 $self->stmt_info($cond, $info);
4215 129 $self->stmt_info($then, $info);
4216 129 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 15 114 129
4217 15 $self->stmt_info($else, $info);
4218 }
4219 129 $info->{stmts}{$s} = 1;
4220 } elsif ($cmd eq 'while') {
4221 6 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4222  
4223 6 $self->stmt_info($cond, $info);
4224 6 $self->stmt_info($block, $info);
4225 6 $info->{stmts}{$s} = 1;
4226 } elsif ($cmd eq 'do') {
4227 1 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4228  
4229 1 $self->stmt_info($block, $info);
4230 1 $self->stmt_info($cond, $info);
4231 1 $info->{stmts}{$s} = 1;
4232 } elsif ($cmd eq 'for') {
4233 8 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
4234  
4235 8 $self->stmt_info($pre, $info);
4236 8 $self->stmt_info($cond, $info);
4237 8 $self->stmt_info($post, $info);
4238 8 $self->stmt_info($block, $info);
4239 8 $info->{stmts}{$s} = 1;
4240 } elsif ($cmd eq 'foreach') {
4241 11 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
4242  
4243 11 $self->stmt_info($expr, $info);
4244 11 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 7 4 11
4245 7 $self->stmt_info($key, $info);
4246 7 $info->{assigns}{$key} = 1;
4247 }
4248 11 $self->stmt_info($value, $info);
4249 11 $info->{assigns}{$value} = 1;
4250 11 $self->stmt_info($block, $info);
4251 11 $info->{stmts}{$s} = 1;
4252 } elsif ($cmd eq 'switch') {
4253 7 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
4254  
4255 7 $self->stmt_info($expr, $info);
4256 7 foreach my $e (@$cases) {
4257 9 my $c = $e->[0];
4258 9 my $b = $e->[1];
4259 9 ▶ if (defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 9 0 9
4260 9 $self->stmt_info($c, $info);
4261 }
4262 9 $self->stmt_info($b, $info);
4263 }
4264 7 $info->{stmts}{$s} = 1;
4265 } elsif ($cmd eq 'case') {
4266 0 my $expr = $self->{strmap}->{$s}->[1];
4267 0 ▶ if (defined $expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expr) 0 0 0
4268 0 $self->stmt_info($expr, $info);
4269 }
4270 } elsif ($cmd eq 'try') {
4271 0 my ($try, $catches, $finally) = @{$self->{strmap}->{$s}}[1..3];
4272  
4273 0 $self->stmt_info($try, $info);
4274 0 foreach my $c (@$catches) {
4275 0 my $e = $c->[0];
4276 0 my $b = $c->[1];
4277 0 $self->stmt_info($e, $info);
4278 0 $self->stmt_info($b, $info);
4279 }
4280 0 ▶ if (defined $finally) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $finally) 0 0 0
4281 0 $self->stmt_info($finally, $info);
4282 }
4283 0 $info->{stmts}{$s} = 1;
4284 } elsif ($cmd eq 'break') {
4285 1 $info->{breaks}{$s} = 1;
4286 } elsif ($cmd eq 'continue') {
4287 0 $info->{continues}{$s} = 1;
4288 }
4289 } elsif (is_variable($s)) {
4290 750 my ($global) = global_split($s);
4291 750 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) { } 48 702 750
4292 48 $info->{globals}{$global} = 1;
4293 } else {
4294 702 ▶ if (defined $hint) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hint) { } 469 233 702
4295 469 $info->{vars}{$s} |= ($hint & T_MASK);
4296 469 ▶ $info->{noassigns}{$s} |= ($hint & T_MASK) unless ($hint & HINT_ASSIGN);
Branch: 1 branch
BranchTrueFalseTotal
unless $hint & 65536 132 337 469
4297 } else {
4298 233 $info->{vars}{$s} |= 0;
4299 233 $info->{noassigns}{$s} |= 0;
4300 }
4301 }
4302 }
4303 5471 return;
4304 }
4305  
4306 0 ▶sub translate_stmt {
Subroutine translate_stmt: not called CC=202 SCAR=106.2
Pod undocumented
4307 0 my ($self, $out, $s, $info) = @_;
4308  
4309 #$self->{log}->('TRANSLATE', "$s") if $self->{log};
4310  
4311 0 ▶ if (!defined $s) {
Branch: 22 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 0 0
elsif ($s =~ /^#null$/) { } 0 0 0
elsif ($s =~ /^#num\d+$/) { } 0 0 0
elsif ($s =~ /^#const\d+$/) { } 0 0 0
elsif ($s =~ /^#str\d+$/) { } 0 0 0
elsif ($s =~ /^#arr\d+$/) { } 0 0 0
elsif ($s =~ /^#fun\d+$/) { } 0 0 0
elsif ($s =~ /^#call\d+$/) { } 0 0 0
elsif ($s =~ /^#elem\d+$/) { } 0 0 0
elsif ($s =~ /^#expr\d+$/) { } 0 0 0
elsif ($s =~ /^#pfx\d+$/) { } 0 0 0
elsif ($s =~ /^#obj\d+$/) { } 0 0 0
elsif ($s =~ /^#scope\d+$/) { } 0 0 0
elsif ($s =~ /^#ns\d+$/) { } 0 0 0
elsif ($s =~ /^#inst\d+$/) { } 0 0 0
elsif ($s =~ /^#ref\d+$/) { } 0 0 0
elsif ($s =~ /^#class\d+$/) { } 0 0 0
elsif ($s =~ /^#trait\d+$/) { } 0 0 0
elsif ($s =~ /^#fh\d+$/) { } 0 0 0
elsif ($s =~ /^#blk\d+$/) { } 0 0 0
elsif ($s =~ /^#stmt\d+$/) { } 0 0 0
elsif (is_variable($s)) { } 0 0 0
4312 0 $self->{warn}->('translate', "undefined symbol");
4313 0 return;
4314 } elsif ($s =~ /^#null$/) {
4315 0 push(@$out, 'undef');
4316 } elsif ($s =~ /^#num\d+$/) {
4317 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4318 0 $self->{warn}->('translate', "num $s not found");
4319 0 return;
4320 }
4321 0 $s = $self->{strmap}->{$s};
4322 0 push(@$out, $s);
4323 } elsif ($s =~ /^#const\d+$/) {
4324 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4325 0 $self->{warn}->('translate', "bad const $s");
4326 0 return;
4327 }
4328 0 $s = $self->{strmap}->{$s};
4329 0 ▶ unless (is_symbol($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($s)) 0 0 0
4330 0 $self->{warn}->('translate', "bad const name $s");
4331 0 return;
4332 }
4333 0 push(@$out, '$'.$s); # convert to var
4334 } elsif ($s =~ /^#str\d+$/) {
4335 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4336 0 $self->{warn}->('translate', "bad str $s");
4337 0 return;
4338 }
4339 0 $s = $self->{strmap}->{$s};
4340 # escape string (keep newlines as newline like php does)
4341 #
4342 0 $s =~ s/\\/\\\\/sg;
4343 0 $s =~ s/'/\\'/sg;
4344 0 $s = '\'' . $s . '\'';
4345 0 push(@$out, $s);
4346 } elsif ($s =~ /^#arr\d+$/) {
4347 0 my $arr = $self->{strmap}{$s};
4348 0 my $keys = $arr->get_keys();
4349 0 push(@$out, '{');
4350  
4351 0 foreach my $k (@$keys) {
4352 0 my $val = $arr->val($k);
4353 0 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) { } 0 0 0
4354 0 push(@$out, $k);
4355 } else {
4356 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4357 }
4358 0 push(@$out, '=>');
4359 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
4360 0 ▶ return unless $self->translate_stmt($out, $val, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $val, $info) 0 0 0
4361 } else {
4362 0 push(@$out, 'undef');
4363 }
4364 0 push(@$out, ',');
4365 }
4366 0 ▶ if (scalar @$keys > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys > 0) 0 0 0
4367 0 pop(@$out);
4368 }
4369 0 push(@$out, '}');
4370 } elsif ($s =~ /^#fun\d+$/) {
4371 0 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
4372  
4373 0 push(@$out, 'sub');
4374 0 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 0 0 0
4375 0 ▶ unless (is_symbol($f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($f)) 0 0 0
4376 0 $self->{warn}->('translate', "bad func name $s $f not supported");
4377 0 return;
4378 }
4379 0 $self->{warn}->('translate', "func in func $s $f not supported");
4380 0 return;
4381 #push(@$out, $f);
4382 }
4383 0 push(@$out, '{');
4384 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4385 0 push(@$out, 'my');
4386 0 push(@$out, '(');
4387 0 foreach my $k (@$a) {
4388 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4389 0 push(@$out, ',');
4390 }
4391 0 pop(@$out);
4392 0 push(@$out, ')');
4393 0 push(@$out, '=');
4394 0 push(@$out, '@_');
4395 0 push(@$out, ';');
4396 }
4397 # TODO: don't pass local func info from outside
4398 #
4399 0 ▶ if (keys %{$info->{locals}} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"locals"};} > 0) 0 0 0
4400 0 push(@$out, 'my');
4401 0 push(@$out, '(');
4402 0 foreach my $k (keys %{$info->{locals}}) {
4403 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4404 0 push(@$out, ',');
4405 }
4406 0 pop(@$out);
4407 0 push(@$out, ')');
4408 0 push(@$out, ';');
4409 }
4410 #$self->translate_stmt($out, $b, $info);
4411  
4412 0 my ($type, $c) = @{$self->{strmap}->{$b}};
4413 0 foreach my $k (@$c) {
4414 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4415 #if ($out->[-1] ne '}') {
4416 0 push(@$out, ';');
4417 #}
4418 }
4419 0 push(@$out, '}');
4420 } elsif ($s =~ /^#call\d+$/) {
4421 0 my ($f, $a) = @{$self->{strmap}->{$s}};
4422  
4423 0 ▶ unless (is_symbol($f)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($f)) 0 0 0
4424 0 $self->{warn}->('translate', "call name $s $f not supported");
4425 0 return;
4426 }
4427 0 ▶ if (($f eq 'strlen') && (scalar @$a == 1)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($f eq 'strlen' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'isset' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'range' and scalar @$a == 2) { } 0 0 0
elsif ($f eq 'base64_encode' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'base64_decode' and scalar @$a == 1) { } 0 0 0
elsif ($f eq 'gzinflate' and scalar @$a == 1) { } 0 0 0
elsif ($f =~ /^(chr|ord)$/ and scalar @$a == 1) { } 0 0 0
Condition0%0/3
$f eq "strlen" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "strlen" and scalar @$a == 1
$f eq "strlen" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "strlen"B= scalar @$a == 1
ABresult
0X0
100
111
4428 0 push(@$out, 'length');
4429 ▶ } elsif (($f eq 'isset') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "isset" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "isset" and scalar @$a == 1
$f eq "isset" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "isset"B= scalar @$a == 1
ABresult
0X0
100
111
4430 0 push(@$out, 'defined');
4431 ▶ } elsif (($f eq 'range') && (scalar @$a == 2)) {
Condition0%0/3
$f eq "range" and scalar @$a == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "range" and scalar @$a == 2
$f eq "range" scalar @$a == 2
Truth table0%0/3
A and B
A= $f eq "range"B= scalar @$a == 2
ABresult
0X0
100
111
4432 0 push(@$out, '[');
4433 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4434 0 push(@$out, '..');
4435 0 ▶ return unless $self->translate_stmt($out, $a->[1], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[1], $info) 0 0 0
4436 0 push(@$out, ']');
4437 0 return 1;
4438 ▶ } elsif (($f eq 'base64_encode') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "base64_encode" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "base64_encode" and scalar @$a == 1
$f eq "base64_encode" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "base64_encode"B= scalar @$a == 1
ABresult
0X0
100
111
4439 # encode_base64($s,'')
4440 0 push(@$out, 'encode_base64');
4441 0 push(@$out, '(');
4442 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4443 0 push(@$out, ',');
4444 0 push(@$out, '\'\'');
4445 0 push(@$out, ')');
4446 0 return 1;
4447 ▶ } elsif (($f eq 'base64_decode') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "base64_decode" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "base64_decode" and scalar @$a == 1
$f eq "base64_decode" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "base64_decode"B= scalar @$a == 1
ABresult
0X0
100
111
4448 # decode_base64($s)
4449 0 push(@$out, 'decode_base64');
4450 0 push(@$out, '(');
4451 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4452 0 push(@$out, ')');
4453 0 return 1;
4454 ▶ } elsif (($f eq 'gzinflate') && (scalar @$a == 1)) {
Condition0%0/3
$f eq "gzinflate" and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "gzinflate" and scalar @$a == 1
$f eq "gzinflate" scalar @$a == 1
Truth table0%0/3
A and B
A= $f eq "gzinflate"B= scalar @$a == 1
ABresult
0X0
100
111
4455 # (Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS))->inflate($s))[0])
4456 0 push(@$out, '(');
4457 0 push(@$out, 'Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS))->inflate');
4458 0 push(@$out, '(');
4459 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4460 0 push(@$out, ')');
4461 0 push(@$out, ')');
4462 0 push(@$out, '[');
4463 0 push(@$out, '0');
4464 0 push(@$out, ']');
4465 0 return 1;
4466 ▶ } elsif (($f =~ /^(chr|ord)$/) && (scalar @$a == 1)) {
Condition0%0/3
$f =~ /^(chr|ord)$/ and scalar @$a == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$f =~ /^(chr|ord)$/ and scalar @$a == 1
$f =~ /^(chr|ord)$/ scalar @$a == 1
Truth table0%0/3
A and B
A= $f =~ /^(chr|ord)$/B= scalar @$a == 1
ABresult
0X0
100
111
4467 0 push(@$out, $f);
4468 } else {
4469 0 $self->{warn}->('translate', "call $s $f not supported");
4470 0 return;
4471 }
4472 0 push(@$out, '(');
4473 0 foreach my $k (@$a) {
4474 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4475 0 push(@$out, ',');
4476 }
4477 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4478 0 pop(@$out);
4479 }
4480 0 push(@$out, ')');
4481 } elsif ($s =~ /^#elem\d+$/) {
4482 0 my ($v, $i) = @{$self->{strmap}->{$s}};
4483  
4484 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} & T_MASK) == T_STR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16) 0 0 0
Condition0%0/3
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16
!ll&&!rl&&r
000
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 16
exists $info->{"vars"}{$v} ($info->{"vars"}{$v} & 65535) == 16
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= ($info->{"vars"}{$v} & 65535) == 16
ABresult
0X0
100
111
4485 0 push(@$out, 'substr');
4486 0 push(@$out, '(');
4487 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4488 0 push(@$out, ',');
4489 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) { } 0 0 0
4490 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4491 0 push(@$out, ',');
4492 0 push(@$out, '1');
4493 } else {
4494 0 push(@$out, '-1');
4495 }
4496 0 push(@$out, ')');
4497 0 return 1;
4498 }
4499 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4500 0 push(@$out, '->');
4501 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} & T_MASK) == T_ARRAY)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'vars'}{$v} and ($info->{'vars'}{$v} & 65535) == 32) { } 0 0 0
Condition0%0/3
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 32
!ll&&!rl&&r
000
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} & 65535) == 32
exists $info->{"vars"}{$v} ($info->{"vars"}{$v} & 65535) == 32
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= ($info->{"vars"}{$v} & 65535) == 32
ABresult
0X0
100
111
4502 0 push(@$out, '[');
4503 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 0 0 0
4504 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4505 }
4506 0 push(@$out, ']');
4507 } else {
4508 0 push(@$out, '{');
4509 0 ▶ if (defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i) 0 0 0
4510 0 ▶ return unless $self->translate_stmt($out, $i, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $i, $info) 0 0 0
4511 }
4512 0 push(@$out, '}');
4513 }
4514 } elsif ($s =~ /^#expr\d+$/) {
4515 0 my ($op, $v1, $v2) = @{$self->{strmap}->{$s}};
4516  
4517 0 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) 0 0 0
4518 0 ▶ if ($v1 =~ /^#expr\d+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v1 =~ /^#expr\d+$/) { } 0 0 0
elsif ($v1 =~ /^#elem\d+$/ and defined $v2 and $op eq '=') { } 0 0 0
4519 0 my $vop = $self->{strmap}->{$v1}->[0];
4520 0 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 0 0 0
Condition0%0/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
000
MC/DC0%0/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table0%0/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
4521 0 push(@$out, '(');
4522 }
4523 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4524 0 ▶ if (($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "=" and $op ne $vop) 0 0 0
Condition0%0/3
$op ne "=" and $op ne $vop
!ll&&!rl&&r
000
MC/DC0%0/2
$op ne "=" and $op ne $vop
$op ne "=" $op ne $vop
Truth table0%0/3
A and B
A= $op ne "="B= $op ne $vop
ABresult
0X0
100
111
4525 0 push(@$out, ')');
4526 }
4527 ▶ } elsif (($v1 =~ /^#elem\d+$/) && defined $v2 && ($op eq '=')) {
Condition0%0/6
$v1 =~ /^#elem\d+$/ and defined $v2 and $op eq "="
!ll&&!rl&&r
000
$v1 =~ /^#elem\d+$/ and defined $v2
!ll&&!rl&&r
000
MC/DC0%0/3
$v1 =~ /^#elem\d+$/ and defined $v2 and $op eq "="
$v1 =~ /^#elem\d+$/ defined $v2 $op eq "="
Truth table0%0/4
A and B and C
A= $v1 =~ /^#elem\d+$/B= defined $v2C= $op eq "="
ABCresult
0XX0
10X0
1100
1111
4528 0 my $v = $self->{strmap}->{$v1}->[0];
4529 0 my $i = $self->{strmap}->{$v1}->[1];
4530 0 ▶ unless (defined $i && is_strict_variable($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and is_strict_variable($v)) { } 0 0 0
Condition0%0/3
defined $i and is_strict_variable($v)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $i and is_strict_variable($v)
defined $i is_strict_variable($v)
Truth table0%0/3
A and B
A= defined $iB= is_strict_variable($v)
ABresult
0X0
100
111
4531 # try to emulate php-arrays with perl-maps
4532 # see: https://www.php.net/manual/en/language.types.array.php
4533 # - if no key is specified, the maximum of the existing int
4534 # indices is taken, and the new key will be that maximum
4535 # value plus 1 (but at least 0).
4536 # - If no int indices exist yet, the key will be 0 (zero).
4537 #
4538 # TODO: Note that the maximum integer key used for this
4539 # need not currently exist in the array. It need only
4540 # have existed in the array at some time since the
4541 # last time the array was re-indexed.
4542 #
4543 0 ▶ if (exists $info->{vars}{$v} && (($info->{vars}{$v} && T_MASK) == T_ARRAY)) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $info->{'vars'}{$v} and ($info->{'vars'}{$v} && 65535) == 32) { } 0 0 0
Condition0%0/5
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} && 65535) == 32
!ll&&!rl&&r
000
$info->{'vars'}{$v} && 65535
!ll
00
MC/DC0%0/2
exists $info->{"vars"}{$v} and ($info->{"vars"}{$v} && 65535) == 32
exists $info->{"vars"}{$v} $info->{'vars'}{$v}
Truth table0%0/3
A and B
A= exists $info->{"vars"}{$v}B= $info->{'vars'}{$v}
ABresult
0X0
100
111
4544 # for 'array' convert '$x[] = $v' to:
4545 # push(@{$x}, $v)
4546 #
4547 0 push(@$out, 'push');
4548 0 push(@$out, '(');
4549 0 push(@$out, '@');
4550 0 push(@$out, '{');
4551 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4552 0 push(@$out, '}');
4553 0 push(@$out, ',');
4554 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4555 0 push(@$out, ')');
4556 0 return 1;
4557 } else {
4558 # for 'map' convert '$x[] = $v' to:
4559 # $x->{(max keys %$x)[-1] + 1} = $v
4560 # (or: $x->{keys %$x ? (sort keys %$x)[-1] + 1 : 0} = $v)
4561 #
4562 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4563 0 my $vx = $out->[-1];
4564 0 push(@$out, '->');
4565 0 push(@$out, '{');
4566 0 push(@$out, '(');
4567 0 push(@$out, 'max');
4568 0 push(@$out, 'keys');
4569 0 push(@$out, '%'.$vx);
4570 0 push(@$out, ')');
4571 0 push(@$out, '[');
4572 0 push(@$out, '-1');
4573 0 push(@$out, ']');
4574 0 push(@$out, '+');
4575 0 push(@$out, '1');
4576 0 push(@$out, '}');
4577 }
4578 } else {
4579 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4580 }
4581 } else {
4582 0 ▶ return unless $self->translate_stmt($out, $v1, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v1, $info) 0 0 0
4583 }
4584 }
4585 0 ▶ if ($op eq '==') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '==') { } 0 0 0
elsif ($op eq '!=') { } 0 0 0
4586 0 push(@$out, 'eq');
4587 } elsif ($op eq '!=') {
4588 0 push(@$out, 'ne');
4589 } else {
4590 0 push(@$out, $op);
4591 }
4592 0 ▶ if (defined $v2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v2) 0 0 0
4593 0 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 0 0 0
4594 0 push(@$out, '{');
4595 }
4596 0 ▶ if ($v2 =~ /^#expr\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2 =~ /^#expr\d+$/) { } 0 0 0
4597 0 my $vop = $self->{strmap}->{$v2}->[0];
4598 0 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 0 0 0
Condition0%0/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
000
$op ne "?" and $op ne "="
!ll&&!rl&&r
000
MC/DC0%0/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table0%0/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
4599 0 push(@$out, '(');
4600 }
4601 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4602 0 ▶ if (($op ne '?') && ($op ne '=') && ($op ne $vop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne "?" and $op ne "=" and $op ne $vop) 0 0 0
Condition0%0/6
$op ne "?" and $op ne "=" and $op ne $vop
!ll&&!rl&&r
000
$op ne "?" and $op ne "="
!ll&&!rl&&r
000
MC/DC0%0/3
$op ne "?" and $op ne "=" and $op ne $vop
$op ne "?" $op ne "=" $op ne $vop
Truth table0%0/4
A and B and C
A= $op ne "?"B= $op ne "="C= $op ne $vop
ABCresult
0XX0
10X0
1100
1111
4603 0 push(@$out, ')');
4604 }
4605 } else {
4606 0 ▶ return unless $self->translate_stmt($out, $v2, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v2, $info) 0 0 0
4607 }
4608 0 ▶ if ($op eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "\$") 0 0 0
4609 0 push(@$out, '}');
4610 }
4611 }
4612 } elsif ($s =~ /^#pfx\d+$/) {
4613 0 ▶ unless (exists $self->{strmap}->{$s}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"strmap"}{$s}) 0 0 0
4614 0 $self->{warn}->('translate', "pfx $s not found");
4615 0 return;
4616 }
4617 0 my $pfx = $self->{strmap}->{$s};
4618 0 ▶ if (exists $pfx->{global}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pfx->{"global"}) 0 0 0
4619 0 my $s = join(' ', sort keys %$pfx);
4620 0 $self->{warn}->('translate', "global pfx $s");
4621 0 return;
4622 }
4623 0 push(@$out, 'my');
4624 } elsif ($s =~ /^#obj\d+$/) {
4625 0 my ($o, $m) = @{$self->{strmap}->{$s}};
4626  
4627 0 $self->{warn}->('translate', "obj $s $o->$m not supported");
4628 0 return;
4629 } elsif ($s =~ /^#scope\d+$/) {
4630 0 my ($c, $e) = @{$self->{strmap}->{$s}};
4631  
4632 0 $self->{warn}->('translate', "scope $s $c::$e not supported");
4633 0 return;
4634 } elsif ($s =~ /^#ns\d+$/) {
4635 0 my ($n, $e) = @{$self->{strmap}->{$s}};
4636  
4637 0 $self->{warn}->('translate', "namespace $s $n::$e not supported");
4638 0 return;
4639 } elsif ($s =~ /^#inst\d+$/) {
4640 0 my ($c, $f, $i) = @{$self->{strmap}->{$s}};
4641  
4642 0 $self->{warn}->('translate', "new inst $s $f not supported");
4643 0 return;
4644 } elsif ($s =~ /^#ref\d+$/) {
4645 0 my $v = $self->{strmap}->{$s}->[0];
4646 0 push(@$out, '\\');
4647 0 ▶ return unless $self->translate_stmt($out, $v, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $v, $info) 0 0 0
4648 } elsif ($s =~ /^#class\d+$/) {
4649 0 my ($c, $b, $p) = @{$self->{strmap}->{$s}};
4650  
4651 0 $self->{warn}->('translate', "class $s $c not supported");
4652 0 return;
4653 } elsif ($s =~ /^#trait\d+$/) {
4654 0 my ($t, $b) = @{$self->{strmap}->{$s}};
4655  
4656 0 $self->{warn}->('translate', "trait $s $t not supported");
4657 0 return;
4658 } elsif ($s =~ /^#fh\d+$/) {
4659 0 my $f = $self->{strmap}->{$s}{name};
4660 0 my $m = $self->{strmap}->{$s}{mode};
4661 0 my $p = $self->{strmap}->{$s}{pos};
4662  
4663 0 $self->{warn}->('translate', "fh $s $f not supported");
4664 0 return;
4665 } elsif ($s =~ /^#blk\d+$/) {
4666 0 my ($type, $a) = @{$self->{strmap}->{$s}};
4667  
4668 0 ▶ if ($type eq 'expr') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'expr') { } 0 0 0
elsif ($type eq 'flat') { } 0 0 0
elsif ($type eq 'case') { } 0 0 0
elsif ($type eq 'brace') { } 0 0 0
4669 0 foreach my $k (@$a) {
4670 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4671 0 push(@$out, ',');
4672 }
4673 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4674 0 pop(@$out);
4675 }
4676 } elsif ($type eq 'flat') {
4677 0 foreach my $k (@$a) {
4678 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4679 0 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 0 0
4680 0 next; # avoid ;
4681 }
4682 0 ▶ if ($out->[-1] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}") 0 0 0
4683 0 push(@$out, ';');
4684 }
4685 }
4686 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4687 0 pop(@$out);
4688 }
4689 } elsif ($type eq 'case') {
4690 0 foreach my $k (@$a) {
4691 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4692 0 push(@$out, ';');
4693 }
4694 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4695 0 pop(@$out);
4696 }
4697 } elsif ($type eq 'brace') {
4698 0 ▶ if (scalar @$a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a == 1) { } 0 0 0
4699 0 ▶ return unless $self->translate_stmt($out, $a->[0], $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a->[0], $info) 0 0 0
4700 } else {
4701 0 push(@$out, '(');
4702 0 foreach my $k (@$a) {
4703 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4704 0 ▶ if ($out->[-1] ne ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne ")") 0 0 0
4705 0 push(@$out, ';');
4706 }
4707 }
4708 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4709 0 pop(@$out);
4710 }
4711 0 push(@$out, ')');
4712 }
4713 } else {
4714 0 push(@$out, '{');
4715 0 foreach my $k (@$a) {
4716 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4717 0 ▶ if ($k =~ /^#pfx\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^#pfx\d+$/) 0 0 0
4718 0 next; # avoid ;
4719 }
4720 0 ▶ if ($out->[-1] ne '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->[-1] ne "}") 0 0 0
4721 0 push(@$out, ';');
4722 }
4723 }
4724 0 ▶ if ((scalar @$a > 0) && ($out->[-1] eq ';')) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0 and $out->[-1] eq ";") 0 0 0
Condition0%0/3
scalar @$a > 0 and $out->[-1] eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$a > 0 and $out->[-1] eq ";"
scalar @$a > 0 $out->[-1] eq ";"
Truth table0%0/3
A and B
A= scalar @$a > 0B= $out->[-1] eq ";"
ABresult
0X0
100
111
4725 0 pop(@$out);
4726 }
4727 0 push(@$out, '}');
4728 }
4729 } elsif ($s =~ /^#stmt\d+$/) {
4730 0 my $cmd = $self->{strmap}->{$s}->[0];
4731 0 ▶ if ($cmd eq 'echo') {
Branch: 20 branches
BranchTrueFalseTotal
if ($cmd eq 'echo') { } 0 0 0
elsif ($cmd eq 'print') { } 0 0 0
elsif ($cmd eq 'namespace') { } 0 0 0
elsif ($cmd =~ /^(include|include_once|require|require_once)$/) { } 0 0 0
elsif ($cmd eq 'use') { } 0 0 0
elsif ($cmd eq 'global') { } 0 0 0
elsif ($cmd eq 'static') { } 0 0 0
elsif ($cmd eq 'const') { } 0 0 0
elsif ($cmd eq 'unset') { } 0 0 0
elsif ($cmd eq 'return') { } 0 0 0
elsif ($cmd eq 'goto') { } 0 0 0
elsif ($cmd eq 'label') { } 0 0 0
elsif ($cmd eq 'if') { } 0 0 0
elsif ($cmd eq 'while') { } 0 0 0
elsif ($cmd eq 'do') { } 0 0 0
elsif ($cmd eq 'for') { } 0 0 0
elsif ($cmd eq 'foreach') { } 0 0 0
elsif ($cmd eq 'switch') { } 0 0 0
elsif ($cmd eq 'break') { } 0 0 0
elsif ($cmd eq 'continue') { } 0 0 0
4732 0 my $a = $self->{strmap}->{$s}->[1];
4733 0 push(@$out, 'print');
4734 0 foreach my $k (@$a) {
4735 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4736 0 push(@$out, ',');
4737 }
4738 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) 0 0 0
4739 0 pop(@$out);
4740 }
4741 } elsif ($cmd eq 'print') {
4742 0 my $arg = $self->{strmap}->{$s}->[1];
4743 0 push(@$out, $cmd);
4744 0 ▶ return unless $self->translate_stmt($out, $arg, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $arg, $info) 0 0 0
4745 } elsif ($cmd eq 'namespace') {
4746 0 my ($a, $block) = @{$self->{strmap}->{$s}}[1..2];
4747 0 $self->{warn}->('translate', "namespace $s $a not supported");
4748 0 return;
4749 } elsif ($cmd =~ /^(include|include_once|require|require_once)$/) {
4750 0 my $arg = $self->{strmap}->{$s}->[1];
4751 0 push(@$out, $cmd);
4752 0 ▶ return unless $self->translate_stmt($out, $arg, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $arg, $info) 0 0 0
4753 } elsif ($cmd eq 'use') {
4754 0 my $a = $self->{strmap}->{$s}->[1];
4755 0 $self->{warn}->('translate', "use $s not supported");
4756 0 return;
4757 } elsif ($cmd eq 'global') {
4758 0 my $a = $self->{strmap}->{$s}->[1];
4759 0 $self->{warn}->('translate', "global $s not supported");
4760 0 return;
4761 } elsif ($cmd eq 'static') {
4762 0 my $a = $self->{strmap}->{$s}->[1];
4763 0 $self->{warn}->('translate', "static $s not supported");
4764 0 return;
4765 } elsif ($cmd eq 'const') {
4766 0 my $a = $self->{strmap}->{$s}->[1];
4767 0 $self->{warn}->('translate', "const $s not supported");
4768 0 return;
4769 } elsif ($cmd eq 'unset') {
4770 0 my $a = $self->{strmap}->{$s}->[1];
4771 0 $self->{warn}->('translate', "unset $s not supported");
4772 0 return;
4773 } elsif ($cmd eq 'return') {
4774 0 my $a = $self->{strmap}->{$s}->[1];
4775 0 push(@$out, $cmd);
4776 0 ▶ return unless $self->translate_stmt($out, $a, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $a, $info) 0 0 0
4777 } elsif ($cmd eq 'goto') {
4778 0 my $a = $self->{strmap}->{$s}->[1];
4779 0 $self->{warn}->('translate', "goto $s not supported");
4780 0 return;
4781 } elsif ($cmd eq 'label') {
4782 0 my $a = $self->{strmap}->{$s}->[1];
4783 0 $self->{warn}->('translate', "label $s not supported");
4784 0 return;
4785 } elsif ($cmd eq 'if') {
4786 0 my ($cond, $then, $else) = @{$self->{strmap}->{$s}}[1..3];
4787  
4788 0 push(@$out, $cmd);
4789 0 push(@$out, '(');
4790 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4791 0 push(@$out, ')');
4792 0 ▶ return unless $self->translate_stmt($out, $then, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $then, $info) 0 0 0
4793 0 ▶ if (defined $else) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $else) 0 0 0
4794 0 push(@$out, 'else');
4795 0 ▶ return unless $self->translate_stmt($out, $else, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $else, $info) 0 0 0
4796 }
4797 } elsif ($cmd eq 'while') {
4798 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4799  
4800 0 push(@$out, $cmd);
4801 0 push(@$out, '(');
4802 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4803 0 push(@$out, ')');
4804 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4805 } elsif ($cmd eq 'do') {
4806 0 my ($cond, $block) = @{$self->{strmap}->{$s}}[1..2];
4807  
4808 0 push(@$out, $cmd);
4809 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4810 0 push(@$out, 'while');
4811 0 push(@$out, '(');
4812 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4813 0 push(@$out, ')');
4814 } elsif ($cmd eq 'for') {
4815 0 my ($pre, $cond, $post, $block) = @{$self->{strmap}->{$s}}[1..4];
4816  
4817 0 push(@$out, $cmd);
4818 0 push(@$out, '(');
4819 #push(@$out, 'my'); # set as local -> persists after for-loop
4820 0 ▶ return unless $self->translate_stmt($out, $pre, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $pre, $info) 0 0 0
4821 0 push(@$out, ';');
4822 0 ▶ return unless $self->translate_stmt($out, $cond, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $cond, $info) 0 0 0
4823 0 push(@$out, ';');
4824 0 ▶ return unless $self->translate_stmt($out, $post, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $post, $info) 0 0 0
4825 0 push(@$out, ')');
4826 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4827 } elsif ($cmd eq 'foreach') {
4828 0 my ($expr, $key, $value, $block) = @{$self->{strmap}->{$s}}[1..4];
4829  
4830 0 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 0 0 0
4831 # convert 'foreach ($x as $k => $v)' to
4832 # foreach my $k ( sort { $a <=> $b } keys %$x ) { my $v = $x->{$k}; .. }
4833 #
4834 0 push(@$out, 'foreach');
4835 #push(@$out, 'my');
4836 0 ▶ return unless $self->translate_stmt($out, $key, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $key, $info) 0 0 0
4837 0 push(@$out, '(');
4838 0 push(@$out, 'sort');
4839 0 push(@$out, '{');
4840 0 push(@$out, '$a');
4841 0 push(@$out, '<=>');
4842 0 push(@$out, '$b');
4843 0 push(@$out, '}');
4844 0 push(@$out, 'keys');
4845 0 push(@$out, '%');
4846 0 push(@$out, '{');
4847 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4848 0 push(@$out, '}');
4849 0 push(@$out, ')');
4850 0 push(@$out, '{');
4851  
4852 #push(@$out, 'my');
4853 0 ▶ return unless $self->translate_stmt($out, $value, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $value, $info) 0 0 0
4854 0 push(@$out, '=');
4855 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4856 0 push(@$out, '->');
4857 0 push(@$out, '{');
4858 0 ▶ return unless $self->translate_stmt($out, $key, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $key, $info) 0 0 0
4859 0 push(@$out, '}');
4860 0 push(@$out, ';');
4861  
4862 0 my $type = $self->{strmap}->{$block}->[1];
4863 0 my $c = $self->{strmap}->{$block}->[2];
4864 0 foreach my $k (@$c) {
4865 0 ▶ return unless $self->translate_stmt($out, $k, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $k, $info) 0 0 0
4866 #if ($out->[-1] ne '}') {
4867 0 push(@$out, ';'); # might follow {} after map define/deref
4868 #}
4869 }
4870 0 push(@$out, '}');
4871 0 return 1;
4872 } else {
4873 0 push(@$out, $cmd);
4874 0 push(@$out, 'my');
4875 0 ▶ return unless $self->translate_stmt($out, $value, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $value, $info) 0 0 0
4876 0 push(@$out, '(');
4877 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4878 0 push(@$out, ')');
4879 }
4880 0 ▶ return unless $self->translate_stmt($out, $block, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $block, $info) 0 0 0
4881 } elsif ($cmd eq 'switch') {
4882 0 my ($expr, $cases) = @{$self->{strmap}->{$s}}[1..2];
4883 0 my $first = 1;
4884  
4885 0 foreach my $e (@$cases) {
4886 0 my $c = $e->[0];
4887 0 my $b = $e->[1];
4888 0 ▶ if (!defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c) { } 0 0 0
4889 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) 0 0 0
4890 0 $self->{warn}->('translate', "bad switch $s");
4891 0 return;
4892 }
4893 0 push(@$out, 'else');
4894 } else {
4895 0 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 0 0 0
4896 0 push(@$out, 'if');
4897 0 $first = 0;
4898 } else {
4899 0 push(@$out, 'elsif');
4900 }
4901 0 push(@$out, '(');
4902 0 ▶ return unless $self->translate_stmt($out, $expr, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $expr, $info) 0 0 0
4903 0 push(@$out, '==');
4904 0 push(@$out, '(');
4905 0 ▶ return unless $self->translate_stmt($out, $c, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $c, $info) 0 0 0
4906 0 push(@$out, ')');
4907 0 push(@$out, ')');
4908 }
4909 0 push(@$out, '{');
4910 0 ▶ return unless $self->translate_stmt($out, $b, $info);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->translate_stmt($out, $b, $info) 0 0 0
4911 0 push(@$out, '}');
4912 }
4913 } elsif ($cmd eq 'break') {
4914 0 push(@$out, 'last');
4915 } elsif ($cmd eq 'continue') {
4916 0 push(@$out, 'next');
4917 } else {
4918 0 $self->{warn}->('translate', "bad statement $s");
4919 0 return;
4920 }
4921 } elsif (is_variable($s)) {
4922 0 my ($global) = global_split($s);
4923 0 ▶ if (defined $global) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global) 0 0 0
4924 0 $self->{warn}->('translate', "global $s not supported");
4925 0 return;
4926 }
4927 0 ▶ unless (is_symbol($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_symbol($s)) 0 0 0
4928 0 $self->{warn}->('translate', "bad var name $s not supported");
4929 0 return;
4930 }
4931 0 push(@$out, $s);
4932 } else {
4933 0 $self->{warn}->('translate', "bad symbol $s not supported");
4934 0 return;
4935 }
4936 0 return 1;
4937 }
4938  
4939 0 ▶sub translate_func {
Subroutine translate_func: not called CC=22 SCAR=62.3
Pod undocumented
4940 0 my ($self, $s, $maxlen, $format) = @_;
4941 0 my @out = ();
4942  
4943 0 ▶ unless ($s =~ /^#fun\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ /^#fun\d+$/) 0 0 0
4944 0 $self->{warn}->('translate', "no func $s");
4945 0 return;
4946 }
4947 # create anonymous subroutine here
4948 #
4949 0 my ($f, $a, $b, $p) = @{$self->{strmap}->{$s}};
4950 0 $f = $self->setfun(undef, $a, $b, $p);
4951  
4952 0 my $info = {args => {}, vars => {}, locals => {}, globals => {}, calls => {}, returns => {}};
4953 0 $self->stmt_info($b, $info);
4954  
4955 0 ▶ if (scalar @$a > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$a > 0) { } 0 0 0
4956 0 foreach my $v (@$a) {
4957 0 $info->{args}{$v} = 0;
4958 }
4959 0 foreach my $v (keys %{$info->{vars}}) {
4960 0 ▶ $info->{locals}{$v} |= $info->{vars}{$v} unless exists $info->{args}{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"args"}{$v} 0 0 0
4961 }
4962 0 foreach my $v (keys %{$info->{args}}) {
4963 0 ▶ $info->{vars}{$v} |= $info->{args}{$v} unless exists $info->{vars}{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"vars"}{$v} 0 0 0
4964 }
4965 } else {
4966 0 $info->{locals} = $info->{vars};
4967 }
4968 0 ▶ if (keys %{$info->{args}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"args"};}) 0 0 0
4969 0 ▶ $self->{log}->('translate', "local args: %s", join(' ', map { ($info->{vars}{$_} ne '1') ? "$_:$info->{vars}{$_}" : $_ } keys %{$info->{args}})) if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
$info->{'vars'}{$_} ne '1' ? : 0 0 0
4970 }
4971 0 ▶ if (keys %{$info->{locals}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"locals"};}) 0 0 0
4972 0 ▶ $self->{log}->('translate', "local vars: %s", join(' ', map { ($info->{vars}{$_} ne '1') ? "$_:$info->{vars}{$_}" : $_ } keys %{$info->{locals}})) if $self->{log};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
$info->{'vars'}{$_} ne '1' ? : 0 0 0
4973 }
4974 0 ▶ if (keys %{$info->{globals}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"globals"};}) 0 0 0
4975 0 ▶ $self->{log}->('translate', "globals: %s", join(' ', keys %{$info->{globals}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4976 }
4977 0 ▶ if (keys %{$info->{calls}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{"calls"};}) 0 0 0
4978 0 ▶ $self->{log}->('translate', "calls: %s", join(' ', keys %{$info->{calls}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4979 }
4980 0 ▶ if (keys %{$info->{returns}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$info{'returns'};}) { } 0 0 0
4981 0 ▶ $self->{log}->('translate', "returns: %s", join(' ', keys %{$info->{returns}})) if $self->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log"} 0 0 0
4982 } else {
4983 0 $self->{warn}->('translate', "no return for func $s");
4984 0 return;
4985 }
4986  
4987 0 ▶ unless ($self->translate_stmt(\@out, $f, $info)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->translate_stmt(\@out, $f, $info)) 0 0 0
4988 0 return;
4989 }
4990  
4991 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 0 0 0
4992 0 my @tmp = ();
4993 0 expand_formatted(\@tmp, \@out, 0);
4994 0 return join(' ', @tmp);
4995 }
4996 0 return join(' ', @out);
4997 }
4998  
4999 6 1;
5000  
5001 __END__
« blib/lib/PHP/Decode/Op.pm ↑ Summary lib/PHP/Decode/Transformer.pm »