Decode/Func.pm

filter: Statementstmt 67.9% 1074 / 1580 Branchbran 49.3% 634 / 1286 Conditioncond 33.3% 114 / 342 MC/DCmcdc 10.3% 21 / 203 Subroutinesub 95.7% 45 / 47 Podpod 5.0% 1 / 20 totaltotal 54.3% 1889 / 3478 CC 777 SCAR 105.7
CC
777
Cov
57%
exec_cmd
47828.6
preg_replace
88.6
levenshtein
56.0
CRAP 38767.4
↑ Summary Decode/Parser.pm »
1 #
2 # execute PHP built-in functions
3 #
4 package PHP::Decode::Func;
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use List::Util qw(min max shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Digest::MD5 qw(md5 md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶eval "use Digest::SHA1 qw(sha1 sha1_hex); 1" or eval "use Digest::SHA qw(sha1 sha1_hex); 1" or die "Digest::SHA/SHA1 required";
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
eval "use Digest::SHA1 qw(sha1 sha1_hex); 1" or eval "use Digest::SHA qw(sha1 sha1_hex); 1" or die "Digest::SHA/SHA1 required" 4 0 4
Condition33%1/3
eval "use Digest::SHA1 qw(sha1 sha1_hex); 1" or eval "use Digest::SHA qw(sha1 sha1_hex); 1"
l!l&&r!l&&!r
400
MC/DC0%0/2
eval "use Digest::SHA1 qw(sha1 sha1_hex); 1" or eval "use Digest::SHA qw(sha1 sha1_hex); 1"
eval "use Digest::SHA1 qw(sha1 sha1_hex); 1" eval "use Digest::SHA qw(sha1 sha1_hex); 1"
Truth table33%1/3
A or B
A= eval "use Digest::SHA1 qw(sha1 sha1_hex); 1"B= eval "use Digest::SHA qw(sha1 sha1_hex); 1"
ABresult
1X1
011
000
13 4 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use PHP::Decode::Array qw(is_int_index);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use PHP::Decode::Op;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use PHP::Decode::Parser qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use PHP::Decode::Transformer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 our $VERSION = '0.132';
22  
23 # if block contains just a sequence of strings, then return joined string
24 #
25 6 ▶sub _joinable_str {
Subroutine _joinable_str: called CC=6 SCAR=18.1
26 6 my ($parser, $s, $val) = @_;
27  
28 6 ▶ if (is_block($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_block($s)) 1 5 6
29 1 my ($type, $a) = @{$parser->{strmap}{$s}};
30 1 foreach my $stmt (@$a) {
31 1 $val = &_joinable_str($parser, $stmt, $val);
32 1 ▶ last if (!defined $val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 1 0 1
33 }
34 1 return $val;
35 }
36 5 ▶ if (is_strval($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($s)) 4 1 5
37 4 return $val . $parser->{strmap}{$s};
38 }
39 1 ▶ if (is_null($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_null($s)) 0 1 1
40 0 return '';
41 }
42 1 return;
43 }
44  
45 3 ▶sub parsing_func {
Subroutine parsing_func: called CC=3 SCAR=11.2
Pod undocumented
46 3 my ($ctx) = @_;
47  
48 3 ▶ if ($ctx->{infunction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"infunction"}) 1 2 3
49 1 ▶ if (!$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"incall"}) 1 0 1
50 1 return 0;
51 }
52 0 return 1;
53 }
54 2 return 0;
55 }
56  
57 # see: https://gist.github.com/BaiGang/1321793
58 #
59 0 ▶sub levenshtein {
Subroutine levenshtein: not called CC=7 SCAR=40.3
Pod undocumented
60 0 my ($str1, $str2) = @_;
61 0 my ($len1, $len2) = (length $str1, length $str2);
62 0 my %mat;
63
64 0 ▶ if ($len1 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len1 == 0) 0 0 0
65 0 return $len2;
66 }
67 0 ▶ if ($len2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len2 == 0) 0 0 0
68 0 return $len1;
69 }
70 0 ▶ for (my $i = 0; $i <= $len1; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $len1) 0 0 0
71 0 $mat{0}{$i} = $i;
72 0 $mat{1}{$i} = 0;
73 }
74 0 my @ar1 = split //, $str1;
75 0 my @ar2 = split //, $str2;
76
77 0 ▶ for (my $j = 1; $j <= $len2; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $len2) 0 0 0
78 0 my $p = $j % 2;
79 0 my $q = ($j + 1) % 2;
80 0 $mat{$p}{0} = $j;
81 0 ▶ for (my $i = 1; $i <= $len1; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $len1) 0 0 0
82 0 my $cost = 0;
83 0 ▶ if ($ar1[$i-1] ne $ar2[$j-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ar1[$i - 1] ne $ar2[$j - 1]) 0 0 0
84 0 $cost = 1;
85 }
86 $mat{$p}{$i} = min($cost + $mat{$q}{$i-1},
87 0 $mat{$p}{$i-1} + 1, $mat{$q}{$i} + 1);
88 }
89 }
90 0 return $mat{$len2%2}{$len1};
91 }
92  
93 # see: Perl-only CRC32 function
94 # http://billauer.co.il/blog/2011/05/perl-crc32-crc-xs-module/
95 #
96 4 my $crc32a_table;
97 my $crc32b_table;
98  
99 1 ▶sub mycrc32a {
Subroutine mycrc32a: called CC=8 SCAR=20.9
Pod undocumented
100 1 my ($input, $init_value, $polynomial) = @_;
101  
102 # hash('crc32', $str);
103 # == perl -I./Digest-CRC-0.22/lib -e 'use Digest::CRC;
104 # $ctx = Digest::CRC->new(width=>32, init=>0xffffffff, xorout=>0xffffffff, refout=>0, poly=>0x4C11DB7, refin=>0, cont=>0);
105 # $ctx->add("test");
106 # print $digest = $ctx->hexdigest . "\n";' --> (need to read bytes backwards)
107 #
108 1 ▶ $init_value = 0 unless (defined $init_value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $init_value 1 0 1
109 1 ▶ $polynomial = 0x04c11db7 unless (defined $polynomial);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $polynomial 1 0 1
110  
111 1 ▶ unless (defined $crc32a_table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $crc32a_table) 1 0 1
112 1 $crc32a_table = [];
113  
114 1 ▶ for (my $i=0; $i<256; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 256 1 257
115 256 my $x = $i << 24;
116 256 ▶ for (my $j=0; $j<8; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 8) 2048 256 2304
117 2048 ▶ if ($x & (1 << 31)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x & 2147483648) { } 1024 1024 2048
118 1024 $x = ($x << 1) ^ $polynomial;
119 } else {
120 1024 $x = $x << 1;
121 }
122 }
123 256 $x = $x & 0xffffffff;
124 256 push @$crc32a_table, $x;
125 }
126 }
127 1 my $crc = $init_value ^ 0xffffffff;
128  
129 1 foreach my $x (unpack ('C*', $input)) {
130 4 $crc = (($crc << 8) & 0xffffff00) ^ $crc32a_table->[(($crc >> 24) & 0xff) ^ ($x & 0xff)];
131 }
132 1 $crc = $crc ^ 0xffffffff;
133  
134 # reverse byteorder
135 1 $crc = ($crc << 24) & 0xff000000 | ($crc << 8) & 0xff0000 | ($crc >> 8) & 0xff00 | ($crc >> 24) & 0xff;
136 1 return $crc;
137 }
138  
139 3 ▶sub mycrc32b {
Subroutine mycrc32b: called CC=8 SCAR=20.8
Pod undocumented
140 3 my ($input, $init_value, $polynomial) = @_;
141  
142 # hash('crc32b', $str);
143 # == perl -I./Digest-CRC-0.22/lib -e 'use Digest::CRC;
144 # $ctx = Digest::CRC->new(width=>32, init=>0xffffffff, xorout=>0xffffffff, refout=>1, poly=>0x4C11DB7, refin=>1, cont=>0);
145 # $ctx->add("test");
146 # print $digest = $ctx->hexdigest;'
147 #
148 3 ▶ $init_value = 0 unless (defined $init_value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $init_value 3 0 3
149 #$polynomial = _reflect(0x04c11db7,32) unless (defined $polynomial);
150 3 ▶ $polynomial = 0xedb88320 unless (defined $polynomial);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $polynomial 3 0 3
151  
152 3 ▶ unless (defined $crc32b_table) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $crc32b_table) 1 2 3
153 1 $crc32b_table = [];
154 1 ▶ for (my $i=0; $i<256; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 256 1 257
155 256 my $x = $i;
156 256 ▶ for (my $j=0; $j<8; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 8) 2048 256 2304
157 2048 ▶ if ($x & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x & 1) { } 1024 1024 2048
158 1024 $x = ($x >> 1) ^ $polynomial;
159 } else {
160 1024 $x = $x >> 1;
161 }
162 }
163 256 push @$crc32b_table, $x;
164 }
165 }
166 3 my $crc = $init_value ^ 0xffffffff;
167  
168 3 foreach my $x (unpack ('C*', $input)) {
169 12 $crc = (($crc >> 8) & 0xffffff) ^ $crc32b_table->[($crc ^ $x) & 0xff];
170 }
171 3 $crc = $crc ^ 0xffffffff;
172 3 return $crc;
173 }
174  
175 # see: https://metacpan.org/dist/PHP-Strings/source/Strings.pm
176 # todo: might use more functions from PHP::Strings module
177 #
178 0 ▶sub stripcslashes {
Subroutine stripcslashes: not called CC=3 SCAR=24.8
Pod undocumented
179 0 my ($str) = @_;
180  
181 0 $str =~ s{
182 \\([abfnrtv\\?'"])
183 |
184 \\(\d\d\d)
185 |
186 \\(x[[:xdigit:]]{2})
187 |
188 \\(x[[:xdigit:]])
189 }{
190 0 ▶ if ( $+ eq 'v' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($+ eq 'v') { } 0 0 0
elsif (length $+ == 1) { } 0 0 0
191 0 "\013";
192 } elsif (length $+ == 1) {
193 0 eval qq{qq/\\$+/};
194 } else {
195 0 chr oct "0$+";
196 }
197 }exg ;
198 0 return $str;
199 }
200  
201 13 ▶sub dyn_replace {
Subroutine dyn_replace: called CC=3 SCAR=11.0
Pod undocumented
202 13 my ($replace) = @_;
203 13 my @groups;
204 {
205 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
206 13 $groups[$_] = $$_ for 1 .. $#-; # the size of @- tells us the number of capturing groups
207 }
208 # For the e modifier preg_replace escapes [' " \ NULL] in the replacement string.
209 # see: https://www.php.net/manual/en/function.preg-replace.php
210 #
211 13 ▶ for (my $i=1; $i < scalar @groups; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @groups) 7 13 20
212 #print ">> dyn_replace $i: $groups[$i]\n";
213 7 $groups[$i] =~ s/(["'\\\0])/\\$1/g;
214 }
215 13 $replace =~ s/\$(\d+)/$groups[$1]/g;
216 13 return $replace;
217 }
218  
219 5 ▶sub dyn_replace_eval {
Subroutine dyn_replace_eval: called CC=3 SCAR=11.0
Pod undocumented
220 5 my ($ctx, $replace) = @_;
221 5 my $parser = $ctx->{parser};
222 5 my $res = dyn_replace($replace);
223  
224 5 my $code = $parser->setstr($res);
225 5 my $parser2 = $parser->subparser();
226 5 my $ctx2 = $ctx->subctx(parser => $parser2);
227 5 my $block = $ctx2->parse_eval($code);
228 5 my $k = $ctx2->exec_eval($block);
229 5 my $str = _joinable_str($parser, $k, '');
230 5 ▶ unless (defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $str) 1 4 5
231 # mark non resolvable code with {{{#stmtX}}} pattern
232 #
233 1 $str = '{{{' . $k . '}}}';
234 }
235 5 ▶ $ctx->{log}->($ctx, 'replace', $replace, "$res -> eval($code) -> $str ($k)") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 5 5
236 5 return $str;
237 }
238  
239 4 ▶sub dyn_result {
Subroutine dyn_result: called CC=6 SCAR=18.9
Pod undocumented
240 4 my ($str, $parser) = @_;
241 4 my @out;
242 my $k;
243 4 my $res;
244  
245 # when the result contains non resolved statements,
246 # then create a chain of concatted expresions.
247 #
248 4 ▶ while ($str =~ /^(.*?)\{\{\{(#\w+\d+)\}\}\}(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(.*?)\{\{\{(#\w+\d+)\}\}\}(.*)$/) 1 4 5
249 1 ▶ if ($1 ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 ne "") 0 1 1
250 0 $k = $parser->setstr($1);
251 0 push(@out, $k);
252 }
253 1 push(@out, $2);
254 1 $str = $3;
255 }
256 4 ▶ if (($str eq '') && (scalar @out > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq '' and scalar @out > 0) { } 1 3 4
Condition66%2/3
$str eq "" and scalar @out > 0
!ll&&!rl&&r
301
MC/DC50%1/2
$str eq "" and scalar @out > 0
$str eq "" scalar @out > 0
Truth table66%2/3
A and B
A= $str eq ""B= scalar @out > 0
ABresult
0X0
100
111
257 1 $res = pop(@out);
258 } else {
259 3 $res = $parser->setstr($str);
260 }
261 4 ▶ while (scalar @out > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @out > 0) 0 4 4
262 0 my $op1 = pop(@out);
263 0 $res = $parser->setexpr('.', $op1, $res);
264 }
265 4 return $res;
266 }
267  
268 13 ▶sub preg_replace {
Subroutine preg_replace: called CC=31 SCAR=44.8
Pod undocumented
269 13 my ($ctx, $_pattern, $_replacement, $str, $mode, $limit) = @_;
270 13 my $parser = $ctx->{parser};
271 13 my $pattern = $parser->get_strval($_pattern);
272 13 my $replacement = $parser->get_strval($_replacement);
273 13 my $cnt = 0;
274 13 my $res;
275 my $k;
276  
277 13 ▶ if ($str eq '#null') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq '#null') { } 1 12 13
278 1 $res = '';
279 } else {
280 12 $res = $parser->get_strval($str);
281 }
282 13 ▶ unless (defined $pattern && defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pattern and defined $res) 0 13 13
Condition33%1/3
defined $pattern and defined $res
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $pattern and defined $res
defined $pattern defined $res
Truth table33%1/3
A and B
A= defined $patternB= defined $res
ABresult
0X0
100
111
283 0 return;
284 }
285 13 my $m = '';
286 13 my $modifier;
287 13 ▶ if ($mode eq 'preg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "preg") 8 5 13
288 8 my ($delim) = $pattern =~ /^(.)/;
289 8 my $delim2;
290  
291 # allow bracket delimiters
292 # https://php.net/regexp.reference.delimiters
293 #
294 8 ▶ if ($delim eq '[') {
Branch: 4 branches
BranchTrueFalseTotal
if ($delim eq '[') { } 0 8 8
elsif ($delim eq '(') { } 0 8 8
elsif ($delim eq '{') { } 1 7 8
elsif ($delim eq '<') { } 0 7 7
295 0 $delim2 = ']';
296 } elsif ($delim eq '(') {
297 0 $delim2 = ')';
298 } elsif ($delim eq '{') {
299 1 $delim2 = '}';
300 } elsif ($delim eq '<') {
301 0 $delim2 = '>';
302 } else {
303 7 $delim2 = $delim;;
304 }
305 # TODO: need to handle escapes in pattern?
306 # https://php.net/manual/en/function.preg-quote.php
307 #
308 8 ▶ if ($pattern =~ m|^\Q$delim\E([^$delim2]*)\Q$delim2\E(\w*)$|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern =~ /^\Q$delim\E([^$delim2]*)\Q$delim2\E(\w*)$/) 8 0 8
309 8 $pattern = $1;
310 8 $modifier = $2;
311 8 ▶ $m .= 'i' if ($modifier =~ /i/);
Branch: 1 branch
BranchTrueFalseTotal
if $modifier =~ /i/ 1 7 8
312 8 ▶ $m .= 'm' if ($modifier =~ /m/);
Branch: 1 branch
BranchTrueFalseTotal
if $modifier =~ /m/ 0 8 8
313 8 ▶ $m .= 's' if ($modifier =~ /s/);
Branch: 1 branch
BranchTrueFalseTotal
if $modifier =~ /s/ 0 8 8
314 8 ▶ $m .= 'x' if ($modifier =~ /x/);
Branch: 1 branch
BranchTrueFalseTotal
if $modifier =~ /x/ 0 8 8
315 }
316 }
317  
318 # don't escape pattern here - it might contain regexp rules
319 # don't escape replacement here - special-chars should not get excaped
320 #
321 13 ▶ if ($limit == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit == 0) { } 0 13 13
322 # delete pattern
323 0 ▶ if ($mode eq 'preg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'preg') { } 0 0 0
324 0 $res =~ s/$pattern//g;
325 } else {
326 0 $res =~ s/\Q$pattern\E//g;
327 }
328 0 $k = $parser->setstr($res);
329 } else {
330 13 ▶ unless (defined $replacement) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $replacement) 0 13 13
331 0 return;
332 }
333  
334 # the replacement might contain backreferences in the
335 # form '\1'. Convert them to '$1' for perl call.
336 #
337 13 ▶ if ($mode eq 'preg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "preg") 8 5 13
338 8 $replacement =~ s/(\\([0-9]))/\$$2/g;
339 }
340  
341 # When the replacement contains backreferences and
342 # it comes from data, it needs to get evaled first.
343 # (eval as string by /ee does not help in this case).
344 #
345 # http://stackoverflow.com/questions/1908159/perl-can-i-store-backreferences-not-their-values-in-variables
346 #
347 13 ▶ if (defined $modifier && $modifier =~ /e/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $modifier and $modifier =~ /e/) { } 4 9 13
Condition100%3/3
defined $modifier and $modifier =~ /e/
!ll&&!rl&&r
544
MC/DC100%2/2
defined $modifier and $modifier =~ /e/
defined $modifier $modifier =~ /e/
Truth table100%3/3
A and B
A= defined $modifierB= $modifier =~ /e/
ABresult
0X0
100
111
348 # eval-modifier deprecated since php-5.5
349 # https://php.net/manual/en/reference.pcre.pattern.modifiers.php#reference.pcre.pattern.modifiers.eval
350 #
351 4 eval { $res =~ s/$pattern/dyn_replace_eval($ctx, $replacement)/eg; };
352 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
353 0 $ctx->{warn}->($ctx, 'replace', $str, "bad preg/e $pattern");
354 0 return;
355 }
356 4 ▶ if (scalar @- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @- > 0) 4 0 4
357 4 $cnt++;
358 }
359 4 $k = dyn_result($res, $parser);
360 } else {
361 9 ▶ if ($limit != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit != -1) { } 0 9 9
362 0 ▶ while ($cnt < $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt < $limit) 0 0 0
363 0 ▶ if ($mode eq 'preg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'preg') { } 0 0 0
364 0 eval { $res =~ s/$pattern/dyn_replace($replacement)/e; };
365 } else {
366 0 eval { $res =~ s/\Q$pattern\E/$replacement/; };
367 }
368 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
369 0 $ctx->{warn}->($ctx, 'replace', $str, "bad preg $pattern");
370 0 return;
371 }
372 0 ▶ if (scalar @- == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @- == 0) 0 0 0
373 # no match found in substitution
374 0 last;
375 }
376 0 $cnt++;
377 }
378 } else {
379 9 ▶ if ($mode eq 'preg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'preg') { } 4 5 9
380 4 eval { $res =~ s/$pattern/dyn_replace($replacement)/eg; };
381 } else {
382 # TODO: use quotemeta($replacement) here?
383 #
384 5 eval { $res =~ s/\Q$pattern\E/$replacement/g; };
385 }
386 9 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 9 9
387 0 $ctx->{warn}->($ctx, 'replace', $str, "bad preg $pattern");
388 0 return;
389 }
390 9 ▶ if (scalar @- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @- > 0) 9 0 9
391 9 $cnt++;
392 }
393 }
394 9 $k = $parser->setstr($res);
395 }
396 }
397 13 ▶ $ctx->{log}->($ctx, 'replace', $str, "[%s]->[%s] %s -> %s", $parser->shortstr($pattern,40), $parser->shortstr($replacement,40), $parser->shortstr($str,40), $parser->shortstr($res,40)) if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 13 13
398 13 return ($k, $cnt);
399 }
400  
401 13 ▶sub preg_replace_subject {
Subroutine preg_replace_subject: called CC=7 SCAR=19.8
Pod undocumented
402 13 my ($ctx, $pattern, $replacement, $str, $mode, $limit) = @_;
403 13 my $parser = $ctx->{parser};
404  
405 13 ▶ if (is_array($pattern)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_array($pattern)) { } 1 12 13
elsif (is_strval($pattern)) { } 12 0 12
406 1 my $arr = $parser->{strmap}{$pattern};
407 1 my $keys = $arr->get_keys();
408 1 my $rep = $replacement;
409 1 my $r_arr;
410 my $r_keys;
411 1 my $cnt = 0;
412  
413 1 ▶ if (is_array($replacement)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($replacement)) 1 0 1
414 1 $r_arr = $parser->{strmap}{$replacement};
415 1 $r_keys = $r_arr->get_keys();
416 }
417 1 foreach my $k (@$keys) {
418 1 my $val = $arr->val($k);
419 1 ▶ if (is_array($replacement)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($replacement)) 1 0 1
420 1 my $rk = shift(@$r_keys);
421 1 $rep = $r_arr->val($rk);
422 }
423 #$ctx->{log}->($ctx, 'replace', $str, "preg $val -> $rep [$str]") if $ctx->{log};
424 1 my ($r, $n) = preg_replace($ctx, $val, $rep, $str, $mode, $limit);
425 1 ▶ if ($limit != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit != -1) 0 1 1
426 0 $limit -= $cnt;
427 }
428 1 $cnt += $n;
429 1 $str = $r;
430 }
431 1 return ($str, $cnt);
432 } elsif (is_strval($pattern)) {
433 12 my ($r, $cnt) = preg_replace($ctx, $pattern, $replacement, $str, $mode, $limit);
434 12 return ($r, $cnt);
435 }
436 0 return;
437 }
438  
439 4 ▶use constant R_VOID => 0x0001;
Subroutine BEGIN: called CC=1 SCAR=0.0
440 4 ▶use constant R_INT => 0x0002;
Subroutine BEGIN: called CC=1 SCAR=0.0
441 4 ▶use constant R_FLOAT => 0x0004;
Subroutine BEGIN: called CC=1 SCAR=0.0
442 4 ▶use constant R_BOOL => 0x0008;
Subroutine BEGIN: called CC=1 SCAR=0.0
443 4 ▶use constant R_STR => 0x0010;
Subroutine BEGIN: called CC=1 SCAR=0.0
444 4 ▶use constant R_ARRAY => 0x0020;
Subroutine BEGIN: called CC=1 SCAR=0.0
445 4 ▶use constant R_OBJECT => 0x0040;
Subroutine BEGIN: called CC=1 SCAR=0.0
446 4 ▶use constant R_CALL => 0x0080;
Subroutine BEGIN: called CC=1 SCAR=0.0
447 4 ▶use constant R_MIXED => 0x0100;
Subroutine BEGIN: called CC=1 SCAR=0.0
448 4 ▶use constant R_FIX => 0x0200; # string not usable by eval
Subroutine BEGIN: called CC=1 SCAR=0.0
449 4 ▶use constant R_FIXSTR => (R_FIX|R_STR);
Subroutine BEGIN: called CC=1 SCAR=0.0
450  
451 # https://php.net/manual/en/function.get-defined-functions.php
452 # list all: php -r '$x = get_defined_functions(); print_r($x);' | less
453 # list standard: php -r '$f=get_extension_funcs("standard"); print_r($f);' | less
454 # list per extension: php -r '$x = get_loaded_extensions(); foreach ($x as $e) { print ("$e: \n"); $f=get_extension_funcs($e); print_r($f); }' | less
455 #
456 4 my %php_funcs_core = (
457 zend_version => { ret => R_FIXSTR },
458 func_num_args => { ret => R_INT },
459 func_get_arg => { ret => R_MIXED },
460 func_get_args => { ret => R_ARRAY },
461 strlen => { ret => R_INT },
462 strcmp => { ret => R_INT },
463 strncmp => { ret => R_INT },
464 strcasecmp => { ret => R_INT },
465 strncasecmp => { ret => R_INT },
466 each => { param => ['#ref0'], ret => R_ARRAY },
467 error_reporting => { ret => R_INT },
468 define => { ret => R_BOOL },
469 defined => { ret => R_BOOL },
470 get_class => { ret => R_STR },
471 get_called_class => { ret => R_STR },
472 get_parent_class => { ret => R_STR },
473 method_exists => { ret => R_BOOL },
474 property_exists => { ret => R_BOOL },
475 class_exists => { ret => R_BOOL },
476 interface_exists => { ret => R_BOOL },
477 function_exists => { ret => R_BOOL },
478 class_alias => { ret => R_BOOL },
479 get_included_files => { ret => R_ARRAY },
480 get_required_files => { ret => R_ARRAY },
481 is_subclass_of => { ret => R_BOOL },
482 is_a => { ret => R_BOOL },
483 get_class_vars => { ret => R_ARRAY },
484 get_object_vars => { ret => R_ARRAY },
485 get_class_methods => { ret => R_ARRAY },
486 trigger_error => { ret => R_BOOL },
487 user_error => { ret => R_BOOL },
488 set_error_handler => { ret => R_CALL },
489 restore_error_handler => { ret => R_BOOL },
490 set_exception_handler => { ret => R_CALL },
491 restore_exception_handler => { ret => R_BOOL },
492 get_declared_classes => { ret => R_ARRAY },
493 get_declared_interfaces => { ret => R_ARRAY },
494 get_defined_functions => { ret => R_ARRAY },
495 get_defined_vars => { ret => R_ARRAY },
496 create_function => { ret => R_STR, callable => 1 },
497 get_resource_type => { ret => R_FIXSTR },
498 get_loaded_extensions => { ret => R_ARRAY },
499 extension_loaded => { ret => R_BOOL },
500 get_extension_funcs => { ret => R_ARRAY },
501 get_defined_constants => { ret => R_ARRAY },
502 debug_backtrace => { ret => R_ARRAY },
503 debug_print_backtrace => { ret => R_VOID },
504 gc_collect_cycles => { ret => R_INT },
505 gc_enabled => { ret => R_BOOL },
506 gc_enable => { ret => R_VOID },
507 gc_disable => { ret => R_VOID },
508 gc_status => { ret => R_ARRAY },
509 );
510  
511 4 my %php_funcs_standard = (
512 exit => { ret => R_VOID }, # is language construct
513 die => { ret => R_VOID }, # is language construct
514 unset => { ret => R_VOID }, # is language construct
515 constant => { ret => R_MIXED },
516 bin2hex => { ret => R_FIXSTR },
517 sleep => { ret => R_INT },
518 usleep => { ret => R_VOID },
519 time_nanosleep => { ret => R_ARRAY|R_BOOL },
520 time_sleep_until => { ret => R_BOOL },
521 strptime => { ret => R_STR },
522 flush => { ret => R_VOID },
523 wordwrap => { ret => R_STR },
524 htmlspecialchars => { ret => R_STR },
525 htmlentities => { ret => R_STR },
526 html_entity_decode => { ret => R_STR },
527 htmlspecialchars_decode => { ret => R_STR },
528 get_html_translation_table => { ret => R_ARRAY },
529 sha1 => { ret => R_FIXSTR },
530 sha1_file => { ret => R_FIXSTR|R_BOOL },
531 md5 => { ret => R_FIXSTR },
532 md5_file => { ret => R_FIXSTR|R_BOOL },
533 crc32 => { ret => R_INT },
534 iptcparse => {},
535 iptcembed => {},
536 getimagesize => {},
537 image_type_to_mime_type => {},
538 image_type_to_extension => {},
539 phpinfo => {},
540 phpversion => {},
541 phpcredits => {},
542 php_logo_guid => {},
543 php_real_logo_guid => {},
544 php_egg_logo_guid => {},
545 zend_logo_guid => {},
546 php_sapi_name => {},
547 php_uname => { ret => R_STR },
548 php_ini_scanned_files => {},
549 php_ini_loaded_file => {},
550 strnatcmp => {},
551 strnatcasecmp => {},
552 substr_count => { ret => R_INT },
553 strspn => {},
554 strcspn => {},
555 strtok => {},
556 strtoupper => {},
557 strtolower => {},
558 strpos => {},
559 stripos => {},
560 strrpos => {},
561 strripos => {},
562 strrev => { ret => R_STR },
563 hebrev => {},
564 hebrevc => {},
565 nl2br => {},
566 basename => {},
567 dirname => {},
568 pathinfo => {},
569 stripslashes => {},
570 stripcslashes => {},
571 strstr => {},
572 stristr => {},
573 strrchr => {},
574 str_shuffle => {},
575 str_word_count => {},
576 str_split => { ret => R_ARRAY },
577 strpbrk => {},
578 substr_compare => {},
579 strcoll => {},
580 money_format => {},
581 substr => {},
582 substr_replace => {},
583 quotemeta => {},
584 ucfirst => {},
585 lcfirst => {},
586 ucwords => {},
587 strtr => {},
588 addslashes => {},
589 addcslashes => {},
590 rtrim => { ret => R_STR },
591 str_replace => {},
592 str_ireplace => {},
593 str_repeat => {},
594 count_chars => {},
595 chunk_split => {},
596 trim => { ret => R_STR },
597 ltrim => { ret => R_STR },
598 strip_tags => {},
599 similar_text => {},
600 explode => {},
601 implode => {},
602 join => {},
603 setlocale => {},
604 localeconv => {},
605 nl_langinfo => {},
606 soundex => {},
607 levenshtein => {},
608 chr => {},
609 ord => {},
610 parse_str => {},
611 str_getcsv => {},
612 str_pad => {},
613 chop => {},
614 strchr => {},
615 sprintf => {},
616 printf => {},
617 vprintf => {},
618 vsprintf => {},
619 fprintf => {},
620 vfprintf => {},
621 sscanf => {},
622 fscanf => {},
623 parse_url => {},
624 urlencode => { ret => R_STR },
625 urldecode => { ret => R_STR },
626 rawurlencode => { ret => R_STR },
627 rawurldecode => { ret => R_STR },
628 http_build_query => {},
629 readlink => {},
630 linkinfo => {},
631 symlink => {},
632 link => {},
633 unlink => {},
634 exec => { param => ['#str0', '#ref0', '#ref0'], ret => R_STR|R_BOOL },
635 system => {},
636 escapeshellcmd => {},
637 escapeshellarg => {},
638 passthru => {},
639 shell_exec => {},
640 proc_open => {},
641 proc_close => {},
642 proc_terminate => {},
643 proc_get_status => {},
644 proc_nice => {},
645 rand => {},
646 srand => {},
647 getrandmax => {},
648 mt_rand => {},
649 mt_srand => {},
650 mt_getrandmax => {},
651 getservbyname => {},
652 getservbyport => {},
653 getprotobyname => {},
654 getprotobynumber => {},
655 getmyuid => {},
656 getmygid => {},
657 getmypid => {},
658 getmyinode => {},
659 getlastmod => {},
660 base64_decode => { cmd => \&cmd_base64_decode, ret => R_STR },
661 base64_encode => { cmd => \&cmd_base64_encode, ret => R_STR },
662 convert_uuencode => {},
663 convert_uudecode => {},
664 abs => {},
665 ceil => {},
666 floor => {},
667 round => {},
668 sin => {},
669 cos => {},
670 tan => {},
671 asin => {},
672 acos => {},
673 atan => {},
674 atanh => {},
675 atan2 => {},
676 sinh => {},
677 cosh => {},
678 tanh => {},
679 asinh => {},
680 acosh => {},
681 expm1 => {},
682 log1p => {},
683 pi => {},
684 is_finite => {},
685 is_nan => {},
686 is_infinite => {},
687 pow => { ret => R_INT|R_FLOAT },
688 exp => {},
689 log => {},
690 log10 => {},
691 sqrt => {},
692 hypot => {},
693 deg2rad => {},
694 rad2deg => {},
695 bindec => {},
696 hexdec => {},
697 octdec => {},
698 decbin => {},
699 decoct => {},
700 dechex => {},
701 base_convert => {},
702 number_format => {},
703 fmod => {},
704 inet_ntop => {},
705 inet_pton => {},
706 ip2long => {},
707 long2ip => {},
708 getenv => { cmd => \&PHP::Decode::Transformer::cmd_getenv, ret => R_STR },
709 putenv => {},
710 getopt => {},
711 sys_getloadavg => {},
712 microtime => {},
713 gettimeofday => {},
714 getrusage => {},
715 uniqid => {},
716 quoted_printable_decode => {},
717 quoted_printable_encode => {},
718 convert_cyr_string => {},
719 get_current_user => {},
720 set_time_limit => {},
721 get_cfg_var => {},
722 magic_quotes_runtime => {},
723 set_magic_quotes_runtime => {},
724 get_magic_quotes_gpc => {},
725 get_magic_quotes_runtime => {},
726 import_request_variables => {},
727 error_log => {},
728 error_get_last => {},
729 call_user_func => { callable => 1 },
730 call_user_func_array => { callable => 1 },
731 call_user_method => { callable => 1 },
732 call_user_method_array => { callable => 1 },
733 forward_static_call => { callable => 1 },
734 forward_static_call_array => { callable => 1 },
735 serialize => {},
736 unserialize => {},
737 var_dump => {},
738 var_export => {},
739 debug_zval_dump => {},
740 print_r => {},
741 memory_get_usage => {},
742 memory_get_peak_usage => {},
743 register_shutdown_function => { callable => 1 },
744 register_tick_function => { callable => 1 },
745 unregister_tick_function => {},
746 highlight_file => {},
747 show_source => {},
748 highlight_string => {},
749 php_strip_whitespace => {},
750 ini_get => {},
751 ini_get_all => {},
752 ini_set => {},
753 ini_alter => {},
754 ini_restore => {},
755 get_include_path => {},
756 set_include_path => {},
757 restore_include_path => {},
758 setcookie => {},
759 setrawcookie => {},
760 header => {},
761 header_remove => {},
762 headers_sent => {},
763 headers_list => {},
764 connection_aborted => {},
765 connection_status => {},
766 ignore_user_abort => {},
767 parse_ini_file => {},
768 parse_ini_string => {},
769 is_uploaded_file => {},
770 move_uploaded_file => {},
771 gethostbyaddr => {},
772 gethostbyname => {},
773 gethostbynamel => {},
774 gethostname => {},
775 dns_check_record => {},
776 checkdnsrr => {},
777 dns_get_mx => {},
778 getmxrr => {},
779 dns_get_record => {},
780 intval => { ret => R_INT },
781 floatval => { ret => R_FLOAT },
782 doubleval => { ret => R_FLOAT },
783 strval => { ret => R_STR },
784 gettype => {},
785 settype => {},
786 empty => { ret => R_BOOL },
787 isset => { ret => R_BOOL },
788 is_null => { ret => R_BOOL },
789 is_resource => { ret => R_BOOL },
790 is_bool => { ret => R_BOOL },
791 is_long => { ret => R_BOOL },
792 is_float => { ret => R_BOOL },
793 is_int => { ret => R_BOOL },
794 is_integer => { ret => R_BOOL },
795 is_double => { ret => R_BOOL },
796 is_real => { ret => R_BOOL },
797 is_numeric => { ret => R_BOOL },
798 is_string => { ret => R_BOOL },
799 is_array => { ret => R_BOOL },
800 is_object => { ret => R_BOOL },
801 is_scalar => { ret => R_BOOL },
802 is_callable => { ret => R_BOOL },
803 pclose => {},
804 popen => {},
805 readfile => {},
806 rewind => {},
807 rmdir => {},
808 umask => {},
809 fclose => {},
810 feof => {},
811 fgetc => {},
812 fgets => {},
813 fgetss => {},
814 fread => {},
815 fopen => {},
816 fpassthru => {},
817 ftruncate => {},
818 fstat => {},
819 fseek => {},
820 ftell => {},
821 fflush => {},
822 fwrite => {},
823 fputs => {},
824 mkdir => {},
825 rename => {},
826 copy => {},
827 tempnam => {},
828 tmpfile => {},
829 file => {},
830 file_get_contents => {},
831 file_put_contents => {},
832 stream_select => {},
833 stream_context_create => {},
834 stream_context_set_params => {},
835 stream_context_get_params => {},
836 stream_context_set_option => {},
837 stream_context_get_options => {},
838 stream_context_get_default => {},
839 stream_context_set_default => {},
840 stream_filter_prepend => {},
841 stream_filter_append => {},
842 stream_filter_remove => {},
843 stream_socket_client => {},
844 stream_socket_server => {},
845 stream_socket_accept => {},
846 stream_socket_get_name => {},
847 stream_socket_recvfrom => {},
848 stream_socket_sendto => {},
849 stream_socket_enable_crypto => {},
850 stream_socket_shutdown => {},
851 stream_socket_pair => {},
852 stream_copy_to_stream => {},
853 stream_get_contents => {},
854 stream_supports_lock => {},
855 fgetcsv => {},
856 fputcsv => {},
857 flock => {},
858 get_meta_tags => {},
859 stream_set_read_buffer => {},
860 stream_set_write_buffer => {},
861 set_file_buffer => {},
862 set_socket_blocking => {},
863 stream_set_blocking => {},
864 socket_set_blocking => {},
865 stream_get_meta_data => {},
866 stream_get_line => {},
867 stream_wrapper_register => {},
868 stream_register_wrapper => {},
869 stream_wrapper_unregister => {},
870 stream_wrapper_restore => {},
871 stream_get_wrappers => {},
872 stream_get_transports => {},
873 stream_resolve_include_path => {},
874 stream_is_local => {},
875 get_headers => {},
876 stream_set_timeout => {},
877 socket_set_timeout => {},
878 socket_get_status => {},
879 realpath => {},
880 fnmatch => {},
881 fsockopen => {},
882 pfsockopen => {},
883 pack => {},
884 unpack => {},
885 get_browser => {},
886 crypt => {},
887 opendir => {},
888 closedir => {},
889 chdir => {},
890 chroot => {},
891 getcwd => {},
892 rewinddir => {},
893 readdir => {},
894 dir => {},
895 scandir => {},
896 glob => {},
897 fileatime => {},
898 filectime => {},
899 filegroup => {},
900 fileinode => {},
901 filemtime => {},
902 fileowner => {},
903 fileperms => {},
904 filesize => {},
905 filetype => {},
906 file_exists => {},
907 is_writable => {},
908 is_writeable => {},
909 is_readable => {},
910 is_executable => {},
911 is_file => {},
912 is_dir => {},
913 is_link => {},
914 stat => {},
915 lstat => {},
916 chown => {},
917 chgrp => {},
918 lchown => {},
919 lchgrp => {},
920 chmod => {},
921 touch => {},
922 clearstatcache => {},
923 disk_total_space => {},
924 disk_free_space => {},
925 diskfreespace => {},
926 realpath_cache_size => {},
927 realpath_cache_get => {},
928 mail => {},
929 ezmlm_hash => {},
930 openlog => {},
931 syslog => {},
932 closelog => {},
933 define_syslog_variables => {},
934 lcg_value => {},
935 metaphone => {},
936 ob_start => { cmd => \&PHP::Decode::Transformer::cmd_ob_start, ret => R_BOOL, callable => 1 },
937 ob_flush => {},
938 ob_clean => {},
939 ob_end_flush => { cmd => \&PHP::Decode::Transformer::cmd_ob_end_flush, ret => R_BOOL, callable => 1 },
940 ob_end_clean => { cmd => \&PHP::Decode::Transformer::cmd_ob_end_clean, ret => R_BOOL },
941 ob_get_flush => {},
942 ob_get_clean => {},
943 ob_get_length => {},
944 ob_get_level => {},
945 ob_get_status => {},
946 ob_get_contents => {},
947 ob_implicit_flush => {},
948 ob_list_handlers => {},
949 ksort => { param => ['#ref0'], ret => R_BOOL },
950 krsort => { param => ['#ref0'], ret => R_BOOL },
951 natsort => { param => ['#ref0'], ret => R_BOOL },
952 natcasesort => { param => ['#ref0'], ret => R_BOOL },
953 asort => { param => ['#ref0'], ret => R_BOOL },
954 arsort => { param => ['#ref0'], ret => R_BOOL },
955 sort => { param => ['#ref0'], ret => R_BOOL },
956 rsort => { param => ['#ref0'], ret => R_BOOL },
957 usort => { param => ['#ref0'], ret => R_BOOL, callable => 1 },
958 uasort => { param => ['#ref0'], ret => R_BOOL, callable => 1 },
959 uksort => { param => ['#ref0'], ret => R_BOOL, callable => 1 },
960 shuffle => { param => ['#ref0'], ret => R_BOOL },
961 array_walk => { param => ['#ref0'], ret => R_BOOL, callable => 1 },
962 array_walk_recursive => { param => ['#ref0'], ret => R_BOOL, callable => 1 },
963 count => {},
964 end => { param => ['#ref0'], ret => R_MIXED },
965 prev => { param => ['#ref0'], ret => R_MIXED },
966 next => { param => ['#ref0'], ret => R_MIXED },
967 reset => { param => ['#ref0'], ret => R_MIXED },
968 current => {},
969 key => {},
970 min => {},
971 max => {},
972 in_array => {},
973 array_search => {},
974 extract => { param => ['#ref0'], ret => R_INT },
975 compact => {},
976 array_fill => {},
977 array_fill_keys => {},
978 range => { ret => R_ARRAY },
979 array_multisort => { param => ['#ref0'], ret => R_BOOL },
980 array_push => { param => ['#ref0'], ret => R_INT },
981 array_pop => { param => ['#ref0'], ret => R_MIXED },
982 array_shift => { param => ['#ref0'], ret => R_MIXED },
983 array_unshift => { param => ['#ref0'], ret => R_INT },
984 array_splice => { param => ['#ref0'], ret => R_ARRAY },
985 array_slice => {},
986 array_merge => {},
987 array_merge_recursive => {},
988 array_replace => {},
989 array_replace_recursive => {},
990 array_keys => {},
991 array_values => {},
992 array_count_values => {},
993 array_reverse => {},
994 array_reduce => {},
995 array_pad => {},
996 array_flip => {},
997 array_change_key_case => {},
998 array_rand => {},
999 array_unique => {},
1000 array_intersect => {},
1001 array_intersect_key => {},
1002 array_intersect_ukey => { callable => 1 },
1003 array_uintersect => { callable => 1 },
1004 array_intersect_assoc => {},
1005 array_uintersect_assoc => { callable => 1 },
1006 array_intersect_uassoc => { callable => 1 },
1007 array_uintersect_uassoc => { callable => 1 },
1008 array_diff => {},
1009 array_diff_key => {},
1010 array_diff_ukey => { callable => 1 },
1011 array_udiff => { callable => 1 },
1012 array_diff_assoc => {},
1013 array_udiff_assoc => { callable => 1 },
1014 array_diff_uassoc => { callable => 1 },
1015 array_udiff_uassoc => { callable => 1 },
1016 array_sum => {},
1017 array_product => {},
1018 array_filter => { callable => 1 },
1019 array_map => { callable => 1, ret => R_ARRAY },
1020 array_chunk => {},
1021 array_combine => {},
1022 array_key_exists => {},
1023 pos => {},
1024 sizeof => {},
1025 key_exists => {},
1026 assert => {},
1027 assert_options => {},
1028 version_compare => {},
1029 ftok => {},
1030 str_rot13 => {},
1031 stream_get_filters => {},
1032 stream_filter_register => {},
1033 stream_bucket_make_writeable => {},
1034 stream_bucket_prepend => {},
1035 stream_bucket_append => {},
1036 stream_bucket_new => {},
1037 output_add_rewrite_var => {},
1038 output_reset_rewrite_vars => {},
1039 sys_get_temp_dir => {},
1040 );
1041  
1042 4 my %php_funcs_date = (
1043 strtotime => {},
1044 date => {},
1045 idate => {},
1046 gmdate => {},
1047 mktime => {},
1048 gmmktime => {},
1049 checkdate => {},
1050 strftime => {},
1051 gmstrftime => {},
1052 time => {},
1053 localtime => {},
1054 getdate => {},
1055 date_create => {},
1056 date_create_from_format => {},
1057 date_parse => {},
1058 date_parse_from_format => {},
1059 date_get_last_errors => {},
1060 date_format => {},
1061 date_modify => {},
1062 date_add => {},
1063 date_sub => {},
1064 date_timezone_get => {},
1065 date_timezone_set => {},
1066 date_offset_get => {},
1067 date_diff => {},
1068 date_time_set => {},
1069 date_date_set => {},
1070 date_isodate_set => {},
1071 date_timestamp_set => {},
1072 date_timestamp_get => {},
1073 timezone_open => {},
1074 timezone_name_get => {},
1075 timezone_name_from_abbr => {},
1076 timezone_offset_get => {},
1077 timezone_transitions_get => {},
1078 timezone_location_get => {},
1079 timezone_identifiers_list => {},
1080 timezone_abbreviations_list => {},
1081 timezone_version_get => {},
1082 date_interval_create_from_date_string => {},
1083 date_interval_format => {},
1084 date_default_timezone_set => {},
1085 date_default_timezone_get => {},
1086 date_sunrise => {},
1087 date_sunset => {},
1088 date_sun_info => {},
1089 );
1090  
1091 4 my %php_funcs_pcre = (
1092 preg_match => {},
1093 preg_match_all => {},
1094 preg_replace => { ret => R_STR|R_ARRAY },
1095 preg_replace_callback => { callable => 1, ret => R_STR|R_ARRAY },
1096 preg_replace_callback_array => { callable => 1, ret => R_STR|R_ARRAY },
1097 preg_filter => {},
1098 preg_split => { ret => R_ARRAY },
1099 preg_quote => {},
1100 preg_grep => {},
1101 preg_last_error => {},
1102 );
1103  
1104 4 my %php_funcs_posix = (
1105 posix_kill => {},
1106 posix_getpid => {},
1107 posix_getppid => {},
1108 posix_getuid => {},
1109 posix_setuid => {},
1110 posix_geteuid => {},
1111 posix_seteuid => {},
1112 posix_getgid => {},
1113 posix_setgid => {},
1114 posix_getegid => {},
1115 posix_setegid => {},
1116 posix_getgroups => {},
1117 posix_getlogin => {},
1118 posix_getpgrp => {},
1119 posix_setsid => {},
1120 posix_setpgid => {},
1121 posix_getpgid => {},
1122 posix_getsid => {},
1123 posix_uname => {},
1124 posix_times => {},
1125 posix_ctermid => {},
1126 posix_ttyname => {},
1127 posix_isatty => {},
1128 posix_getcwd => {},
1129 posix_mkfifo => {},
1130 posix_mknod => {},
1131 posix_access => {},
1132 posix_getgrnam => {},
1133 posix_getgrgid => {},
1134 posix_getpwnam => {},
1135 posix_getpwuid => {},
1136 posix_getrlimit => {},
1137 posix_get_last_error => {},
1138 posix_errno => {},
1139 posix_strerror => {},
1140 posix_initgroups => {},
1141 );
1142  
1143 4 my %php_funcs_curl = (
1144 curl_init => {},
1145 curl_copy_handle => {},
1146 curl_version => {},
1147 curl_setopt => {},
1148 curl_setopt_array => {},
1149 curl_exec => {},
1150 curl_getinfo => {},
1151 curl_error => {},
1152 curl_errno => {},
1153 curl_close => {},
1154 curl_multi_init => {},
1155 curl_multi_add_handle => {},
1156 curl_multi_remove_handle => {},
1157 curl_multi_select => {},
1158 curl_multi_exec => {},
1159 curl_multi_getcontent => {},
1160 curl_multi_info_read => {},
1161 curl_multi_close => {},
1162 );
1163  
1164 4 my %php_funcs_zlib = (
1165 readgzfile => {},
1166 gzrewind => {},
1167 gzclose => {},
1168 gzeof => {},
1169 gzgetc => {},
1170 gzgets => {},
1171 gzgetss => {},
1172 gzread => {},
1173 gzopen => {},
1174 gzpassthru => {},
1175 gzseek => {},
1176 gztell => {},
1177 gzwrite => {},
1178 gzputs => {},
1179 gzfile => {},
1180 gzcompress => {},
1181 gzuncompress => {},
1182 gzdeflate => {},
1183 gzinflate => {},
1184 gzdecode => {},
1185 gzencode => {},
1186 ob_gzhandler => {},
1187 zlib_get_coding_type => {},
1188 );
1189  
1190 4 my %php_funcs_mysql = (
1191 mysql_connect => {},
1192 mysql_pconnect => {},
1193 mysql_close => {},
1194 mysql_select_db => {},
1195 mysql_query => {},
1196 mysql_unbuffered_query => {},
1197 mysql_db_query => {},
1198 mysql_list_dbs => {},
1199 mysql_list_tables => {},
1200 mysql_list_fields => {},
1201 mysql_list_processes => {},
1202 mysql_error => {},
1203 mysql_errno => {},
1204 mysql_affected_rows => {},
1205 mysql_insert_id => {},
1206 mysql_result => {},
1207 mysql_num_rows => {},
1208 mysql_num_fields => {},
1209 mysql_fetch_row => {},
1210 mysql_fetch_array => {},
1211 mysql_fetch_assoc => {},
1212 mysql_fetch_object => {},
1213 mysql_data_seek => {},
1214 mysql_fetch_lengths => {},
1215 mysql_fetch_field => {},
1216 mysql_field_seek => {},
1217 mysql_free_result => {},
1218 mysql_field_name => {},
1219 mysql_field_table => {},
1220 mysql_field_len => {},
1221 mysql_field_type => {},
1222 mysql_field_flags => {},
1223 mysql_escape_string => {},
1224 mysql_real_escape_string => {},
1225 mysql_stat => {},
1226 mysql_thread_id => {},
1227 mysql_client_encoding => {},
1228 mysql_ping => {},
1229 mysql_get_client_info => {},
1230 mysql_get_host_info => {},
1231 mysql_get_proto_info => {},
1232 mysql_get_server_info => {},
1233 mysql_info => {},
1234 mysql_set_charset => {},
1235 mysql => {},
1236 mysql_fieldname => {},
1237 mysql_fieldtable => {},
1238 mysql_fieldlen => {},
1239 mysql_fieldtype => {},
1240 mysql_fieldflags => {},
1241 mysql_selectdb => {},
1242 mysql_freeresult => {},
1243 mysql_numfields => {},
1244 mysql_numrows => {},
1245 mysql_listdbs => {},
1246 mysql_listtables => {},
1247 mysql_listfields => {},
1248 mysql_db_name => {},
1249 mysql_dbname => {},
1250 mysql_tablename => {},
1251 mysql_table_name => {},
1252 );
1253  
1254 4 my %php_funcs_hash = (
1255 hash => { ret => R_STR },
1256 hash_file => {},
1257 hash_hmac => {},
1258 hash_hmac_file => {},
1259 hash_init => {},
1260 hash_update => {},
1261 hash_update_stream => {},
1262 hash_update_file => {},
1263 hash_final => {},
1264 hash_copy => {},
1265 hash_algos => {},
1266 hash_hmac_algos => {},
1267 hash_pbkdf2 => {},
1268 hash_equals => {},
1269 hash_hkdf => {},
1270 mhash_get_block_size => {},
1271 mhash_get_hash_name => {},
1272 mhash_keygen_s2k => {},
1273 mhash_count => {},
1274 mhash => {},
1275 );
1276  
1277 4 my %php_funcs_libxml = (
1278 libxml_set_streams_context => {},
1279 libxml_use_internal_errors => {},
1280 libxml_get_last_error => {},
1281 libxml_get_errors => {},
1282 libxml_clear_errors => {},
1283 libxml_disable_entity_loader => {},
1284 libxml_set_external_entity_loader => {},
1285 );
1286  
1287 4 my %php_funcs_filter = (
1288 filter_has_var => { ret => R_BOOL },
1289 filter_input => { ret => R_MIXED },
1290 filter_var => { ret => R_MIXED },
1291 filter_input_array => { ret => R_MIXED },
1292 filter_var_array => { ret => R_ARRAY|R_BOOL },
1293 filter_list => { ret => R_ARRAY },
1294 filter_id => { ret => R_INT|R_BOOL },
1295 );
1296  
1297 4 my %php_funcs_json = (
1298 json_encode => { ret => R_STR },
1299 json_decode => { ret => R_MIXED },
1300 json_last_error => { ret => R_INT },
1301 json_last_error_msg => { ret => R_STR },
1302 );
1303  
1304 4 my %php_funcs_spl = (
1305 class_implements => {},
1306 class_parents => {},
1307 class_uses => {},
1308 spl_autoload => {},
1309 spl_autoload_call => {},
1310 spl_autoload_extensions => {},
1311 spl_autoload_functions => {},
1312 spl_autoload_register => {},
1313 spl_autoload_unregister => {},
1314 spl_classes => {},
1315 spl_object_hash => {},
1316 spl_object_id => {},
1317 iterator_apply => {},
1318 iterator_count => {},
1319 iterator_to_array => {},
1320 );
1321  
1322 4 my %php_funcs_session = (
1323 session_name => { ret => R_STR },
1324 session_module_name => { ret => R_STR },
1325 session_save_path => { ret => R_STR },
1326 session_id => { ret => R_STR },
1327 session_create_id => { ret => R_STR },
1328 session_regenerate_id => { ret => R_BOOL },
1329 session_decode => { ret => R_BOOL },
1330 session_encode => { ret => R_STR },
1331 session_destroy => { ret => R_BOOL },
1332 session_unset => { ret => R_BOOL },
1333 session_gc => { ret => R_INT },
1334 session_get_cookie_params => { ret => R_BOOL },
1335 session_write_close => { ret => R_BOOL },
1336 session_abort => { ret => R_BOOL },
1337 session_reset => { ret => R_BOOL },
1338 session_status => { ret => R_INT },
1339 session_register_shutdown => { ret => R_VOID },
1340 session_commit => { ret => R_BOOL },
1341 session_set_save_handler => { ret => R_BOOL },
1342 session_cache_limiter => { ret => R_STR },
1343 session_cache_expire => { ret => R_INT },
1344 session_set_cookie_params => { ret => R_ARRAY },
1345 session_start => { ret => R_BOOL },
1346 );
1347  
1348 4 my %php_funcs_pdo = (
1349 pdo_drivers => {},
1350 );
1351  
1352 4 my %php_funcs_xml = (
1353 xml_parser_create => {},
1354 xml_parser_create_ns => {},
1355 xml_set_object => {},
1356 xml_set_element_handler => {},
1357 xml_set_character_data_handler => {},
1358 xml_set_processing_instruction_handler => {},
1359 xml_set_default_handler => {},
1360 xml_set_unparsed_entity_decl_handler => {},
1361 xml_set_notation_decl_handler => {},
1362 xml_set_external_entity_ref_handler => {},
1363 xml_set_start_namespace_decl_handler => {},
1364 xml_set_end_namespace_decl_handler => {},
1365 xml_parse => {},
1366 xml_parse_into_struct => {},
1367 xml_get_error_code => {},
1368 xml_error_string => {},
1369 xml_get_current_line_number => {},
1370 xml_get_current_column_number => {},
1371 xml_get_current_byte_index => {},
1372 xml_parser_free => {},
1373 xml_parser_set_option => {},
1374 xml_parser_get_option => {},
1375 );
1376  
1377 4 my %php_funcs_calendar = (
1378 cal_days_in_month => {},
1379 cal_from_jd => {},
1380 cal_info => {},
1381 cal_to_jd => {},
1382 easter_date => {},
1383 easter_days => {},
1384 frenchtojd => {},
1385 gregoriantojd => {},
1386 jddayofweek => {},
1387 jdmonthname => {},
1388 jdtofrench => {},
1389 jdtogregorian => {},
1390 jdtojewish => {},
1391 jdtojulian => {},
1392 jdtounix => {},
1393 jewishtojd => {},
1394 juliantojd => {},
1395 unixtojd => {},
1396 );
1397  
1398 4 my %php_funcs_ctype = (
1399 ctype_alnum => { ret => R_BOOL },
1400 ctype_alpha => { ret => R_BOOL },
1401 ctype_cntrl => { ret => R_BOOL },
1402 ctype_digit => { ret => R_BOOL },
1403 ctype_lower => { ret => R_BOOL },
1404 ctype_graph => { ret => R_BOOL },
1405 ctype_print => { ret => R_BOOL },
1406 ctype_punct => { ret => R_BOOL },
1407 ctype_space => { ret => R_BOOL },
1408 ctype_upper => { ret => R_BOOL },
1409 ctype_xdigit => { ret => R_BOOL },
1410 );
1411  
1412 4 my %php_funcs_gettext = (
1413 textdomain => { ret => R_STR },
1414 gettext => { ret => R_STR },
1415 '_' => { ret => R_STR },
1416 dgettext => { ret => R_STR },
1417 dcgettext => { ret => R_STR },
1418 bindtextdomain => { ret => R_STR },
1419 ngettext => { ret => R_STR},
1420 dngettext => { ret => R_STR },
1421 dcngettext => { ret => R_STR },
1422 bind_textdomain_codeset => { ret => R_STR },
1423 );
1424  
1425 4 my %php_funcs_iconv = (
1426 iconv_strlen => { ret => R_INT },
1427 iconv_substr => { ret => R_STR },
1428 iconv_strpos => { ret => R_INT },
1429 iconv_strrpos => { ret => R_INT },
1430 iconv_mime_encode => { ret => R_STR },
1431 iconv_mime_decode => { ret => R_STR },
1432 iconv_mime_decode_headers => { ret => R_STR|R_ARRAY },
1433 iconv => { ret => R_STR },
1434 iconv_set_encoding => { ret => R_BOOL },
1435 iconv_get_encoding => { ret => R_STR|R_ARRAY },
1436 ob_iconv_handler => { callable => 1, ret => R_STR },
1437 );
1438  
1439 4 my %php_funcs_socket = (
1440 socket_select => {},
1441 socket_create_listen => {},
1442 socket_accept => {},
1443 socket_set_nonblock => {},
1444 socket_set_block => {},
1445 socket_listen => {},
1446 socket_close => {},
1447 socket_write => {},
1448 socket_read => { ret => R_STR },
1449 socket_getsockname => {},
1450 socket_getpeername => {},
1451 socket_create => {},
1452 socket_connect => {},
1453 socket_strerror => {},
1454 socket_bind => {},
1455 socket_recv => {},
1456 socket_send => {},
1457 socket_recvfrom => {},
1458 socket_sendto => {},
1459 socket_get_option => {},
1460 socket_getopt => {},
1461 socket_set_option => {},
1462 socket_setopt => {},
1463 socket_create_pair => {},
1464 socket_shutdown => {},
1465 socket_last_error => {},
1466 socket_clear_error => {},
1467 socket_import_stream => {},
1468 socket_export_stream => {},
1469 socket_sendmsg => {},
1470 socket_recvmsg => {},
1471 socket_cmsg_space => {},
1472 socket_addrinfo_lookup => {},
1473 socket_addrinfo_connect => {},
1474 socket_addrinfo_bind => {},
1475 socket_addrinfo_explain => {},
1476 );
1477  
1478 4 my %php_funcs_tokenizer = (
1479 token_get_all => {},
1480 token_name => {},
1481 );
1482  
1483 # https://developer.wordpress.org/reference/functions/
1484 #
1485 4 my %php_funcs_wordpress = (
1486 get_option => { ret => R_MIXED },
1487 update_option => { ret => R_BOOL },
1488 add_post_meta => { ret => R_INT },
1489 get_categories => { ret => R_ARRAY },
1490 wp_add_post_tags => { ret => R_ARRAY },
1491 wp_create_category => { ret => R_INT },
1492 get_posts => { ret => R_MIXED },
1493 get_post => { ret => R_MIXED },
1494 wp_insert_post => { ret => R_INT },
1495 wp_update_post => { ret => R_INT },
1496 wp_delete_post => { ret => R_MIXED },
1497 wp_set_post_tags => { ret => R_ARRAY },
1498 get_post_meta => { ret => R_MIXED },
1499 add_post_meta => { ret => R_INT },
1500 update_post_meta => { ret => R_INT },
1501 delete_post_meta => { ret => R_BOOL },
1502 get_users => { ret => R_ARRAY },
1503 get_user_by => { ret => R_MIXED },
1504 get_userdata => { ret => R_MIXED },
1505 wp_insert_user => { ret => R_INT },
1506 wp_update_user => { ret => R_INT },
1507 wp_delete_user => { ret => R_BOOL },
1508 get_user_meta => { ret => R_MIXED },
1509 add_user_meta => { ret => R_INT },
1510 update_user_meta => { ret => R_INT },
1511 delete_user_meta => { ret => R_BOOL },
1512 get_user_setting => { ret => R_MIXED },
1513 delete_user_setting => { ret => R_BOOL },
1514 wp_schedule_single_event => { ret => R_BOOL },
1515 wp_clear_scheduled_hook => { ret => R_INT },
1516 wp_unschedule_event => { ret => R_BOOL },
1517 wp_upload_dir => { ret => R_ARRAY },
1518 );
1519  
1520 4 my %php_funcs = (
1521 Core => \%php_funcs_core,
1522 standard => \%php_funcs_standard,
1523 date => \%php_funcs_date,
1524 pcre => \%php_funcs_pcre,
1525 posix => \%php_funcs_posix,
1526 curl => \%php_funcs_curl,
1527 zlib => \%php_funcs_zlib,
1528 mysql => \%php_funcs_mysql,
1529 hash => \%php_funcs_hash,
1530 libxml => \%php_funcs_libxml,
1531 filter => \%php_funcs_filter,
1532 json => \%php_funcs_json,
1533 spl => \%php_funcs_spl,
1534 session => \%php_funcs_session,
1535 pdo => \%php_funcs_pdo,
1536 xml => \%php_funcs_xml,
1537 calendar => \%php_funcs_calendar,
1538 ctype => \%php_funcs_ctype,
1539 gettext => \%php_funcs_gettext,
1540 iconv => \%php_funcs_iconv,
1541 socket => \%php_funcs_socket,
1542 tokenizer=> \%php_funcs_tokenizer,
1543 #wordpress=> \%php_funcs_wordpress,
1544 );
1545  
1546 1555 ▶sub get_php_func {
Subroutine get_php_func: called CC=3 SCAR=11.0
Pod undocumented
1547 1555 my ($cmd) = @_;
1548  
1549 1555 $cmd = lc($cmd);
1550  
1551 1555 foreach my $e (keys %php_funcs) {
1552 28818 ▶ if (exists $php_funcs{$e}{$cmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $php_funcs{$e}{$cmd}) 672 28146 28818
1553 672 my $f = $php_funcs{$e}{$cmd};
1554 672 return $f;
1555 }
1556 }
1557 return
1558 883 }
1559  
1560 348 ▶sub func_may_call_callbacks {
Subroutine func_may_call_callbacks: called CC=4 SCAR=13.9
Pod undocumented
1561 348 my ($cmd) = @_;
1562  
1563 348 $cmd = lc($cmd);
1564  
1565 348 ▶ if ($cmd =~ /^(eval|include|include_once|require|require_once)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^(eval|include|include_once|require|require_once)$/) 0 348 348
1566 0 return 1;
1567 }
1568 348 my $f = get_php_func($cmd);
1569 348 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 102 246 348
1570 102 ▶ if (exists $f->{callable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $f->{"callable"}) 5 97 102
1571 5 return 1;
1572 }
1573 97 return 0;
1574 }
1575 246 return 1;
1576 }
1577  
1578 3 ▶sub func_may_return_string {
Subroutine func_may_return_string: called CC=6 SCAR=19.5
Pod undocumented
1579 3 my ($cmd) = @_;
1580  
1581 3 $cmd = lc($cmd);
1582  
1583 3 ▶ if ($cmd =~ /^(include|include_once|require|require_once)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^(include|include_once|require|require_once)$/) 0 3 3
1584 0 return 0;
1585 }
1586 3 my $f = get_php_func($cmd);
1587 3 ▶ if (defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f) 3 0 3
1588 3 ▶ if (exists $f->{ret}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $f->{"ret"}) 3 0 3
1589 3 ▶ unless ($f->{ret} & (R_STR|R_MIXED)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f->{"ret"} & 272) 1 2 3
1590 1 return 0;
1591 }
1592 2 ▶ if ($f->{ret} & R_FIX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"ret"} & 512) 0 2 2
1593 0 return 0;
1594 }
1595 }
1596 2 return 1;
1597 }
1598 0 return 1;
1599 }
1600  
1601 22 ▶sub cmd_base64_decode {
Subroutine cmd_base64_decode: called CC=8 SCAR=22.5
Pod undocumented
1602 22 my ($ctx, $cmd, $args) = @_;
1603 22 my $parser = $ctx->{parser};
1604  
1605 22 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 22 0 22
1606 22 my $s = $parser->get_strval($$args[0]);
1607 22 my $php50_compat;
1608 22 my $strict = 0;
1609 22 ▶ if (scalar @$args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 1) 0 22 22
1610 0 $strict = $parser->get_strval($$args[1]);
1611 }
1612 22 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 18 4 22
1613 # older php-versions (< php5.1) treated blanks in base64 string as '+':
1614 # https://php.net/manual/en/function.base64-decode.php
1615 #
1616 # perl ignores any character not part of the 65-character base64 subset.
1617 # https://perldoc.perl.org/MIME::Base64
1618 #
1619 18 ▶ if ($php50_compat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($php50_compat) 0 18 18
1620 0 $s =~ s/ /+/g; # incompatible with ignore-rule
1621 }
1622 18 ▶ if ($strict && !($s =~ /^[A-Za-z0-9\/+]*=*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict and not $s =~ m[^[A-Za-z0-9/+]*=*$]) 0 18 18
Condition33%1/3
$strict and not $s =~ m[^[A-Za-z0-9/+]*=*$]
!ll&&!rl&&r
1800
MC/DC0%0/2
$strict and not $s =~ m[^[A-Za-z0-9/+]*=*$]
$strict not $s =~ m[^[A-Za-z0-9/+]*=*$]
Truth table33%1/3
A and not(B)
A= $strictB= not $s =~ m[^[A-Za-z0-9/+]*=*$]
ABresult
0X0
100
111
1623 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$$args[0] contains non-strict chars");
1624 }
1625 18 my $decoded;
1626 {
1627 # suppress decode_base64() warnings (premature end of data, etc.)
1628 18 local $^W = 0;
1629 18 $decoded = decode_base64($s);
1630 }
1631 18 ▶ if (defined $decoded) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decoded) 18 0 18
1632 #$decoded = decode_input($decoded); # might convert wide strings back to internal perl utf-8 encoding
1633 #$ctx->{log}->($ctx, 'cmd', $cmd, "%d:[%s]->%d:[%s]", length($s), $parser->shortstr($s,40), length($decoded), $parser->shortstr($decoded,40)) if $ctx->{log};
1634 18 return $parser->setstr($decoded);
1635 }
1636 }
1637 }
1638 4 return;
1639 }
1640  
1641 3 ▶sub cmd_base64_encode {
Subroutine cmd_base64_encode: called CC=5 SCAR=17.1
Pod undocumented
1642 3 my ($ctx, $cmd, $args) = @_;
1643 3 my $parser = $ctx->{parser};
1644  
1645 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
1646 3 my $s = $parser->get_strval($$args[0]);
1647 3 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 3 0 3
1648 # might convert from internal perl wide string representation to utf-8 stream
1649 # see: https://perldoc.perl.org/MIME::Base64
1650 #
1651 #my $bytestr = encode('utf-8', $s);
1652 #my $encoded = encode_base64($bytestr,'');
1653 3 my $encoded = encode_base64($s,'');
1654 3 ▶ if (defined $encoded) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoded) 3 0 3
1655 3 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "%d:[%s]->%d:[%s]", length($s), $parser->shortstr($s,40), length($encoded), $parser->shortstr($encoded,40)) if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 3 3
1656 3 return $parser->setstr($encoded);
1657 }
1658 }
1659 }
1660 0 return;
1661 }
1662  
1663 27 ▶sub get_refvar_val {
Subroutine get_refvar_val: called CC=12 SCAR=27.4
Pod undocumented
1664 27 my ($ctx, $var) = @_;
1665 27 my $parser = $ctx->{parser};
1666  
1667 27 ▶ unless ($ctx->{infunction} && !$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"infunction"} and not $ctx->{"incall"}) 27 0 27
Condition33%1/3
$ctx->{"infunction"} and not $ctx->{"incall"}
!ll&&!rl&&r
2700
MC/DC0%0/2
$ctx->{"infunction"} and not $ctx->{"incall"}
$ctx->{"infunction"} not $ctx->{"incall"}
Truth table33%1/3
A and not(B)
A= $ctx->{"infunction"}B= not $ctx->{"incall"}
ABresult
0X0
100
111
1668 27 ▶ if (is_variable($var)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_variable($var)) { } 26 1 27
elsif ($var =~ /^(\#elem\d+)$/) { } 1 0 1
1669 26 my $val = $ctx->getvar($var, 1);
1670 26 ▶ if (!defined $val && $ctx->is_superglobal($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val and $ctx->is_superglobal($var)) 3 23 26
Condition66%2/3
not defined $val and $ctx->is_superglobal($var)
!ll&&!rl&&r
2303
MC/DC50%1/2
not defined $val and $ctx->is_superglobal($var)
not defined $val $ctx->is_superglobal($var)
Truth table66%2/3
not(A) and B
A= not defined $valB= $ctx->is_superglobal($var)
ABresult
0X0
100
111
1671 3 return; # unknown contents
1672 }
1673 23 return (1, $val); # valid
1674 } elsif ($var =~ /^(\#elem\d+)$/) {
1675 1 my ($v, $i) = @{$parser->{strmap}{$var}};
1676 1 my ($basevar, $has_index, $idxstr) = $ctx->resolve_variable($var, 0);
1677 1 ▶ if ($has_index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_index) 1 0 1
1678 1 my $basestr = $ctx->exec_statement($basevar, 0);
1679 1 ▶ if (defined $basestr && is_array($basestr) && defined $idxstr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $basestr and is_array($basestr) and defined $idxstr) 1 0 1
Condition33%2/6
defined $basestr and is_array($basestr) and defined $idxstr
!ll&&!rl&&r
001
defined $basestr and is_array($basestr)
!ll&&!rl&&r
001
MC/DC0%0/3
defined $basestr and is_array($basestr) and defined $idxstr
defined $basestr is_array($basestr) defined $idxstr
Truth table25%1/4
A and B and C
A= defined $basestrB= is_array($basestr)C= defined $idxstr
ABCresult
0XX0
10X0
1100
1111
1680 1 ▶ $idxstr = $parser->setstr('') if is_null($idxstr); # null maps to '' array index
Branch: 1 branch
BranchTrueFalseTotal
if is_null($idxstr) 0 1 1
1681 1 my $arr = $parser->{strmap}{$basestr};
1682 1 my $val = $arr->get($idxstr);
1683 1 return (1, $val); # valid
1684 }
1685 }
1686 }
1687 }
1688 0 return;
1689 }
1690  
1691 8 ▶sub set_refvar_val {
Subroutine set_refvar_val: called CC=4 SCAR=20.7
Pod undocumented
1692 8 my ($ctx, $var, $val) = @_;
1693 8 my $parser = $ctx->{parser};
1694  
1695 8 ▶ if (is_variable($var)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_variable($var)) { } 8 0 8
elsif ($var =~ /^(\#elem\d+)$/) { } 0 0 0
1696 8 $ctx->setvar($var, $val, 1);
1697 } elsif ($var =~ /^(\#elem\d+)$/) {
1698 0 my $sub = $parser->setexpr('=', $var, $val);
1699 0 my $had_assigns = $ctx->have_assignments();
1700 0 my $k = $ctx->exec_statement($sub);
1701 0 ▶ if (!$had_assigns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($had_assigns) 0 0 0
1702 # remove any pending assignments, to avoid variable
1703 # insertion for the 'sub'-assignmenmt.
1704 # The full array assignment is inserted after the loop
1705 #
1706 0 $ctx->discard_pending_assignments();
1707 }
1708 }
1709 8 return;
1710 }
1711  
1712 # check for php numeric string
1713 # https://www.php.net/manual/en/language.types.numeric-strings.php
1714 #
1715 18 ▶sub is_numeric_str {
Subroutine is_numeric_str: called CC=1 SCAR=0.0
Pod undocumented
1716 18 my ($s) = @_;
1717 18 return $s =~ /^\s*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?\s*$/;
1718 }
1719  
1720 # integer steps from $start to $end (might be descending)
1721 #
1722 13 ▶sub range_steps {
Subroutine range_steps: called CC=2 SCAR=6.9
Pod undocumented
1723 13 my ($start, $end, $step) = @_;
1724 13 ▶ my $dir = ($start <= $end) ? $step : -$step;
Branch: 1 branch
BranchTrueFalseTotal
$start <= $end ? : 8 5 13
1725 13 my $cnt = int(abs($end - $start) / $step);
1726  
1727 13 return map { $start + $_ * $dir } (0 .. $cnt);
1728 }
1729  
1730 516 ▶sub exec_cmd {
Subroutine exec_cmd: called CC=667 SCAR=107.8
Pod documented
1731 516 my ($ctx, $cmd, $args) = @_;
1732 516 my $parser = $ctx->{parser};
1733 516 my $res;
1734 516 my $to_num = 0;
1735  
1736 # some dynamic function names are created from mixed-style strings
1737 # see: https://www.php.net/manual/en/functions.user-defined.php
1738 # function names are case-insensitive for the ASCII characters A to Z.
1739 #
1740 516 $cmd = lc($cmd);
1741  
1742 516 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "args (%s)", join(', ', @$args)) if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 516 516
1743  
1744 516 my $f = get_php_func($cmd);
1745  
1746 516 ▶ if (defined $f && exists $f->{cmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f and exists $f->{"cmd"}) 27 489 516
Condition100%3/3
defined $f and exists $f->{"cmd"}
!ll&&!rl&&r
24824127
MC/DC100%2/2
defined $f and exists $f->{"cmd"}
defined $f exists $f->{"cmd"}
Truth table100%3/3
A and B
A= defined $fB= exists $f->{"cmd"}
ABresult
0X0
100
111
1747 27 my $k = &{$f->{cmd}}(@_);
1748 27 return $k;
1749 }
1750  
1751 489 ▶ if ($cmd eq 'unescape') {
Branch: 102 branches
BranchTrueFalseTotal
if ($cmd eq 'unescape') { } 0 489 489
elsif ($cmd eq 'str_rot13') { } 0 489 489
elsif ($cmd eq 'strrev') { } 1 488 489
elsif ($cmd eq 'strtoupper') { } 3 485 488
elsif ($cmd eq 'strtolower') { } 0 485 485
elsif ($cmd eq 'ucfirst') { } 0 485 485
elsif ($cmd eq 'lcfirst') { } 0 485 485
elsif ($cmd eq 'dirname') { } 0 485 485
elsif ($cmd eq 'basename') { } 0 485 485
elsif ($cmd eq 'strlen') { } 15 470 485
elsif ($cmd eq 'chr') { } 8 462 470
elsif ($cmd eq 'ord') { } 13 449 462
elsif ($cmd eq 'hexdec') { } 2 447 449
elsif ($cmd eq 'octdec') { } 0 447 447
elsif ($cmd eq 'bindec') { } 0 447 447
elsif ($cmd eq 'dechex') { } 0 447 447
elsif ($cmd eq 'octhex') { } 0 447 447
elsif ($cmd eq 'binhex') { } 0 447 447
elsif ($cmd eq 'bin2hex') { } 3 444 447
elsif ($cmd eq 'hex2bin') { } 1 443 444
elsif ($cmd eq 'floor') { } 0 443 443
elsif ($cmd eq 'ceil') { } 0 443 443
elsif ($cmd eq 'intval') { } 3 440 443
elsif ($cmd eq 'strval') { } 1 439 440
elsif ($cmd eq 'boolval') { } 0 439 439
elsif ($cmd eq 'floatval') { } 0 439 439
elsif ($cmd eq 'pow') { } 0 439 439
elsif ($cmd eq 'gzinflate') { } 1 438 439
elsif ($cmd eq 'gzdecode') { } 1 437 438
elsif ($cmd eq 'gzuncompress') { } 1 436 437
elsif ($cmd eq 'crc32') { } 1 435 436
elsif ($cmd eq 'hash') { } 6 429 435
elsif ($cmd eq 'rawurldecode') { } 0 429 429
elsif ($cmd eq 'rawurlencode') { } 1 428 429
elsif ($cmd eq 'urldecode') { } 0 428 428
elsif ($cmd eq 'urlencode') { } 1 427 428
elsif ($cmd eq 'trim') { } 0 427 427
elsif ($cmd eq 'ltrim') { } 0 427 427
elsif ($cmd eq 'rtrim' or $cmd eq 'chop') { } 0 427 427
elsif ($cmd eq 'stripslashes') { } 0 427 427
elsif ($cmd eq 'stripcslashes') { } 0 427 427
elsif ($cmd eq 'strpos') { } 2 425 427
elsif ($cmd eq 'substr') { } 2 423 425
elsif ($cmd eq 'substr_count') { } 1 422 423
elsif ($cmd eq 'strstr') { } 0 422 422
elsif ($cmd eq 'strtr') { } 3 419 422
elsif ($cmd eq 'strcmp') { } 1 418 419
elsif ($cmd eq 'strncmp') { } 0 418 418
elsif ($cmd eq 'strcasecmp') { } 0 418 418
elsif ($cmd eq 'strncasecmp') { } 1 417 418
elsif ($cmd eq 'str_repeat') { } 1 416 417
elsif ($cmd eq 'str_replace') { } 4 412 416
elsif ($cmd eq 'ereg_replace') { } 0 412 412
elsif ($cmd eq 'preg_replace') { } 7 405 412
elsif ($cmd eq 'preg_quote') { } 0 405 405
elsif ($cmd eq 'md5') { } 1 404 405
elsif ($cmd eq 'sha1') { } 1 403 404
elsif ($cmd eq 'levenshtein') { } 0 403 403
elsif ($cmd eq 'str_split') { } 0 403 403
elsif ($cmd eq 'preg_split') { } 1 402 403
elsif ($cmd eq 'explode') { } 0 402 402
elsif ($cmd eq 'implode' or $cmd eq 'join') { } 4 398 402
elsif ($cmd eq 'range') { } 14 384 398
elsif ($cmd eq 'count' or $cmd eq 'sizeof') { } 3 381 384
elsif ($cmd eq 'htmlspecialchars' or $cmd eq 'htmlentities') { } 0 381 381
elsif ($cmd eq 'htmlspecialchars_decode' or $cmd eq 'html_entity_decode') { } 0 381 381
elsif ($cmd eq 'pack') { } 2 379 381
elsif ($cmd eq 'unpack') { } 1 378 379
elsif ($cmd eq 'sprintf') { } 1 377 378
elsif ($cmd eq 'array_push') { } 2 375 377
elsif ($cmd eq 'array_pop') { } 3 372 375
elsif ($cmd eq 'array_unshift') { } 3 369 372
elsif ($cmd eq 'array_shift') { } 5 364 369
elsif ($cmd eq 'each') { } 5 359 364
elsif ($cmd eq 'reset') { } 1 358 359
elsif ($cmd eq 'next') { } 4 354 358
elsif ($cmd eq 'prev') { } 1 353 354
elsif ($cmd eq 'end') { } 1 352 353
elsif ($cmd eq 'current' or $cmd eq 'pos') { } 1 351 352
elsif ($cmd eq 'key') { } 0 351 351
elsif ($cmd eq 'array_map') { } 2 349 351
elsif ($cmd eq 'array_walk') { } 2 347 349
elsif ($cmd eq 'array_rand') { } 2 345 347
elsif ($cmd eq 'round') { } 1 344 345
elsif ($cmd eq 'rand' or $cmd eq 'mt_rand') { } 0 344 344
elsif ($cmd eq 'empty') { } 15 329 344
elsif ($cmd eq 'is_array') { } 3 326 329
elsif ($cmd eq 'is_null') { } 15 311 326
elsif ($cmd eq 'is_null_weak') { } 1 310 311
elsif ($cmd eq 'isset') { } 11 299 310
elsif ($cmd eq 'define') { } 3 296 299
elsif ($cmd eq 'function_exists') { } 10 286 296
elsif ($cmd eq 'create_function') { } 12 274 286
elsif ($cmd eq 'call_user_func') { } 3 271 274
elsif ($cmd eq 'call_user_func_array') { } 1 270 271
elsif ($cmd eq 'file') { } 0 270 270
elsif ($cmd eq 'file_get_contents') { } 1 269 270
elsif ($cmd eq 'reset') { } 0 269 269
elsif ($cmd eq 'fopen') { } 3 266 269
elsif ($cmd eq 'fclose') { } 2 264 266
elsif ($cmd eq 'fread') { } 0 264 264
elsif ($cmd eq 'fgets') { } 0 264 264
1752 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1753 0 my $s = $parser->get_strval($$args[0]);
1754 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1755 0 $res = $s;
1756 0 $res =~ s/%([0-9a-fA-F]{2})/chr(hex($1))/ge;
1757 }
1758 }
1759 } elsif ($cmd eq 'str_rot13') {
1760 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1761 0 my $s = $parser->get_strval($$args[0]);
1762 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1763 0 $res = $s;
1764 0 $res =~ tr/A-Za-z/N-ZA-Mn-za-m/;
1765 }
1766 }
1767 } elsif ($cmd eq 'strrev') {
1768 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
1769 1 my $s = $parser->get_strval($$args[0]);
1770 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
1771 1 $res = reverse $s;
1772 }
1773 }
1774 } elsif ($cmd eq 'strtoupper') {
1775 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
1776 3 my $s = $parser->get_strval($$args[0]);
1777 3 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 2 1 3
1778 2 $res = uc($s);
1779 }
1780 }
1781 } elsif ($cmd eq 'strtolower') {
1782 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1783 0 my $s = $parser->get_strval($$args[0]);
1784 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1785 0 $res = lc($s);
1786 }
1787 }
1788 } elsif ($cmd eq 'ucfirst') {
1789 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1790 0 my $s = $parser->get_strval($$args[0]);
1791 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1792 0 $res = ucfirst($s);
1793 }
1794 }
1795 } elsif ($cmd eq 'lcfirst') {
1796 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1797 0 my $s = $parser->get_strval($$args[0]);
1798 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1799 0 $res = lcfirst($s);
1800 }
1801 }
1802 } elsif ($cmd eq 'dirname') {
1803 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1804 0 my $s = $parser->get_strval($$args[0]);
1805 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1806 0 $res = dirname($s);
1807 }
1808 }
1809 } elsif ($cmd eq 'basename') {
1810 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1811 0 my $s = $parser->get_strval($$args[0]);
1812 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1813 0 $res = basename($s);
1814 }
1815 }
1816 } elsif ($cmd eq 'strlen') {
1817 15 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 15 0 15
1818 15 my $val = $$args[0];
1819 15 ▶ if (is_array($val)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_array($val)) { } 0 15 15
elsif (is_null($val)) { } 1 14 15
elsif (is_strval($val)) { } 8 6 14
1820 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "len of array $val taken -> 0");
1821 0 $res = 0;
1822 0 $to_num = 1;
1823 } elsif (is_null($val)) {
1824 1 $res = 0;
1825 1 $to_num = 1;
1826 } elsif (is_strval($val)) {
1827 8 my $s = $parser->get_strval($val);
1828 8 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 8 0 8
1829 8 $res = length($s);
1830 8 $to_num = 1;
1831 }
1832 }
1833 }
1834 } elsif ($cmd eq 'chr') {
1835 8 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 8 0 8
1836 8 my $s = $parser->get_strval($$args[0]);
1837 8 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 7 1 8
1838 7 $res = chr(int($s) & 0xff);
1839 }
1840 }
1841 } elsif ($cmd eq 'ord') {
1842 13 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 13 0 13
1843 13 my $s = $parser->get_strval($$args[0]);
1844 13 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 11 2 13
1845 11 $res = ord($s);
1846 11 $to_num = 1;
1847 }
1848 }
1849 } elsif ($cmd eq 'hexdec') {
1850 2 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 2 0 2
1851 2 my $s = $parser->get_strval($$args[0]);
1852 2 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 2 0 2
1853 2 $res = hex($s);
1854 2 $to_num = 1;
1855 }
1856 }
1857 } elsif ($cmd eq 'octdec') {
1858 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1859 0 my $s = $parser->get_strval($$args[0]);
1860 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1861 0 $res = oct($s);
1862 0 $to_num = 1;
1863 }
1864 }
1865 } elsif ($cmd eq 'bindec') {
1866 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1867 0 my $s = $parser->get_strval($$args[0]);
1868 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1869 0 $res = unpack('N', pack('B32', substr('0' x 32 . $s, -32)));
1870 0 $to_num = 1;
1871 }
1872 }
1873 } elsif ($cmd eq 'dechex') {
1874 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1875 0 my $s = $parser->get_strval($$args[0]);
1876 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1877 0 $res = sprintf("%x", $s);
1878 }
1879 }
1880 } elsif ($cmd eq 'octhex') {
1881 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1882 0 my $s = $parser->get_strval($$args[0]);
1883 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1884 0 $res = sprintf("%o", $s);
1885 }
1886 }
1887 } elsif ($cmd eq 'binhex') {
1888 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1889 0 my $s = $parser->get_strval($$args[0]);
1890 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1891 0 $res = sprintf("%b", $s);
1892 }
1893 }
1894 } elsif ($cmd eq 'bin2hex') {
1895 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
1896 3 my $s = $parser->get_strval($$args[0]);
1897 3 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 3 0 3
1898 3 $res = unpack('H*', $s);
1899 }
1900 }
1901 } elsif ($cmd eq 'hex2bin') {
1902 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
1903 1 my $s = $parser->get_strval($$args[0]);
1904 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
1905 1 $res = pack('H*', $s);
1906 }
1907 }
1908 } elsif ($cmd eq 'floor') {
1909 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1910 0 my $s = $parser->get_strval($$args[0]);
1911 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1912 0 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
1913 0 $res = int($s);
1914 0 $to_num = 1;
1915 }
1916 }
1917 } elsif ($cmd eq 'ceil') {
1918 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1919 0 my $s = $parser->get_strval($$args[0]);
1920 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1921 0 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
1922 0 $res = int($s + 0.99);
1923 0 $to_num = 1;
1924 }
1925 }
1926 } elsif ($cmd eq 'intval') {
1927 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
1928 3 my $s = $parser->get_strval($$args[0]);
1929 3 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 3 0 3
1930 3 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 3 3
1931 3 $res = int(PHP::Decode::Op::to_num($s));
1932 3 $to_num = 1;
1933 }
1934 }
1935 } elsif ($cmd eq 'strval') {
1936 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
1937 1 my $s = $parser->get_strval($$args[0]);
1938 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
1939 1 $res = "$s";
1940 }
1941 }
1942 } elsif ($cmd eq 'boolval') {
1943 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1944 0 my $s = $parser->get_strval($$args[0]);
1945 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1946 0 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
1947 0 ▶ if ($s eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq '0') { } 0 0 0
1948 0 $res = 0;
1949 } else {
1950 0 $res = 1;
1951 }
1952 0 $to_num = 1;
1953 }
1954 }
1955 } elsif ($cmd eq 'floatval') {
1956 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
1957 0 my $s = $parser->get_strval($$args[0]);
1958 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
1959 0 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
1960 0 $res = $s + 0;
1961 0 $to_num = 1;
1962 }
1963 }
1964 } elsif ($cmd eq 'pow') {
1965 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
1966 0 my $s = $parser->get_strval($$args[0]);
1967 0 my $e = $parser->get_strval($$args[1]);
1968 0 ▶ if (defined $s && defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $e) 0 0 0
Condition0%0/3
defined $s and defined $e
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and defined $e
defined $s defined $e
Truth table0%0/3
A and B
A= defined $sB= defined $e
ABresult
0X0
100
111
1969 0 ▶ $s = 0 if ($s eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
1970 0 ▶ $e = 0 if ($e eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "" 0 0 0
1971 0 $res = $s ** $e;
1972 0 $to_num = 1;
1973 }
1974 }
1975 } elsif ($cmd eq 'gzinflate') {
1976 1 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 1 0 1
1977 1 my $s = $parser->get_strval($$args[0]);
1978 1 my $maxlen = '0';
1979 1 ▶ if (scalar @$args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 1) 0 1 1
1980 0 $maxlen = $parser->get_strval($$args[1]);
1981 0 ▶ $maxlen = 0 if ($maxlen eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $maxlen eq "" 0 0 0
1982 }
1983 1 ▶ if (defined $s && (defined $maxlen && ($maxlen eq '0'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and (defined $maxlen and $maxlen eq 0)) 1 0 1
Condition33%2/6
defined $s and (defined $maxlen and $maxlen eq 0)
!ll&&!rl&&r
001
defined $maxlen and $maxlen eq 0
!ll&&!rl&&r
001
MC/DC0%0/3
defined $s and (defined $maxlen and $maxlen eq 0)
defined $s defined $maxlen $maxlen eq 0
Truth table25%1/4
A and B and C
A= defined $sB= defined $maxlenC= $maxlen eq 0
ABCresult
0XX0
10X0
1100
1111
1984 1 my ($i, $istatus) = Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS));
1985 1 my ($output, $ostatus) = $i->inflate($s);
1986 1 ▶ if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) 1 0 1
1987 1 $res = $output;
1988 }
1989 }
1990 }
1991 } elsif ($cmd eq 'gzdecode') {
1992 1 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 1 0 1
1993 1 my $s = $parser->get_strval($$args[0]);
1994 1 my $maxlen = '0';
1995 1 ▶ if (scalar @$args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 1) 0 1 1
1996 0 $maxlen = $parser->get_strval($$args[1]);
1997 0 ▶ $maxlen = 0 if ($maxlen eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $maxlen eq "" 0 0 0
1998 }
1999 1 ▶ if (defined $s && (defined $maxlen && ($maxlen eq '0'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and (defined $maxlen and $maxlen eq 0)) 1 0 1
Condition33%2/6
defined $s and (defined $maxlen and $maxlen eq 0)
!ll&&!rl&&r
001
defined $maxlen and $maxlen eq 0
!ll&&!rl&&r
001
MC/DC0%0/3
defined $s and (defined $maxlen and $maxlen eq 0)
defined $s defined $maxlen $maxlen eq 0
Truth table25%1/4
A and B and C
A= defined $sB= defined $maxlenC= $maxlen eq 0
ABCresult
0XX0
10X0
1100
1111
2000 # http://www.faqs.org/rfcs/rfc1952.html
2001 #
2002 1 ▶ if (substr($s, 0, 3) eq "\x1f\x8b\x08") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($s, 0, 3) eq "\37\213\b") 1 0 1
2003 1 my $off = 10;
2004 1 my $flag = ord(substr($s, 3, 1));
2005 1 ▶ if ($flag > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag > 0) 0 1 1
2006 0 ▶ if ($flag & 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 4) 0 0 0
2007 0 my ($xlen) = unpack('v', substr($s, $off, 2));
2008 0 $off = $off + 2 + $xlen;
2009 }
2010 0 ▶ if ($flag & 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 8) 0 0 0
2011 0 $off = index($s, "\0", $off) + 1;
2012 }
2013 0 ▶ if ($flag & 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 16) 0 0 0
2014 0 $off = index($s, "\0", $off) + 1;
2015 }
2016 0 ▶ if ($flag & 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 2) 0 0 0
2017 0 $off = $off + 2;
2018 }
2019 }
2020 1 my $b = substr($s, $off, -8);
2021  
2022 1 my ($i, $istatus) = Compress::Zlib::inflateInit(-WindowBits => -(MAX_WBITS));
2023 1 my ($output, $ostatus) = $i->inflate($b);
2024 1 ▶ if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) 1 0 1
2025 1 $res = $output;
2026 }
2027 }
2028 }
2029 }
2030 } elsif ($cmd eq 'gzuncompress') {
2031 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2032 1 my $s = $parser->get_strval($$args[0]);
2033 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2034 1 $res = Compress::Zlib::uncompress($s);
2035 }
2036 }
2037 } elsif ($cmd eq 'crc32') {
2038 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2039 1 my $s = $parser->get_strval($$args[0]);
2040 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2041 1 $res = mycrc32b($s);
2042 1 $to_num = 1;
2043 }
2044 }
2045 } elsif ($cmd eq 'hash') {
2046 6 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 6 0 6
2047 6 my $a = $parser->get_strval($$args[0]);
2048 6 my $s = $parser->get_strval($$args[1]);
2049 6 my $raw = '0';
2050 6 ▶ if (scalar @$args > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 2) 2 4 6
2051 2 $raw = $parser->get_strval($$args[2]);
2052 }
2053 6 ▶ if (defined $a && defined $s && defined $raw) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a and defined $s and defined $raw) 6 0 6
Condition33%2/6
defined $a and defined $s and defined $raw
!ll&&!rl&&r
006
defined $a and defined $s
!ll&&!rl&&r
006
MC/DC0%0/3
defined $a and defined $s and defined $raw
defined $a defined $s defined $raw
Truth table25%1/4
A and B and C
A= defined $aB= defined $sC= defined $raw
ABCresult
0XX0
10X0
1100
1111
2054 6 my $output;
2055 6 ▶ if ($a eq 'crc32') {
Branch: 4 branches
BranchTrueFalseTotal
if ($a eq 'crc32') { } 1 5 6
elsif ($a eq 'crc32b') { } 2 3 5
elsif ($a eq 'sha1') { } 1 2 3
elsif ($a eq 'md5') { } 2 0 2
2056 1 $output = pack('N', mycrc32a($s));
2057 } elsif ($a eq 'crc32b') {
2058 2 $output = pack('N', mycrc32b($s));
2059 } elsif ($a eq 'sha1') {
2060 1 $output = sha1($s);
2061 } elsif ($a eq 'md5') {
2062 2 $output = md5($s);
2063 }
2064 6 ▶ if (defined $output) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output) 6 0 6
2065 6 ▶ if ($raw eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw eq '0') { } 4 2 6
2066 #$res = sprintf("%x", $output);
2067 4 $res = unpack('H*', ''.$output);
2068 } else {
2069 2 $res = $output;
2070 }
2071 }
2072 }
2073 }
2074 } elsif ($cmd eq 'rawurldecode') {
2075 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2076 0 my $s = $parser->get_strval($$args[0]);
2077 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2078 # no '+'->' ' conversion here
2079 0 $res = URI::Escape::uri_unescape($s);
2080 }
2081 }
2082 } elsif ($cmd eq 'rawurlencode') {
2083 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2084 1 my $s = $parser->get_strval($$args[0]);
2085 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2086 # no ' '->'+' conversion here
2087 # default safe RFC3986 characters are: "A-Za-z0-9\-\._~"
2088 1 $res = URI::Escape::uri_escape($s);
2089 }
2090 }
2091 } elsif ($cmd eq 'urldecode') {
2092 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2093 0 my $s = $parser->get_strval($$args[0]);
2094 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2095 0 $s =~ s/\+/ /g;
2096 0 $res = URI::Escape::uri_unescape($s);
2097 }
2098 }
2099 } elsif ($cmd eq 'urlencode') {
2100 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2101 1 my $s = $parser->get_strval($$args[0]);
2102 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2103 # default safe characters are here: "A-Za-z0-9\-\._"
2104 # see: php/ext/standard/url.c
2105 1 $res = URI::Escape::uri_escape($s, "^A-Za-z0-9\-\._ ");
2106 1 $res =~ s/ /\+/g;
2107 }
2108 }
2109 } elsif ($cmd eq 'trim') {
2110 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2111 0 my $s = $parser->get_strval($$args[0]);
2112 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2113 0 $res = $s;
2114 0 $res =~ s/^\s+|\s+$//g;
2115 }
2116 }
2117 } elsif ($cmd eq 'ltrim') {
2118 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2119 0 my $s = $parser->get_strval($$args[0]);
2120 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2121 0 $res = $s;
2122 0 $res =~ s/^\s+//;
2123 }
2124 }
2125 ▶ } elsif (($cmd eq 'rtrim') || ($cmd eq 'chop')) {
Condition33%1/3
$cmd eq "rtrim" or $cmd eq "chop"
l!l&&r!l&&!r
00427
MC/DC0%0/2
$cmd eq "rtrim" or $cmd eq "chop"
$cmd eq "rtrim" $cmd eq "chop"
Truth table33%1/3
A or B
A= $cmd eq "rtrim"B= $cmd eq "chop"
ABresult
1X1
011
000
2126 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2127 0 my $s = $parser->get_strval($$args[0]);
2128 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2129 0 $res = $s;
2130 0 $res =~ s/\s+$//;
2131 }
2132 }
2133 } elsif ($cmd eq 'stripslashes') {
2134 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2135 0 my $s = $parser->get_strval($$args[0]);
2136 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2137 0 $res = $s;
2138 0 $res =~ s/\\(\'|\"|\\)/$1/g;
2139 }
2140 }
2141 } elsif ($cmd eq 'stripcslashes') {
2142 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2143 0 my $s = $parser->get_strval($$args[0]);
2144 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2145 0 $res = stripcslashes($s);
2146 }
2147 }
2148 } elsif ($cmd eq 'strpos') {
2149 2 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 2 0 2
2150 2 my $s = $parser->get_strval($$args[0]);
2151 2 my $p = $parser->get_strval($$args[1]);
2152 2 my $off = 0;
2153 2 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 1 1 2
2154 1 $off = $parser->get_strval($$args[2]);
2155 1 ▶ $off = 0 if ($off eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $off eq "" 0 1 1
2156 }
2157 2 ▶ if (defined $s && defined $p) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $p) 2 0 2
Condition33%1/3
defined $s and defined $p
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and defined $p
defined $s defined $p
Truth table33%1/3
A and B
A= defined $sB= defined $p
ABresult
0X0
100
111
2158 2 $res = index($s, $p, $off);
2159 2 $to_num = 1;
2160 }
2161 }
2162 } elsif ($cmd eq 'substr') {
2163 2 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 2 0 2
2164 2 my $s = $parser->get_strval($$args[0]);
2165 2 my $off = $parser->get_strval($$args[1]);
2166 2 ▶ if (defined $s && defined $off) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $off) 2 0 2
Condition33%1/3
defined $s and defined $off
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and defined $off
defined $s defined $off
Truth table33%1/3
A and B
A= defined $sB= defined $off
ABresult
0X0
100
111
2167 2 ▶ $off = 0 if ($off eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $off eq "" 0 2 2
2168 2 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) { } 1 1 2
2169 1 my $len = $parser->get_strval($$args[2]);
2170 1 ▶ if (defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) 1 0 1
2171 1 ▶ $len = 0 if ($len eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $len eq "" 0 1 1
2172 1 $res = substr($s, $off, $len);
2173 }
2174 } else {
2175 1 $res = substr($s, $off);
2176 }
2177 }
2178 }
2179 } elsif ($cmd eq 'substr_count') {
2180 1 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 1 0 1
2181 1 my $s = $parser->get_strval($$args[0]);
2182 1 my $p = $parser->get_strval($$args[1]);
2183 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2184 1 my $sub = $s;
2185 1 ▶ if (scalar @$args > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 2) 1 0 1
2186 1 my $off = $parser->get_strval($$args[2]);
2187 1 ▶ if (scalar @$args > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 3) { } 0 1 1
2188 0 my $len = $parser->get_strval($$args[3]);
2189 0 $sub = substr($s, $off, $len);
2190 } else {
2191 1 $sub = substr($s, $off);
2192 }
2193 }
2194 1 $res = () = $sub =~ /\Q$p\E/g;
2195 1 $to_num=1;
2196 }
2197 }
2198 } elsif ($cmd eq 'strstr') {
2199 0 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 0 0 0
2200 0 my $s = $parser->get_strval($$args[0]);
2201 0 my $p = $parser->get_strval($$args[1]);
2202 0 ▶ if (defined $s && defined $p) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $p) 0 0 0
Condition0%0/3
defined $s and defined $p
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and defined $p
defined $s defined $p
Truth table0%0/3
A and B
A= defined $sB= defined $p
ABresult
0X0
100
111
2203 0 my $off = index($s, $p);
2204 0 ▶ if (defined $off) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) 0 0 0
2205 0 my $before = 0;
2206 0 ▶ if (scalar @$args > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 2) 0 0 0
2207 0 $before = $parser->get_strval($$args[2]);
2208 }
2209 0 ▶ if ($before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before) { } 0 0 0
2210 0 $res = substr($s, 0, $off);
2211 } else {
2212 0 $res = substr($s, $off);
2213 }
2214 }
2215 }
2216 }
2217 } elsif ($cmd eq 'strtr') {
2218 # https://www.php.net/manual/en/function.strtr.php
2219 #
2220 # if from and to have different lengths, the extra characters in
2221 # the longer of the two are ignored. The length of string will be
2222 # the same as the return value's.
2223 #
2224 3 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 3 0 3
2225 3 my $str = $parser->get_strval($$args[0]);
2226 3 my $from = $parser->get_strval($$args[1]);
2227 3 my $to = $parser->get_strval($$args[2]);
2228 3 my $org = $str;
2229  
2230 3 ▶ if (defined $str && defined $from && defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and defined $from and defined $to) 3 0 3
Condition33%2/6
defined $str and defined $from and defined $to
!ll&&!rl&&r
003
defined $str and defined $from
!ll&&!rl&&r
003
MC/DC0%0/3
defined $str and defined $from and defined $to
defined $str defined $from defined $to
Truth table25%1/4
A and B and C
A= defined $strB= defined $fromC= defined $to
ABCresult
0XX0
10X0
1100
1111
2231 # for from > to perl would skip characters missing in 'to',
2232 # for to > from perl would substitue the last char with the full suffix.
2233 #
2234 3 ▶ if (length($from) > length($to)) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $from > length $to) { } 1 2 3
elsif (length $to > length $from) { } 1 1 2
2235 1 $to .= substr($from, length($from)-1);
2236 } elsif (length($to) > length($from)) {
2237 1 $from .= substr($to, length($to)-1);
2238 }
2239 # tr needs eval to use variables
2240 #
2241 3 eval "\$str =~ tr/\Q$from\E/\Q$to\E/;";
2242 3 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 3 0 3
2243 3 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[%s]->[%s] [%s]->[%s]", $parser->shortstr($from,40), $parser->shortstr($to,40), $parser->shortstr($org,40), $parser->shortstr($str,40)) if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 3 3
2244 3 $res = $str;
2245 }
2246 }
2247 }
2248 } elsif ($cmd eq 'strcmp') {
2249 # https://php.net/manual/en/function.strcmp.php
2250 # TODO: perl cmp does just return -1,0,1
2251 #
2252 1 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 0 1
2253 1 my $s = $parser->get_strval($$args[0]);
2254 1 my $d = $parser->get_strval($$args[1]);
2255 1 ▶ if (defined $s && defined $d) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $d) 1 0 1
Condition33%1/3
defined $s and defined $d
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and defined $d
defined $s defined $d
Truth table33%1/3
A and B
A= defined $sB= defined $d
ABresult
0X0
100
111
2256 1 $res = $s cmp $d;
2257 1 $to_num = 1;
2258 }
2259 }
2260 } elsif ($cmd eq 'strncmp') {
2261 # https://php.net/manual/en/function.strncmp.php
2262 # TODO: perl cmp does just return -1,0,1
2263 #
2264 0 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 0 0 0
2265 0 my $s = $parser->get_strval($$args[0]);
2266 0 my $d = $parser->get_strval($$args[1]);
2267 0 my $len = $parser->get_strval($$args[2]);
2268 0 ▶ if (defined $s && defined $d && defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $d and defined $len) 0 0 0
Condition0%0/6
defined $s and defined $d and defined $len
!ll&&!rl&&r
000
defined $s and defined $d
!ll&&!rl&&r
000
MC/DC0%0/3
defined $s and defined $d and defined $len
defined $s defined $d defined $len
Truth table0%0/4
A and B and C
A= defined $sB= defined $dC= defined $len
ABCresult
0XX0
10X0
1100
1111
2269 0 ▶ $len = 0 if ($len eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $len eq "" 0 0 0
2270 0 $res = substr($s,0,$len) cmp substr($d,0,$len);
2271 0 $to_num = 1;
2272 }
2273 }
2274 } elsif ($cmd eq 'strcasecmp') {
2275 # https://php.net/manual/en/function.strcasecmp.php
2276 # TODO: perl cmp does just return -1,0,1
2277 #
2278 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
2279 0 my $s = $parser->get_strval($$args[0]);
2280 0 my $d = $parser->get_strval($$args[1]);
2281 0 ▶ if (defined $s && defined $d) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $d) 0 0 0
Condition0%0/3
defined $s and defined $d
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and defined $d
defined $s defined $d
Truth table0%0/3
A and B
A= defined $sB= defined $d
ABresult
0X0
100
111
2282 0 $res = lc($s) cmp lc($d);
2283 0 $to_num = 1;
2284 }
2285 }
2286 } elsif ($cmd eq 'strncasecmp') {
2287 # https://php.net/manual/en/function.strncasecmp.php
2288 # TODO: perl cmp does just return -1,0,1
2289 #
2290 1 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 1 0 1
2291 1 my $s = $parser->get_strval($$args[0]);
2292 1 my $d = $parser->get_strval($$args[1]);
2293 1 my $len = $parser->get_strval($$args[2]);
2294 1 ▶ if (defined $s && defined $d && defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $d and defined $len) 1 0 1
Condition33%2/6
defined $s and defined $d and defined $len
!ll&&!rl&&r
001
defined $s and defined $d
!ll&&!rl&&r
001
MC/DC0%0/3
defined $s and defined $d and defined $len
defined $s defined $d defined $len
Truth table25%1/4
A and B and C
A= defined $sB= defined $dC= defined $len
ABCresult
0XX0
10X0
1100
1111
2295 1 ▶ $len = 0 if ($len eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $len eq "" 0 1 1
2296 1 $res = lc(substr($s,0,$len)) cmp lc(substr($d,0,$len));
2297 1 $to_num = 1;
2298 }
2299 }
2300 } elsif ($cmd eq 'str_repeat') {
2301 # https://php.net/manual/en/function.str-repeat.php
2302 #
2303 1 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 0 1
2304 1 my $s = $parser->get_strval($$args[0]);
2305 1 my $m = $parser->get_strval($$args[1]);
2306  
2307 1 ▶ if (defined $s && defined $m) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $m) 1 0 1
Condition33%1/3
defined $s and defined $m
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and defined $m
defined $s defined $m
Truth table33%1/3
A and B
A= defined $sB= defined $m
ABresult
0X0
100
111
2308 1 ▶ $m = 0 if ($m eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $m eq "" 0 1 1
2309 1 ▶ if ($m > $ctx->{max_repeat}) { # limit maxsize
Branch: 1 branch
BranchTrueFalseTotal
if ($m > $ctx->{'max_repeat'}) { } 0 1 1
2310 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$s x $m memory exhaution");
2311 } else {
2312 1 $res = $s x $m;
2313 }
2314 }
2315 }
2316 } elsif ($cmd eq 'str_replace') {
2317 4 ▶ if (scalar @$args >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 3) 4 0 4
2318 4 my $pattern = $$args[0];
2319 4 my $replacement = $$args[1];
2320 4 my $subject = $$args[2];
2321 4 my $limit = -1;
2322 4 ▶ if (scalar @$args == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 4) 0 4 4
2323 0 $limit = $parser->get_strval($$args[3]);
2324 0 ▶ $limit = 0 if ($limit eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $limit eq "" 0 0 0
2325 }
2326 4 ▶ if (defined $pattern && defined $replacement && defined $subject) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pattern and defined $replacement and defined $subject) 4 0 4
Condition33%2/6
defined $pattern and defined $replacement and defined $subject
!ll&&!rl&&r
004
defined $pattern and defined $replacement
!ll&&!rl&&r
004
MC/DC0%0/3
defined $pattern and defined $replacement and defined $subject
defined $pattern defined $replacement defined $subject
Truth table25%1/4
A and B and C
A= defined $patternB= defined $replacementC= defined $subject
ABCresult
0XX0
10X0
1100
1111
2327 4 ▶ if (is_array($subject)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_array($subject)) { } 1 3 4
elsif (is_strval($subject)) { } 3 0 3
elsif ($subject eq '#null') { } 0 0 0
2328 1 my $arr = $parser->{strmap}{$subject};
2329 1 my $keys = $arr->get_keys();
2330 1 my $newarr = $parser->newarr();
2331
2332 1 foreach my $k (@$keys) {
2333 2 my $val = $arr->val($k);
2334 2 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $val, 'str', $limit);
2335 2 $newarr->set(undef, $r);
2336 2 ▶ if ($limit != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit != -1) 0 2 2
2337 0 $limit -= $cnt;
2338 }
2339 }
2340 1 return $newarr->{name};
2341 } elsif (is_strval($subject)) {
2342 3 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $subject, 'str', $limit);
2343 3 return $r;
2344 } elsif ($subject eq '#null') {
2345 0 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $subject, 'str', $limit);
2346 0 return $r;
2347 }
2348 }
2349 }
2350 } elsif ($cmd eq 'ereg_replace') {
2351 0 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 0 0 0
2352 0 my $pattern = $parser->get_strval($$args[0]);
2353 0 my $replacement = $parser->get_strval($$args[1]);
2354 0 my $str = $parser->get_strval($$args[2]);
2355  
2356 # todo: use posix regex here
2357 #
2358 0 ▶ if (defined $pattern && defined $replacement && defined $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pattern and defined $replacement and defined $str) 0 0 0
Condition0%0/6
defined $pattern and defined $replacement and defined $str
!ll&&!rl&&r
000
defined $pattern and defined $replacement
!ll&&!rl&&r
000
MC/DC0%0/3
defined $pattern and defined $replacement and defined $str
defined $pattern defined $replacement defined $str
Truth table0%0/4
A and B and C
A= defined $patternB= defined $replacementC= defined $str
ABCresult
0XX0
10X0
1100
1111
2359 0 $res = $str;
2360 0 $res =~ s/\Q$pattern\E/$replacement/g;
2361 0 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[%s]->[%s] %s -> %s", $parser->shortstr($pattern,40), $parser->shortstr($replacement,40), $parser->shortstr($str,40), $parser->shortstr($res,40)) if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 0 0
2362 }
2363 }
2364 } elsif ($cmd eq 'preg_replace') {
2365 7 ▶ if (scalar @$args >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 3) 7 0 7
2366 7 my $pattern = $$args[0];
2367 7 my $replacement = $$args[1];
2368 7 my $subject = $$args[2];
2369 7 my $limit = -1;
2370 7 ▶ if (scalar @$args == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 4) 0 7 7
2371 0 $limit = $parser->get_strval($$args[3]);
2372 0 ▶ $limit = 0 if ($limit eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $limit eq "" 0 0 0
2373 }
2374  
2375 # preg_replace uses pattern '/xxx/' instead of 'xxx'
2376 #
2377 7 ▶ if (defined $pattern && defined $replacement && defined $subject) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pattern and defined $replacement and defined $subject) 7 0 7
Condition33%2/6
defined $pattern and defined $replacement and defined $subject
!ll&&!rl&&r
007
defined $pattern and defined $replacement
!ll&&!rl&&r
007
MC/DC0%0/3
defined $pattern and defined $replacement and defined $subject
defined $pattern defined $replacement defined $subject
Truth table25%1/4
A and B and C
A= defined $patternB= defined $replacementC= defined $subject
ABCresult
0XX0
10X0
1100
1111
2378 7 ▶ if (is_array($subject)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_array($subject)) { } 1 6 7
elsif (is_strval($subject)) { } 6 0 6
elsif ($subject eq '#null') { } 0 0 0
2379 1 my $arr = $parser->{strmap}{$subject};
2380 1 my $keys = $arr->get_keys();
2381 1 my $newarr = $parser->newarr();
2382
2383 1 foreach my $k (@$keys) {
2384 2 my $val = $arr->val($k);
2385 2 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $val, 'preg', $limit);
2386 2 $newarr->set(undef, $r);
2387 2 ▶ if ($limit != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit != -1) 0 2 2
2388 0 $limit -= $cnt;
2389 }
2390 }
2391 1 return $newarr->{name};
2392 } elsif (is_strval($subject)) {
2393 6 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $subject, 'preg', $limit);
2394 6 return $r;
2395 } elsif ($subject eq '#null') {
2396 0 my ($r, $cnt) = preg_replace_subject($ctx, $pattern, $replacement, $subject, 'preg', $limit);
2397 0 return $r;
2398 }
2399 }
2400 }
2401 } elsif ($cmd eq 'preg_quote') {
2402 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2403 0 my $s = $parser->get_strval($$args[0]);
2404 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2405 # escape: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
2406 0 $s =~ s/%([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\-])/\\$1/ge;
2407 0 $res = $s;
2408 }
2409 }
2410 } elsif ($cmd eq 'md5') {
2411 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2412 1 my $s = $parser->get_strval($$args[0]);
2413 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2414 1 $res = md5_hex($s);
2415 }
2416 }
2417 } elsif ($cmd eq 'sha1') {
2418 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2419 1 my $s = $parser->get_strval($$args[0]);
2420 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2421 1 $res = sha1_hex($s);
2422 }
2423 }
2424 } elsif ($cmd eq 'levenshtein') {
2425 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
2426 0 my $s1 = $parser->get_strval($$args[0]);
2427 0 my $s2 = $parser->get_strval($$args[1]);
2428 0 ▶ if (defined $s1 && defined $s2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1 and defined $s2) 0 0 0
Condition0%0/3
defined $s1 and defined $s2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s1 and defined $s2
defined $s1 defined $s2
Truth table0%0/3
A and B
A= defined $s1B= defined $s2
ABresult
0X0
100
111
2429 0 $res = levenshtein($s1, $2);
2430 }
2431 }
2432 } elsif ($cmd eq 'str_split') {
2433 0 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 0 0 0
2434 0 my $s1 = $parser->get_strval($$args[0]);
2435 0 my $s2 = '1';
2436 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
2437 0 $s2 = $parser->get_strval($$args[1]);
2438 }
2439 0 ▶ if (defined $s1 && defined $s2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1 and defined $s2) 0 0 0
Condition0%0/3
defined $s1 and defined $s2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s1 and defined $s2
defined $s1 defined $s2
Truth table0%0/3
A and B
A= defined $s1B= defined $s2
ABresult
0X0
100
111
2440 0 my $arr = $parser->newarr();
2441 # don't include delimter in split result
2442 0 my @parts = $s1 =~ /.{1,$s2}/g;
2443  
2444 0 foreach my $p (@parts) {
2445 0 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[$s2] part: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 0 0
2446 0 my $k = $parser->setstr($p);
2447 0 $arr->set(undef, $k);
2448 }
2449 0 return $arr->{name};
2450 }
2451 }
2452 } elsif ($cmd eq 'preg_split') {
2453 1 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 1 0 1
2454 1 my $s1 = $parser->get_strval($$args[0]);
2455 1 my $s2 = $parser->get_strval($$args[1]);
2456 1 my $limit = '-1';
2457 1 my $flags = 0;
2458 1 ▶ if (scalar @$args > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 2) 0 1 1
2459 0 $limit = $parser->get_strval($$args[2]);
2460 0 ▶ $limit = 0 if ($limit eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $limit eq "" 0 0 0
2461 }
2462 1 ▶ if (scalar @$args > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 3) 0 1 1
2463 0 $flags = $parser->get_strval($$args[3]);
2464 }
2465 1 ▶ if (defined $s1 && defined $s2 && ($flags == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1 and defined $s2 and $flags == 0) 1 0 1
Condition33%2/6
defined $s1 and defined $s2 and $flags == 0
!ll&&!rl&&r
001
defined $s1 and defined $s2
!ll&&!rl&&r
001
MC/DC0%0/3
defined $s1 and defined $s2 and $flags == 0
defined $s1 defined $s2 $flags == 0
Truth table25%1/4
A and B and C
A= defined $s1B= defined $s2C= $flags == 0
ABCresult
0XX0
10X0
1100
1111
2466 1 my $arr = $parser->newarr();
2467 1 my ($pattern) = $s1 =~ /^\/(.*)\/$/;
2468 1 my @parts = split /$pattern/, $s2, $limit;
2469  
2470 1 foreach my $p (@parts) {
2471 3 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[$s2] '$s1' part: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 3 3
2472 3 my $k = $parser->setstr($p);
2473 3 $arr->set(undef, $k);
2474 }
2475 1 return $arr->{name};
2476 }
2477 }
2478 } elsif ($cmd eq 'explode') {
2479 0 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 0 0 0
2480 0 my $s1 = $parser->get_strval($$args[0]);
2481 0 my $s2 = $parser->get_strval($$args[1]);
2482 0 my $limit = '-1';
2483 0 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 0 0 0
2484 0 $limit = $parser->get_strval($$args[2]);
2485 }
2486 0 ▶ if (defined $s1 && defined $s2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1 and defined $s2) 0 0 0
Condition0%0/3
defined $s1 and defined $s2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s1 and defined $s2
defined $s1 defined $s2
Truth table0%0/3
A and B
A= defined $s1B= defined $s2
ABresult
0X0
100
111
2487 0 my $arr = $parser->newarr();
2488 0 my @parts = split /\Q$s1\E/, $s2, $limit;
2489  
2490 0 foreach my $p (@parts) {
2491 0 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[$s2] '$s1': part: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 0 0
2492 0 my $k = $parser->setstr($p);
2493 0 $arr->set(undef, $k);
2494 }
2495 0 return $arr->{name};
2496 }
2497 }
2498 ▶ } elsif (($cmd eq 'implode') || ($cmd eq 'join')) {
Condition100%3/3
$cmd eq "implode" or $cmd eq "join"
l!l&&r!l&&!r
22398
MC/DC100%2/2
$cmd eq "implode" or $cmd eq "join"
$cmd eq "implode" $cmd eq "join"
Truth table100%3/3
A or B
A= $cmd eq "implode"B= $cmd eq "join"
ABresult
1X1
011
000
2499 # https://php.net/manual/en/function.implode.php
2500 # 'join' is an alias for implode()
2501 #
2502 4 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 4 0 4
2503 4 my $basestr = $$args[0];
2504 4 my $glue = '';
2505  
2506 4 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 4 0 4
2507 4 ▶ if (is_array($$args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($args->[0])) { } 1 3 4
2508 1 $ctx->{warn}->($ctx, 'cmd', $cmd, "reversed arguments $$args[0] $$args[1]");
2509 1 $basestr = $$args[0];
2510 1 $glue = $parser->get_strval($$args[1]);
2511 } else {
2512 3 $glue = $parser->get_strval($$args[0]);
2513 3 $basestr = $$args[1];
2514 }
2515 }
2516 4 ▶ if (defined $glue && defined $basestr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $glue and defined $basestr) 4 0 4
Condition33%1/3
defined $glue and defined $basestr
!ll&&!rl&&r
004
MC/DC0%0/2
defined $glue and defined $basestr
defined $glue defined $basestr
Truth table33%1/3
A and B
A= defined $glueB= defined $basestr
ABresult
0X0
100
111
2517 4 ▶ if (is_array($basestr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($basestr)) 2 2 4
2518 2 my $arr = $parser->{strmap}{$basestr};
2519 2 my $keys = $arr->get_keys();
2520  
2521 2 my @vals = ();
2522 2 my $failed = 0;
2523 2 foreach my $k (@$keys) {
2524 4 my $val = $arr->val($k);
2525 4 ▶ if (is_strval($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($val)) { } 4 0 4
2526 4 push (@vals, $parser->{strmap}->{$val});
2527 } else {
2528 0 my $v = $ctx->exec_statement($val);
2529 0 ▶ if (is_strval($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($v)) { } 0 0 0
2530 0 push (@vals, $parser->{strmap}->{$v});
2531 } else {
2532 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$basestr: key $k not str ($val -> $v)");
2533 0 $failed = 1;
2534 0 last;
2535 }
2536 }
2537 }
2538 2 ▶ $res = join($glue, @vals) unless ($failed);
Branch: 1 branch
BranchTrueFalseTotal
unless $failed 2 0 2
2539 }
2540 }
2541 }
2542 } elsif ($cmd eq 'range') {
2543 # https://www.php.net/manual/en/function.range.php
2544 #
2545 14 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 14 0 14
2546 14 my $s1 = $parser->get_strval($$args[0]);
2547 14 my $s2 = $parser->get_strval($$args[1]);
2548 14 my $step = '1';
2549 14 ▶ if (scalar @$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 3) 3 11 14
2550 3 $step = $parser->get_strval($$args[2]);
2551 3 ▶ $step = 0 if (!defined $step || ($step eq ''));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $step or $step eq "" 0 3 3
Condition33%1/3
not defined $step or $step eq ""
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $step or $step eq ""
not defined $step $step eq ""
Truth table33%1/3
not(A) or B
A= not defined $stepB= $step eq ""
ABresult
1X1
011
000
2552 }
2553 14 ▶ if (defined $s1 && defined $s2 && ($step =~ /^-?\d+$/) && ($step != 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s1 and defined $s2 and $step =~ /^-?\d+$/ and $step != 0) 13 1 14
Condition55%5/9
defined $s1 and defined $s2 and $step =~ /^-?\d+$/ and $step != 0
!ll&&!rl&&r
1013
defined $s1 and defined $s2 and $step =~ /^-?\d+$/
!ll&&!rl&&r
0113
defined $s1 and defined $s2
!ll&&!rl&&r
0014
MC/DC25%1/4
defined $s1 and defined $s2 and $step =~ /^-?\d+$/ and $step != 0
defined $s1 defined $s2 $step =~ /^-?\d+$/ $step != 0
Truth table40%2/5
A and B and C and D
A= defined $s1B= defined $s2C= $step =~ /^-?\d+$/D= $step != 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2554 13 my @parts;
2555  
2556 # php ranges might be descending and use abs(step).
2557 # for non-numeric strings only the first char is used.
2558 # (float ranges are not supported)
2559 #
2560 13 ▶ if (($s1 =~ /^-?\d+$/) && ($s2 =~ /^-?\d+$/)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s1 =~ /^-?\d+$/ and $s2 =~ /^-?\d+$/) { } 4 9 13
elsif ($s1 ne '' and $s2 ne '' and not is_numeric_str($s1) and not is_numeric_str($s2)) { } 9 0 9
Condition66%2/3
$s1 =~ /^-?\d+$/ and $s2 =~ /^-?\d+$/
!ll&&!rl&&r
904
MC/DC50%1/2
$s1 =~ /^-?\d+$/ and $s2 =~ /^-?\d+$/
$s1 =~ /^-?\d+$/ $s2 =~ /^-?\d+$/
Truth table66%2/3
A and B
A= $s1 =~ /^-?\d+$/B= $s2 =~ /^-?\d+$/
ABresult
0X0
100
111
2561 4 @parts = range_steps($s1, $s2, abs($step));
2562 ▶ } elsif (($s1 ne '') && ($s2 ne '') && !is_numeric_str($s1) && !is_numeric_str($s2)) {
Condition33%3/9
$s1 ne "" and $s2 ne "" and not is_numeric_str($s1) and not is_numeric_str($s2)
!ll&&!rl&&r
009
$s1 ne "" and $s2 ne "" and not is_numeric_str($s1)
!ll&&!rl&&r
009
$s1 ne "" and $s2 ne ""
!ll&&!rl&&r
009
MC/DC0%0/4
$s1 ne "" and $s2 ne "" and not is_numeric_str($s1) and not is_numeric_str($s2)
$s1 ne "" $s2 ne "" not is_numeric_str($s1) not is_numeric_str($s2)
Truth table20%1/5
A and B and not(C) and not(D)
A= $s1 ne ""B= $s2 ne ""C= not is_numeric_str($s1)D= not is_numeric_str($s2)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2563 9 @parts = map { chr } range_steps(ord($s1), ord($s2), abs($step));
2564 } else {
2565 0 return;
2566 }
2567 13 my $arr = $parser->newarr();
2568  
2569 13 foreach my $p (@parts) {
2570 308 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "['$s1', '$s2']: part: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 308 308
2571 308 my $k = $parser->setstr($p);
2572 308 $arr->set(undef, $k);
2573 }
2574 13 return $arr->{name};
2575 }
2576 }
2577 ▶ } elsif (($cmd eq 'count') || ($cmd eq 'sizeof')) {
Condition66%2/3
$cmd eq "count" or $cmd eq "sizeof"
l!l&&r!l&&!r
30381
MC/DC50%1/2
$cmd eq "count" or $cmd eq "sizeof"
$cmd eq "count" $cmd eq "sizeof"
Truth table66%2/3
A or B
A= $cmd eq "count"B= $cmd eq "sizeof"
ABresult
1X1
011
000
2578 # https://php.net/manual/en/function.count.php
2579 # todo: support arg2: COUNT_NORMAL/COUNT_RECURSIVE
2580 #
2581 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
2582 3 my $basestr = $$args[0];
2583 3 ▶ if (defined $basestr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $basestr) 3 0 3
2584 3 ▶ if (is_array($basestr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($basestr)) 2 1 3
2585 2 my $arr = $parser->{strmap}{$basestr};
2586 2 my $keys = $arr->get_keys();
2587 2 $res = scalar @$keys;
2588 2 $to_num = 1;
2589 }
2590 }
2591 }
2592 ▶ } elsif (($cmd eq 'htmlspecialchars') || ($cmd eq 'htmlentities')) {
Condition33%1/3
$cmd eq "htmlspecialchars" or $cmd eq "htmlentities"
l!l&&r!l&&!r
00381
MC/DC0%0/2
$cmd eq "htmlspecialchars" or $cmd eq "htmlentities"
$cmd eq "htmlspecialchars" $cmd eq "htmlentities"
Truth table33%1/3
A or B
A= $cmd eq "htmlspecialchars"B= $cmd eq "htmlentities"
ABresult
1X1
011
000
2593 0 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 0 0 0
2594 0 my $s = $parser->get_strval($$args[0]);
2595 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2596 0 $res = HTML::Entities::encode_entities($s);
2597 }
2598 }
2599 ▶ } elsif (($cmd eq 'htmlspecialchars_decode') || ($cmd eq 'html_entity_decode')) {
Condition33%1/3
$cmd eq "htmlspecialchars_decode" or $cmd eq "html_entity_decode"
l!l&&r!l&&!r
00381
MC/DC0%0/2
$cmd eq "htmlspecialchars_decode" or $cmd eq "html_entity_decode"
$cmd eq "htmlspecialchars_decode" $cmd eq "html_entity_decode"
Truth table33%1/3
A or B
A= $cmd eq "htmlspecialchars_decode"B= $cmd eq "html_entity_decode"
ABresult
1X1
011
000
2600 # just support 1 argument version without flags & charset for now
2601 #
2602 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2603 0 my $s = $parser->get_strval($$args[0]);
2604 0 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 0 0 0
2605 0 $res = HTML::Entities::decode_entities($s);
2606 }
2607 }
2608 } elsif ($cmd eq 'pack') {
2609 2 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 2 0 2
2610 2 my $s = $parser->get_strval($$args[0]);
2611 2 my @param = ();
2612 2 my $i;
2613  
2614 2 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 2 0 2
2615 2 ▶ for ($i=1; $i < scalar @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$args) 4 2 6
2616 4 my $p = $parser->get_strval($args->[$i]);
2617 4 ▶ last unless (defined $p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 4 4
2618 4 push(@param, $p);
2619 }
2620 2 ▶ if ($i == scalar @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == scalar @$args) 2 0 2
2621 2 eval { $res = pack($s, @param); };
2622 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
2623 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "bad param $s");
2624 }
2625 }
2626 }
2627 }
2628 } elsif ($cmd eq 'unpack') {
2629 1 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 0 1
2630 1 my $s = $parser->get_strval($$args[0]);
2631 1 my $d = $parser->get_strval($$args[1]);
2632  
2633 1 ▶ if (defined $s && defined $d) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $d) 1 0 1
Condition33%1/3
defined $s and defined $d
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and defined $d
defined $s defined $d
Truth table33%1/3
A and B
A= defined $sB= defined $d
ABresult
0X0
100
111
2634 1 my @values;
2635 1 eval { @values = unpack($s, $d); };
2636 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
2637 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "bad param $s");
2638 }
2639  
2640 1 my $arr = $parser->newarr();
2641  
2642 1 foreach my $p (@values) {
2643 2 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[$s]: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 2 2
2644 2 my $k = $parser->setstr($p);
2645 2 $arr->set(undef, $k);
2646 }
2647 1 return $arr->{name};
2648 }
2649 }
2650 } elsif ($cmd eq 'sprintf') {
2651 1 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 1 0 1
2652 1 my $s = $parser->get_strval($$args[0]);
2653 1 my @param = ();
2654 1 my $i;
2655  
2656 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
2657 1 ▶ for ($i=1; $i < scalar @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$args) 2 1 3
2658 2 my $p = $parser->get_strval($args->[$i]);
2659 2 ▶ last unless (defined $p);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 2 2
2660 2 push(@param, $p);
2661 }
2662 1 ▶ if ($i == scalar @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == scalar @$args) 1 0 1
2663 1 eval { $res = sprintf($s, @param); };
2664 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
2665 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "bad param $s");
2666 }
2667 }
2668 }
2669 }
2670 } elsif ($cmd eq 'array_push') {
2671 # https://php.net/manual/en/function.array-push.php
2672 #
2673 2 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 2 0 2
2674 2 my $var = $$args[0]; # ref var
2675 2 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2676  
2677 2 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 2 0 2
2678 2 ▶ if (!defined $val || is_null($val) || is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or is_null($val) or is_array($val)) 2 0 2
Condition66%4/6
not defined $val or is_null($val) or is_array($val)
l!l&&r!l&&!r
110
not defined $val or is_null($val)
l!l&&r!l&&!r
011
MC/DC0%0/3
not defined $val or is_null($val) or is_array($val)
not defined $val is_null($val) is_array($val)
Truth table50%2/4
not(A) or B or C
A= not defined $valB= is_null($val)C= is_array($val)
ABCresult
1XX1
01X1
0011
0000
2679 2 my $arr;
2680 2 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 1 1 2
Condition66%2/3
defined $val and is_array($val)
!ll&&!rl&&r
011
MC/DC50%1/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table66%2/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2681 1 $arr = $parser->{strmap}{$val};
2682 1 $arr = $arr->copy(); # recursive copy
2683 } else {
2684 1 $arr = $parser->newarr();
2685 }
2686 2 ▶ for (my $i=1; $i < scalar @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$args) 2 2 4
2687 2 $arr->set(undef, $$args[$i]);
2688 }
2689 2 set_refvar_val($ctx, $var, $arr->{name});
2690 2 my $keys = $arr->get_keys();
2691  
2692 2 $res = scalar keys @$keys; # returns elem count
2693 2 $to_num = 1;
2694 }
2695 }
2696 }
2697 } elsif ($cmd eq 'array_pop') {
2698 # https://php.net/manual/en/function.array-pop.php
2699 #
2700 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
2701 3 my $var = $$args[0]; # ref var
2702 3 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2703  
2704 3 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 2 1 3
2705 2 ▶ if (!defined $val || is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or is_array($val)) 2 0 2
Condition33%1/3
not defined $val or is_array($val)
l!l&&r!l&&!r
020
MC/DC0%0/2
not defined $val or is_array($val)
not defined $val is_array($val)
Truth table33%1/3
not(A) or B
A= not defined $valB= is_array($val)
ABresult
1X1
011
000
2706 2 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 2 0 2
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2707 2 my $arr = $parser->{strmap}{$val};
2708 2 my $keys = $arr->get_keys();
2709 2 ▶ if (scalar @$keys == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys == 0) { } 1 1 2
2710 1 $res = '#null';
2711 } else {
2712 1 my $k = pop @$keys;
2713 1 $res = $arr->val($k);
2714 1 $arr = $arr->copy($keys);
2715 1 set_refvar_val($ctx, $var, $arr->{name});
2716 }
2717 } else {
2718 0 $res = '#null';
2719 }
2720 2 return $res;
2721 }
2722 }
2723 }
2724 } elsif ($cmd eq 'array_unshift') {
2725 # https://php.net/manual/en/function.array-unshift.php
2726 #
2727 3 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 3 0 3
2728 3 my $var = $$args[0]; # ref var
2729 3 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2730  
2731 3 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 2 1 3
2732 2 ▶ if (!defined $val || is_null($val) || is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or is_null($val) or is_array($val)) 2 0 2
Condition66%4/6
not defined $val or is_null($val) or is_array($val)
l!l&&r!l&&!r
110
not defined $val or is_null($val)
l!l&&r!l&&!r
011
MC/DC0%0/3
not defined $val or is_null($val) or is_array($val)
not defined $val is_null($val) is_array($val)
Truth table50%2/4
not(A) or B or C
A= not defined $valB= is_null($val)C= is_array($val)
ABCresult
1XX1
01X1
0011
0000
2733 2 my $newarr = $parser->newarr();
2734  
2735 2 ▶ for (my $i=1; $i < scalar @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$args) 2 2 4
2736 2 $newarr->set(undef, $$args[$i]); # prepend new elems
2737 }
2738 2 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) 1 1 2
Condition66%2/3
defined $val and is_array($val)
!ll&&!rl&&r
011
MC/DC50%1/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table66%2/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2739 1 my $arr = $parser->{strmap}{$val};
2740 1 my $keys = $arr->get_keys();
2741  
2742 1 foreach my $k (@$keys) {
2743 1 my $oldval = $arr->val($k);
2744 1 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) { } 1 0 1
2745 1 $newarr->set(undef, $oldval); # renumber int key
2746 } else {
2747 0 $newarr->set($k, $oldval);
2748 }
2749 }
2750 }
2751 2 set_refvar_val($ctx, $var, $newarr->{name});
2752  
2753 2 my $keys = $newarr->get_keys();
2754 2 $res = scalar keys @$keys; # returns elem count
2755 2 $to_num = 1;
2756 }
2757 }
2758 }
2759 } elsif ($cmd eq 'array_shift') {
2760 # https://php.net/manual/en/function.array-shift.php
2761 #
2762 5 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 5 0 5
2763 5 my $var = $$args[0]; # ref var
2764 5 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2765  
2766 5 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 4 1 5
2767 4 ▶ if (!defined $val || is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or is_array($val)) 2 2 4
Condition66%2/3
not defined $val or is_array($val)
l!l&&r!l&&!r
022
MC/DC50%1/2
not defined $val or is_array($val)
not defined $val is_array($val)
Truth table66%2/3
not(A) or B
A= not defined $valB= is_array($val)
ABresult
1X1
011
000
2768 2 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 2 0 2
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2769 2 my $arr = $parser->{strmap}{$val};
2770 2 my $keys = $arr->get_keys();
2771 2 ▶ if (scalar @$keys == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys == 0) { } 1 1 2
2772 1 $res = '#null';
2773 } else {
2774 1 my $k = shift @$keys;
2775 1 $res = $arr->val($k);
2776  
2777 1 my $newarr = $parser->newarr();
2778 1 foreach my $k (@$keys) {
2779 1 my $oldval = $arr->val($k);
2780 1 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) { } 1 0 1
2781 1 $newarr->set(undef, $oldval); # renumber int key
2782 } else {
2783 0 $newarr->set($k, $oldval);
2784 }
2785 }
2786 1 set_refvar_val($ctx, $var, $newarr->{name});
2787 }
2788 } else {
2789 0 $res = '#null';
2790 }
2791 2 return $res;
2792 }
2793 }
2794 }
2795 } elsif ($cmd eq 'each') {
2796 # https://php.net/manual/en/function.each.php
2797 #
2798 5 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 5 0 5
2799 5 my $var = $$args[0]; # ref var
2800 5 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2801  
2802 5 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 5 0 5
2803 5 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 5 0 5
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
005
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2804 5 my $arr = $parser->{strmap}{$val};
2805 5 my $pos = $arr->get_pos();
2806 5 my $keys = $arr->get_keys();
2807 5 ▶ if ($pos >= scalar @$keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= scalar @$keys) { } 1 4 5
2808 1 $res = 0;
2809 1 $to_num = 1;
2810 } else {
2811 4 my $k = $keys->[$pos];
2812 4 my $v = $arr->val($k);
2813 4 my $newarr = $parser->newarr();
2814 4 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) 4 0 4
2815 4 $k = $parser->setnum($k);
2816 }
2817 4 $newarr->set(undef, $k);
2818 4 $newarr->set(undef, $v);
2819 4 $arr->set_pos($pos+1);
2820 4 return $newarr->{name};
2821 }
2822 } else {
2823 0 $res = 0;
2824 0 $to_num = 1;
2825 }
2826 }
2827 }
2828 } elsif ($cmd eq 'reset') {
2829 # https://php.net/manual/en/function.reset.php
2830 #
2831 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2832 1 my $var = $$args[0]; # ref var
2833 1 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2834  
2835 1 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 1 0 1
2836 1 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 1 0 1
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2837 1 my $arr = $parser->{strmap}{$val};
2838 1 my $keys = $arr->get_keys();
2839 1 $arr->set_pos(0);
2840 1 ▶ if (scalar @$keys == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys == 0) { } 0 1 1
2841 0 $res = 0;
2842 0 $to_num = 1;
2843 } else {
2844 1 my $k = shift @$keys;
2845 1 $res = $arr->val($k);
2846 1 return $res;
2847 }
2848 } else {
2849 0 $res = 0;
2850 0 $to_num = 1;
2851 }
2852 }
2853 }
2854 } elsif ($cmd eq 'next') {
2855 # https://php.net/manual/en/function.next.php
2856 #
2857 4 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 4 0 4
2858 4 my $var = $$args[0]; # ref var
2859 4 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2860  
2861 4 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 4 0 4
2862 4 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 4 0 4
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
004
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2863 4 my $arr = $parser->{strmap}{$val};
2864 4 my $pos = $arr->get_pos();
2865 4 my $keys = $arr->get_keys();
2866 4 ▶ if (($pos+1) >= scalar @$keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + 1 >= scalar @$keys) { } 1 3 4
2867 1 $res = 0;
2868 1 $to_num = 1;
2869 } else {
2870 3 my $k = $keys->[$pos+1];
2871 3 $res = $arr->val($k);
2872 3 $arr->set_pos($pos+1);
2873 3 return $res;
2874 }
2875 } else {
2876 0 $res = 0;
2877 0 $to_num = 1;
2878 }
2879 }
2880 }
2881 } elsif ($cmd eq 'prev') {
2882 # https://php.net/manual/en/function.prev.php
2883 #
2884 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2885 1 my $var = $$args[0]; # ref var
2886 1 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2887  
2888 1 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 1 0 1
2889 1 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 1 0 1
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2890 1 my $arr = $parser->{strmap}{$val};
2891 1 my $pos = $arr->get_pos();
2892 1 my $keys = $arr->get_keys();
2893 1 ▶ if (($pos == 0) || (scalar @$keys == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos == 0 or scalar @$keys == 0) { } 0 1 1
Condition33%1/3
$pos == 0 or scalar @$keys == 0
l!l&&r!l&&!r
001
MC/DC0%0/2
$pos == 0 or scalar @$keys == 0
$pos == 0 scalar @$keys == 0
Truth table33%1/3
A or B
A= $pos == 0B= scalar @$keys == 0
ABresult
1X1
011
000
2894 0 $res = 0;
2895 0 $to_num = 1;
2896 } else {
2897 1 my $k = $keys->[$pos-1];
2898 1 $res = $arr->val($k);
2899 1 $arr->set_pos($pos-1);
2900 1 return $res;
2901 }
2902 } else {
2903 0 $res = 0;
2904 0 $to_num = 1;
2905 }
2906 }
2907 }
2908 } elsif ($cmd eq 'end') {
2909 # https://php.net/manual/en/function.end.php
2910 #
2911 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2912 1 my $var = $$args[0]; # ref var
2913 1 my ($is_valid, $val) = get_refvar_val($ctx, $var);
2914  
2915 1 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 1 0 1
2916 1 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) { } 1 0 1
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
001
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
2917 1 my $arr = $parser->{strmap}{$val};
2918 1 my $keys = $arr->get_keys();
2919 1 ▶ if (scalar @$keys == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$keys == 0) { } 0 1 1
2920 0 $res = 0;
2921 0 $to_num = 1;
2922 } else {
2923 1 my $pos = scalar @$keys - 1;
2924 1 my $k = $keys->[$pos];
2925 1 $res = $arr->val($k);
2926 1 $arr->set_pos($pos);
2927 1 return $res;
2928 }
2929 } else {
2930 0 $res = 0;
2931 0 $to_num = 1;
2932 }
2933 }
2934 }
2935 ▶ } elsif (($cmd eq 'current') || ($cmd eq 'pos')) {
Condition66%2/3
$cmd eq "current" or $cmd eq "pos"
l!l&&r!l&&!r
10351
MC/DC50%1/2
$cmd eq "current" or $cmd eq "pos"
$cmd eq "current" $cmd eq "pos"
Truth table66%2/3
A or B
A= $cmd eq "current"B= $cmd eq "pos"
ABresult
1X1
011
000
2936 # https://php.net/manual/en/function.current.php
2937 #
2938 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
2939 1 my $var = $$args[0];
2940  
2941 1 ▶ unless ($ctx->{infunction} && !$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"infunction"} and not $ctx->{"incall"}) 1 0 1
Condition33%1/3
$ctx->{"infunction"} and not $ctx->{"incall"}
!ll&&!rl&&r
100
MC/DC0%0/2
$ctx->{"infunction"} and not $ctx->{"incall"}
$ctx->{"infunction"} not $ctx->{"incall"}
Truth table33%1/3
A and not(B)
A= $ctx->{"infunction"}B= not $ctx->{"incall"}
ABresult
0X0
100
111
2942 1 ▶ if (is_array($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($var)) { } 1 0 1
2943 1 my $arr = $parser->{strmap}{$var};
2944 1 my $pos = $arr->get_pos();
2945 1 my $keys = $arr->get_keys();
2946 1 ▶ if ($pos >= scalar @$keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= scalar @$keys) { } 0 1 1
2947 0 $res = 0;
2948 0 $to_num = 1;
2949 } else {
2950 1 my $k = $keys->[$pos];
2951 1 $res = $arr->val($k);
2952 1 return $res;
2953 }
2954 } else {
2955 0 $res = 0;
2956 0 $to_num = 1;
2957 }
2958 }
2959 }
2960 } elsif ($cmd eq 'key') {
2961 # https://php.net/manual/en/function.key.php
2962 #
2963 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
2964 0 my $var = $$args[0];
2965  
2966 0 ▶ unless ($ctx->{infunction} && !$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"infunction"} and not $ctx->{"incall"}) 0 0 0
Condition0%0/3
$ctx->{"infunction"} and not $ctx->{"incall"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->{"infunction"} and not $ctx->{"incall"}
$ctx->{"infunction"} not $ctx->{"incall"}
Truth table0%0/3
A and not(B)
A= $ctx->{"infunction"}B= not $ctx->{"incall"}
ABresult
0X0
100
111
2967 0 ▶ if (is_array($var)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($var)) { } 0 0 0
2968 0 my $arr = $parser->{strmap}{$var};
2969 0 my $pos = $arr->get_pos();
2970 0 my $keys = $arr->get_keys();
2971 0 ▶ if ($pos >= scalar @$keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= scalar @$keys) { } 0 0 0
2972 0 $res = '#null';
2973 0 return $res;
2974 } else {
2975 0 my $k = $keys->[$pos];
2976 0 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) 0 0 0
2977 0 $k = $parser->setnum($k);
2978 }
2979 0 return $k;
2980 }
2981 } else {
2982 0 $res = '#null';
2983 0 return $res;
2984 }
2985 }
2986 }
2987 } elsif ($cmd eq 'array_map') {
2988 # https://php.net/manual/en/function.array-map.php
2989 #
2990 2 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 2 0 2
2991 2 my $name = $$args[0];
2992 2 my $param = $$args[1];
2993 2 ▶ if ((is_strval($name) || is_variable($name)) && is_array($param)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name) || is_variable($name) and is_array($param)) 2 0 2
Condition33%2/6
is_strval($name) || is_variable($name) and is_array($param)
!ll&&!rl&&r
002
is_strval($name) or is_variable($name)
l!l&&r!l&&!r
200
MC/DC0%0/3
is_strval($name) || is_variable($name) and is_array($param)
is_strval($name) is_variable($name) is_array($param)
Truth table20%1/5
A or B and C
A= is_strval($name)B= is_variable($name)C= is_array($param)
ABCresult
00X0
1X00
0100
1X11
0111
2994 2 my $arr = $parser->{strmap}{$param};
2995 2 my $keys = $arr->get_keys();
2996  
2997 2 ▶ if (is_strval($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name)) 2 0 2
2998 2 $name = $parser->{strmap}{$name};
2999 }
3000 2 ▶ if (defined $keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keys) 2 0 2
3001 2 my $newarr = $parser->newarr();
3002 2 foreach my $k (@$keys) {
3003 3 my $val = $arr->val($k);
3004 3 my $c = $parser->setcall($name, [$val]);
3005 3 my $v = $ctx->exec_statement($c);
3006 3 $newarr->set($k, $v);
3007 }
3008 2 return $newarr->{name};
3009 }
3010 }
3011 }
3012 } elsif ($cmd eq 'array_walk') {
3013 # https://php.net/manual/en/function.array-walk.php
3014 #
3015 2 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 2 0 2
3016 2 my $var = $$args[0]; # ref var
3017 2 my $name = $$args[1]; # callable
3018 2 my $arg;
3019 2 ▶ if (is_strval($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name)) 1 1 2
3020 1 $name = $parser->{strmap}->{$name};
3021 }
3022 2 ▶ if (scalar @$args > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 2) 0 2 2
3023 0 $arg = $$args[2];
3024 }
3025 2 my ($is_valid, $val) = get_refvar_val($ctx, $var);
3026  
3027 2 ▶ if ($is_valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_valid) 2 0 2
3028 2 ▶ if (defined $val && is_array($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and is_array($val)) 2 0 2
Condition33%1/3
defined $val and is_array($val)
!ll&&!rl&&r
002
MC/DC0%0/2
defined $val and is_array($val)
defined $val is_array($val)
Truth table33%1/3
A and B
A= defined $valB= is_array($val)
ABresult
0X0
100
111
3029 # todo: need only to create new array if handler has ref-param
3030 #
3031 2 my $arr = $parser->{strmap}{$val};
3032 2 my $keys = $arr->get_keys();
3033 2 my $newarr = $parser->newarr();
3034 2 foreach my $k (@$keys) {
3035 4 my $oldval = $arr->val($k);
3036 4 my $k2 = $k;
3037 4 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) 4 0 4
3038 4 $k2 = $parser->setnum($k);
3039 }
3040 4 my $v = $var.'__walktmp';
3041 4 $ctx->setvar($v, $oldval, 1);
3042 4 ▶ my $c = $parser->setcall($name, defined $arg ? [$v, $k2, $arg] : [$v, $k2]);
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 4 4
3043 4 my $r = $ctx->exec_statement($c, 1);
3044 4 my $n = $ctx->getvar($v, 1);
3045 4 $newarr->set($k, $n);
3046 }
3047 2 set_refvar_val($ctx, $var, $newarr->{name});
3048 }
3049 2 $res = 1;
3050 2 $to_num = 1;
3051 }
3052 }
3053 } elsif ($cmd eq 'array_rand') {
3054 # https://php.net/manual/en/function.array-rand.php
3055 #
3056 2 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 2 0 2
3057 2 my $param = $$args[0];
3058 2 my $num = 1;
3059 2 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 1 2
3060 1 $num = $parser->get_strval($$args[1]);
3061 }
3062 2 ▶ unless ($ctx->{infunction} && !$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"infunction"} and not $ctx->{"incall"}) 2 0 2
Condition33%1/3
$ctx->{"infunction"} and not $ctx->{"incall"}
!ll&&!rl&&r
200
MC/DC0%0/2
$ctx->{"infunction"} and not $ctx->{"incall"}
$ctx->{"infunction"} not $ctx->{"incall"}
Truth table33%1/3
A and not(B)
A= $ctx->{"infunction"}B= not $ctx->{"incall"}
ABresult
0X0
100
111
3063 # don't precalc rand() in function body
3064 #
3065 2 ▶ if (is_array($param)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($param)) 2 0 2
3066 2 my $arr = $parser->{strmap}{$param};
3067 2 my $keys = $arr->get_keys();
3068 2 ▶ if (!defined $keys || ($num > scalar @$keys)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $keys or $num > scalar @$keys) { } 0 2 2
elsif ($num == 1) { } 1 1 2
Condition33%1/3
not defined $keys or $num > scalar @$keys
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $keys or $num > scalar @$keys
not defined $keys $num > scalar @$keys
Truth table33%1/3
not(A) or B
A= not defined $keysB= $num > scalar @$keys
ABresult
1X1
011
000
3069 0 $res = 0;
3070 0 $to_num = 1;
3071 } elsif ($num == 1) {
3072 1 my $i = int(rand(scalar @$keys));
3073 1 my $k = $keys->[$i]; # return key
3074 1 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) { } 0 1 1
3075 0 $res = $k;
3076 0 $to_num = 1;
3077 } else {
3078 1 $res = $parser->get_strval($k);
3079 }
3080 } else {
3081 # keep random keys uniq & in order
3082 1 my @randidx = shuffle(0 .. $#$keys);
3083 1 @randidx = sort { $a <=> $b } @randidx[0..$num-1];
3084  
3085 1 my $newarr = $parser->newarr();
3086 1 ▶ foreach (my $i=0; $i < $num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 2 1 3
3087 2 my $k = $keys->[$randidx[$i]];
3088 2 ▶ if (is_int_index($k)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_int_index($k)) 2 0 2
3089 2 $k = $parser->setnum($k);
3090 }
3091 2 $newarr->set(undef, $k); # append key
3092 }
3093 1 return $newarr->{name};
3094 }
3095 }
3096 }
3097 }
3098 } elsif ($cmd eq 'round') {
3099 1 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 1 0 1
3100 1 my $s = $parser->get_strval($$args[0]);
3101 1 my $precision = 0;
3102 1 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 0 1
3103 1 $precision = $parser->get_strval($$args[1]);
3104 }
3105 1 ▶ if (defined $s && defined $precision) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and defined $precision) 1 0 1
Condition33%1/3
defined $s and defined $precision
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and defined $precision
defined $s defined $precision
Truth table33%1/3
A and B
A= defined $sB= defined $precision
ABresult
0X0
100
111
3106 1 ▶ if ($precision == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precision == 0) { } 0 1 1
3107 0 $res = int($s + 0.5);
3108 } else {
3109 1 $res = sprintf "%0.*f", $precision, $s;
3110 }
3111 1 $to_num = 1;
3112 }
3113 }
3114 ▶ } elsif (($cmd eq 'rand') || ($cmd eq 'mt_rand')) {
Condition33%1/3
$cmd eq "rand" or $cmd eq "mt_rand"
l!l&&r!l&&!r
00344
MC/DC0%0/2
$cmd eq "rand" or $cmd eq "mt_rand"
$cmd eq "rand" $cmd eq "mt_rand"
Truth table33%1/3
A or B
A= $cmd eq "rand"B= $cmd eq "mt_rand"
ABresult
1X1
011
000
3115 0 my $min = 0;
3116 0 my $max = 32767;
3117 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
3118 0 $min = $parser->get_strval($$args[0]);
3119 0 $max = $parser->get_strval($$args[1]);
3120 }
3121 0 ▶ if (defined $min && defined $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max) 0 0 0
Condition0%0/3
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and defined $max
defined $min defined $max
Truth table0%0/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
3122 # don't precalc rand() in function body
3123 #
3124 0 ▶ unless ($ctx->{infunction} && !$ctx->{incall}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"infunction"} and not $ctx->{"incall"}) 0 0 0
Condition0%0/3
$ctx->{"infunction"} and not $ctx->{"incall"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->{"infunction"} and not $ctx->{"incall"}
$ctx->{"infunction"} not $ctx->{"incall"}
Truth table0%0/3
A and not(B)
A= $ctx->{"infunction"}B= not $ctx->{"incall"}
ABresult
0X0
100
111
3125 0 my $range = int($max) - int($min);
3126 0 $res = int(rand($range)) + int($min);
3127 0 $to_num = 1;
3128 }
3129 }
3130 } elsif ($cmd eq 'empty') {
3131 # https://php.net/manual/en/function.empty.php
3132 # (https://php.net/manual/en/types.comparisons.php)
3133 #
3134 15 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 15 0 15
3135 15 my $val = $$args[0];
3136 15 ▶ if (is_array($val)) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_array($val)) { } 2 13 15
elsif (is_null($val)) { } 3 10 13
elsif (is_strval($val)) { } 3 7 10
elsif (is_variable($val)) { } 1 6 7
elsif ($val =~ /^(\#elem\d+)$/) { } 6 0 6
3137 2 my $arr = $parser->{strmap}{$val};
3138 2 ▶ $res = $arr->empty() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$arr->empty ? : 1 1 2
3139 2 $to_num = 1;
3140 } elsif (is_null($val)) {
3141 3 $res = 1;
3142 3 $to_num = 1;
3143 } elsif (is_strval($val)) {
3144 3 my $s = $parser->get_strval($val);
3145 3 ▶ if (!defined $s) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 3 3
elsif ($s eq '0') { } 0 3 3
elsif ($val =~ /^(\#str\d+)$/ and $s eq '') { } 1 2 3
3146 0 $res = 1;
3147 } elsif ($s eq '0') {
3148 0 $res = 1;
3149 ▶ } elsif (($val =~ /^(\#str\d+)$/) && ($s eq '')) {
Condition66%2/3
$val =~ /^(\#str\d+)$/ and $s eq ""
!ll&&!rl&&r
021
MC/DC50%1/2
$val =~ /^(\#str\d+)$/ and $s eq ""
$val =~ /^(\#str\d+)$/ $s eq ""
Truth table66%2/3
A and B
A= $val =~ /^(\#str\d+)$/B= $s eq ""
ABresult
0X0
100
111
3150 1 $res = 1;
3151 } else {
3152 2 $res = 0;
3153 }
3154 3 $to_num = 1;
3155 } elsif (is_variable($val)) {
3156 1 my $v = $ctx->getvar($val);
3157 #$ctx->{log}->($ctx, 'cmd', $cmd, "$val -> $v: (tainted: %s)", $ctx->{tainted}) if $ctx->{log};
3158 1 ▶ if (!defined $v) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 1 1
elsif ($v eq '#unresolved') { } 1 0 1
3159 0 ▶ unless (&parsing_func($ctx) || $ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&parsing_func($ctx) or $ctx->{"tainted"}) 0 0 0
Condition0%0/3
&parsing_func($ctx) or $ctx->{"tainted"}
l!l&&r!l&&!r
000
MC/DC0%0/2
&parsing_func($ctx) or $ctx->{"tainted"}
&parsing_func($ctx) $ctx->{"tainted"}
Truth table0%0/3
A or B
A= &parsing_func($ctx)B= $ctx->{"tainted"}
ABresult
1X1
011
000
3160 0 ▶ unless ($ctx->{skipundef}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"skipundef"}) 0 0 0
3161 0 $res = 1;
3162 0 $to_num = 1;
3163 }
3164 }
3165 } elsif ($v eq '#unresolved') {
3166 1 $ctx->{warn}->($ctx, 'cmd', $cmd, "$val is #unresolved");
3167 }
3168 } elsif ($val =~ /^(\#elem\d+)$/) {
3169 6 my ($v, $i) = @{$parser->{strmap}->{$val}};
3170 6 my ($basevar, $has_index, $idxstr) = $ctx->resolve_variable($val, 0);
3171 6 ▶ if (defined $basevar) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $basevar) 6 0 6
3172 6 ▶ if ($has_index) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_index) { } 6 0 6
3173 6 my $basestr = $ctx->exec_statement($basevar, 0);
3174 6 ▶ if (defined $basestr && is_array($basestr) && defined $idxstr) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $basestr and is_array($basestr) and defined $idxstr) { } 2 4 6
elsif (not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/) { } 0 8 8
Condition66%4/6
defined $basestr and is_array($basestr) and defined $idxstr
!ll&&!rl&&r
402
defined $basestr and is_array($basestr)
!ll&&!rl&&r
042
MC/DC33%1/3
defined $basestr and is_array($basestr) and defined $idxstr
defined $basestr is_array($basestr) defined $idxstr
Truth table50%2/4
A and B and C
A= defined $basestrB= is_array($basestr)C= defined $idxstr
ABCresult
0XX0
10X0
1100
1111
3175 2 ▶ $idxstr = $parser->setstr('') if is_null($idxstr); # null maps to '' array index
Branch: 1 branch
BranchTrueFalseTotal
if is_null($idxstr) 0 2 2
3176 2 my $arr = $parser->{strmap}{$basestr};
3177 2 my $arrval = $arr->get($idxstr);
3178 2 ▶ if (defined $arrval) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $arrval) { } 0 2 2
elsif (not $ctx->is_superglobal($basevar)) { } 1 1 2
3179 0 my $s = $parser->get_strval($arrval);
3180 0 ▶ if (!defined $s) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 0 0
elsif ($s eq '0') { } 0 0 0
elsif ($arrval =~ /^(\#str\d+)$/ and $s eq '') { } 0 0 0
3181 0 $res = 1;
3182 } elsif ($s eq '0') {
3183 0 $res = 1;
3184 ▶ } elsif (($arrval =~ /^(\#str\d+)$/) && ($s eq '')) {
Condition0%0/3
$arrval =~ /^(\#str\d+)$/ and $s eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$arrval =~ /^(\#str\d+)$/ and $s eq ""
$arrval =~ /^(\#str\d+)$/ $s eq ""
Truth table0%0/3
A and B
A= $arrval =~ /^(\#str\d+)$/B= $s eq ""
ABresult
0X0
100
111
3185 0 $res = 1;
3186 } else {
3187 0 $res = 0;
3188 }
3189 } elsif (!$ctx->is_superglobal($basevar)) {
3190 1 $res = 1;
3191 }
3192 2 $to_num = 1;
3193 ▶ } elsif (!defined $basestr && (!$ctx->is_superglobal($basevar) || ($basevar =~ /^\$GLOBALS$/))) {
Condition16%1/6
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
!ll&&!rl&&r
400
not $ctx->is_superglobal($basevar) or $basevar =~ /^\$GLOBALS$/
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
not defined $basestr not $ctx->is_superglobal($basevar) $basevar =~ /^\$GLOBALS$/
Truth table25%1/4
not(A) and not(B) or C
A= not defined $basestrB= not $ctx->is_superglobal($basevar)C= $basevar =~ /^\$GLOBALS$/
ABCresult
0XX0
1000
11X1
1011
3194 0 ▶ unless ($ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"tainted"}) 0 0 0
3195 0 ▶ $ctx->{warn}->($ctx, 'cmd', $cmd, "$val %s[%s] is #unresolved", $basevar, defined $i ? $i : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 0 0 0
3196 }
3197 }
3198 } else {
3199 0 my $v = $ctx->getvar($basevar);
3200 0 ▶ if (!defined $v) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 0 0 0
elsif ($v eq '#unresolved') { } 0 0 0
3201 0 ▶ unless (&parsing_func($ctx) || $ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&parsing_func($ctx) or $ctx->{"tainted"}) 0 0 0
Condition0%0/3
&parsing_func($ctx) or $ctx->{"tainted"}
l!l&&r!l&&!r
000
MC/DC0%0/2
&parsing_func($ctx) or $ctx->{"tainted"}
&parsing_func($ctx) $ctx->{"tainted"}
Truth table0%0/3
A or B
A= &parsing_func($ctx)B= $ctx->{"tainted"}
ABresult
1X1
011
000
3202 0 ▶ unless ($ctx->{skipundef}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"skipundef"}) 0 0 0
3203 0 $res = 1;
3204 0 $to_num = 1;
3205 }
3206 }
3207 } elsif ($v eq '#unresolved') {
3208 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$val is #unresolved");
3209 }
3210 }
3211 }
3212 }
3213 }
3214 } elsif ($cmd eq 'is_array') {
3215 # https://www.php.net/manual/en/function.is-array.php
3216 #
3217 3 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 3 0 3
3218 3 my $val = $$args[0];
3219 3 ▶ if (is_array($val)) {
Branch: 4 branches
BranchTrueFalseTotal
if (is_array($val)) { } 1 2 3
elsif ($ctx->is_superglobal($val)) { } 1 1 2
elsif (is_null($val)) { } 1 0 1
elsif (is_strval($val)) { } 0 0 0
3220 1 $res = 1;
3221 1 $to_num = 1;
3222 } elsif ($ctx->is_superglobal($val)) {
3223 1 $res = 1;
3224 1 $to_num = 1;
3225 } elsif (is_null($val)) {
3226 1 $res = 0;
3227 1 $to_num = 1;
3228 } elsif (is_strval($val)) {
3229 0 $res = 0;
3230 0 $to_num = 1;
3231 }
3232 }
3233 } elsif ($cmd eq 'is_null') {
3234 # https://php.net/manual/en/function.is-null.php (similar to $a === null)
3235 # (https://php.net/manual/en/types.comparisons.php)
3236 #
3237 15 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 15 0 15
3238 15 my $val = $$args[0];
3239 15 ▶ if (is_array($val)) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_array($val)) { } 2 13 15
elsif (is_null($val)) { } 3 10 13
elsif (is_strval($val)) { } 2 8 10
elsif (is_variable($val)) { } 4 4 8
elsif ($val =~ /^(\#elem\d+)$/) { } 3 1 4
3240 2 $res = 0;
3241 2 $to_num = 1;
3242 } elsif (is_null($val)) {
3243 3 $res = 1;
3244 3 $to_num = 1;
3245 } elsif (is_strval($val)) {
3246 2 my $s = $parser->get_strval($val);
3247 2 ▶ if (!defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $s) { } 0 2 2
3248 0 $res = 1;
3249 } else {
3250 2 $res = 0;
3251 }
3252 2 $to_num = 1;
3253 } elsif (is_variable($val)) {
3254 4 my $v = $ctx->getvar($val);
3255 4 ▶ if (!defined $v) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 2 2 4
elsif ($v eq '#unresolved') { } 2 0 2
3256 2 ▶ unless (&parsing_func($ctx) || $ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&parsing_func($ctx) or $ctx->{"tainted"}) 2 0 2
Condition33%1/3
&parsing_func($ctx) or $ctx->{"tainted"}
l!l&&r!l&&!r
002
MC/DC0%0/2
&parsing_func($ctx) or $ctx->{"tainted"}
&parsing_func($ctx) $ctx->{"tainted"}
Truth table33%1/3
A or B
A= &parsing_func($ctx)B= $ctx->{"tainted"}
ABresult
1X1
011
000
3257 2 ▶ unless ($ctx->{skipundef}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"skipundef"}) 2 0 2
3258 2 ▶ if ($ctx->is_superglobal($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->is_superglobal($val)) { } 2 0 2
3259 # superglobals always exist as empty array,
3260 # Since it is unknown which fields exist in a real environment,
3261 # don't create superglobal array on the fly here.
3262 #
3263 2 $res = 0;
3264 } else {
3265 0 $res = 1;
3266 }
3267 2 $to_num = 1;
3268 }
3269 }
3270 } elsif ($v eq '#unresolved') {
3271 2 $ctx->{warn}->($ctx, 'cmd', $cmd, "$val is #unresolved");
3272 }
3273 } elsif ($val =~ /^(\#elem\d+)$/) {
3274 3 my ($v, $i) = @{$parser->{strmap}->{$val}};
3275 3 my ($basevar, $has_index, $idxstr) = $ctx->resolve_variable($val, 0);
3276 3 ▶ if (defined $basevar) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $basevar) 3 0 3
3277 3 my $basestr = $ctx->exec_statement($basevar, 0);
3278 3 ▶ if (defined $basestr && is_array($basestr) && defined $idxstr) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $basestr and is_array($basestr) and defined $idxstr) { } 2 1 3
elsif (not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/) { } 0 2 2
Condition66%4/6
defined $basestr and is_array($basestr) and defined $idxstr
!ll&&!rl&&r
102
defined $basestr and is_array($basestr)
!ll&&!rl&&r
012
MC/DC33%1/3
defined $basestr and is_array($basestr) and defined $idxstr
defined $basestr is_array($basestr) defined $idxstr
Truth table50%2/4
A and B and C
A= defined $basestrB= is_array($basestr)C= defined $idxstr
ABCresult
0XX0
10X0
1100
1111
3279 2 ▶ $idxstr = $parser->setstr('') if is_null($idxstr); # null maps to '' array index
Branch: 1 branch
BranchTrueFalseTotal
if is_null($idxstr) 0 2 2
3280 2 my $arr = $parser->{strmap}{$basestr};
3281 2 my $arrval = $arr->get($idxstr);
3282 2 ▶ if (defined $arrval) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $arrval) { } 0 2 2
elsif (not $ctx->is_superglobal($basevar)) { } 1 1 2
3283 0 $res = 0;
3284 } elsif (!$ctx->is_superglobal($basevar)) {
3285 1 $res = 1;
3286 }
3287 2 $to_num = 1;
3288 ▶ } elsif (!defined $basestr && (!$ctx->is_superglobal($basevar) || ($basevar =~ /^\$GLOBALS$/))) {
Condition16%1/6
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
!ll&&!rl&&r
100
not $ctx->is_superglobal($basevar) or $basevar =~ /^\$GLOBALS$/
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
not defined $basestr not $ctx->is_superglobal($basevar) $basevar =~ /^\$GLOBALS$/
Truth table25%1/4
not(A) and not(B) or C
A= not defined $basestrB= not $ctx->is_superglobal($basevar)C= $basevar =~ /^\$GLOBALS$/
ABCresult
0XX0
1000
11X1
1011
3289 0 ▶ unless ($ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"tainted"}) 0 0 0
3290 0 ▶ $ctx->{warn}->($ctx, 'cmd', $cmd, "$val %s[%s] is #unresolved", $basevar, defined $i ? $i : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 0 0 0
3291 }
3292 }
3293 }
3294 }
3295 }
3296 } elsif ($cmd eq 'is_null_weak') {
3297 # https://php.net/manual/en/types.comparisons.php (similar to $a == null)
3298 #
3299 1 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 1 0 1
3300 1 my $val = $$args[0];
3301 1 ▶ if (is_array($val)) {
Branch: 5 branches
BranchTrueFalseTotal
if (is_array($val)) { } 0 1 1
elsif (is_null($val)) { } 0 1 1
elsif (is_strval($val)) { } 0 1 1
elsif (is_variable($val)) { } 1 0 1
elsif ($val =~ /^(\#elem\d+)$/) { } 0 0 0
3302 0 $res = 1;
3303 0 $to_num = 1;
3304 } elsif (is_null($val)) {
3305 0 $res = 1;
3306 0 $to_num = 1;
3307 } elsif (is_strval($val)) {
3308 0 my $s = $parser->get_strval($val);
3309 0 ▶ if (!defined $s) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 0 0
elsif ($val =~ /^(\#num\d+)$/ and $s == 0) { } 0 0 0
elsif ($s eq '0') { } 0 0 0
elsif ($val =~ /^(\#str\d+)$/ and $s eq '') { } 0 0 0
elsif ($val =~ /^(\#null)$/) { } 0 0 0
3310 0 $res = 1;
3311 ▶ } elsif (($val =~ /^(\#num\d+)$/) && ($s == 0)) {
Condition0%0/3
$val =~ /^(\#num\d+)$/ and $s == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$val =~ /^(\#num\d+)$/ and $s == 0
$val =~ /^(\#num\d+)$/ $s == 0
Truth table0%0/3
A and B
A= $val =~ /^(\#num\d+)$/B= $s == 0
ABresult
0X0
100
111
3312 0 $res = 1;
3313 } elsif ($s eq '0') {
3314 0 $res = 0;
3315 ▶ } elsif (($val =~ /^(\#str\d+)$/) && ($s eq '')) {
Condition0%0/3
$val =~ /^(\#str\d+)$/ and $s eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$val =~ /^(\#str\d+)$/ and $s eq ""
$val =~ /^(\#str\d+)$/ $s eq ""
Truth table0%0/3
A and B
A= $val =~ /^(\#str\d+)$/B= $s eq ""
ABresult
0X0
100
111
3316 0 $res = 1;
3317 } elsif ($val =~ /^(\#null)$/) {
3318 0 $res = 1;
3319 } else {
3320 0 $res = 0;
3321 }
3322 0 $to_num = 1;
3323 } elsif (is_variable($val)) {
3324 1 my $v = $ctx->getvar($val);
3325 1 ▶ if (!defined $v) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $v) { } 1 0 1
elsif ($v eq '#unresolved') { } 0 0 0
3326 1 ▶ unless (&parsing_func($ctx) || $ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&parsing_func($ctx) or $ctx->{"tainted"}) 0 1 1
Condition33%1/3
&parsing_func($ctx) or $ctx->{"tainted"}
l!l&&r!l&&!r
010
MC/DC0%0/2
&parsing_func($ctx) or $ctx->{"tainted"}
&parsing_func($ctx) $ctx->{"tainted"}
Truth table33%1/3
A or B
A= &parsing_func($ctx)B= $ctx->{"tainted"}
ABresult
1X1
011
000
3327 0 ▶ unless ($ctx->{skipundef}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"skipundef"}) 0 0 0
3328 0 ▶ if ($ctx->is_superglobal($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->is_superglobal($val)) { } 0 0 0
3329 # superglobals always exist as empty array,
3330 # Since it is unknown which fields exist in a real environment,
3331 # don't create superglobal array on the fly here.
3332 #
3333 0 $res = 0;
3334 } else {
3335 0 $res = 1;
3336 }
3337 0 $to_num = 1;
3338 }
3339 }
3340 } elsif ($v eq '#unresolved') {
3341 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$val is #unresolved");
3342 }
3343 } elsif ($val =~ /^(\#elem\d+)$/) {
3344 0 my ($v, $i) = @{$parser->{strmap}->{$val}};
3345 0 my ($basevar, $has_index, $idxstr) = $ctx->resolve_variable($val, 0);
3346 0 ▶ if (defined $basevar) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $basevar) 0 0 0
3347 0 my $basestr = $ctx->exec_statement($basevar, 0);
3348 0 ▶ if (defined $basestr && is_array($basestr) && defined $idxstr) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $basestr and is_array($basestr) and defined $idxstr) { } 0 0 0
elsif (not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/) { } 0 0 0
Condition0%0/6
defined $basestr and is_array($basestr) and defined $idxstr
!ll&&!rl&&r
000
defined $basestr and is_array($basestr)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $basestr and is_array($basestr) and defined $idxstr
defined $basestr is_array($basestr) defined $idxstr
Truth table0%0/4
A and B and C
A= defined $basestrB= is_array($basestr)C= defined $idxstr
ABCresult
0XX0
10X0
1100
1111
3349 0 ▶ $idxstr = $parser->setstr('') if is_null($idxstr); # null maps to '' array index
Branch: 1 branch
BranchTrueFalseTotal
if is_null($idxstr) 0 0 0
3350 0 my $arr = $parser->{strmap}{$basestr};
3351 0 my $arrval = $arr->get($idxstr);
3352 0 ▶ if (defined $arrval) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $arrval) { } 0 0 0
elsif (not $ctx->is_superglobal($basevar)) { } 0 0 0
3353 0 my $s = $parser->get_strval($arrval);
3354 0 ▶ if (!defined $s) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $s) { } 0 0 0
elsif ($arrval =~ /^(\#num\d+)$/ and $s == 0) { } 0 0 0
elsif ($arrval eq '0') { } 0 0 0
elsif ($arrval =~ /^(\#str\d+)$/ and $s eq '') { } 0 0 0
elsif ($arrval =~ /^(\#null)$/) { } 0 0 0
3355 0 $res = 1;
3356 ▶ } elsif (($arrval =~ /^(\#num\d+)$/) && ($s == 0)) {
Condition0%0/3
$arrval =~ /^(\#num\d+)$/ and $s == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$arrval =~ /^(\#num\d+)$/ and $s == 0
$arrval =~ /^(\#num\d+)$/ $s == 0
Truth table0%0/3
A and B
A= $arrval =~ /^(\#num\d+)$/B= $s == 0
ABresult
0X0
100
111
3357 0 $res = 1;
3358 } elsif ($arrval eq '0') {
3359 0 $res = 1;
3360 ▶ } elsif (($arrval =~ /^(\#str\d+)$/) && ($s eq '')) {
Condition0%0/3
$arrval =~ /^(\#str\d+)$/ and $s eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$arrval =~ /^(\#str\d+)$/ and $s eq ""
$arrval =~ /^(\#str\d+)$/ $s eq ""
Truth table0%0/3
A and B
A= $arrval =~ /^(\#str\d+)$/B= $s eq ""
ABresult
0X0
100
111
3361 0 $res = 1;
3362 } elsif ($arrval =~ /^(\#null)$/) {
3363 0 $res = 1;
3364 } else {
3365 0 $res = 0;
3366 }
3367 } elsif (!$ctx->is_superglobal($basevar)) {
3368 0 $res = 1;
3369 }
3370 0 $to_num = 1;
3371 ▶ } elsif (!defined $basestr && (!$ctx->is_superglobal($basevar) || ($basevar =~ /^\$GLOBALS$/))) {
Condition0%0/6
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
!ll&&!rl&&r
000
not $ctx->is_superglobal($basevar) or $basevar =~ /^\$GLOBALS$/
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $basestr and !$ctx->is_superglobal($basevar) || $basevar =~ /^\$GLOBALS$/
not defined $basestr not $ctx->is_superglobal($basevar) $basevar =~ /^\$GLOBALS$/
Truth table0%0/4
not(A) and not(B) or C
A= not defined $basestrB= not $ctx->is_superglobal($basevar)C= $basevar =~ /^\$GLOBALS$/
ABCresult
0XX0
1000
11X1
1011
3372 0 ▶ unless ($ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"tainted"}) 0 0 0
3373 0 ▶ $ctx->{warn}->($ctx, 'cmd', $cmd, "$val %s[%s] is #unresolved", $basevar, defined $i ? $i : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 0 0 0
3374 }
3375 }
3376 }
3377 }
3378 }
3379 } elsif ($cmd eq 'isset') {
3380 11 my $inv = &exec_cmd($ctx, 'is_null', $args);
3381 11 ▶ if (defined $inv && is_strval($inv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inv and is_strval($inv)) 6 5 11
Condition66%2/3
defined $inv and is_strval($inv)
!ll&&!rl&&r
506
MC/DC50%1/2
defined $inv and is_strval($inv)
defined $inv is_strval($inv)
Truth table66%2/3
A and B
A= defined $invB= is_strval($inv)
ABresult
0X0
100
111
3382 6 ▶ if ($parser->{strmap}{$inv} eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{'strmap'}{$inv} eq '0') { } 4 2 6
3383 4 $res = 1;
3384 } else {
3385 2 $res = 0;
3386 }
3387 6 $to_num = 1;
3388 }
3389 } elsif ($cmd eq 'define') {
3390 3 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 3 0 3
3391 3 my $key = $parser->get_strval($$args[0]);
3392 3 my $val = $parser->get_strval($$args[1]);
3393 3 ▶ if (defined $key && defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and defined $val) 3 0 3
Condition33%1/3
defined $key and defined $val
!ll&&!rl&&r
003
MC/DC0%0/2
defined $key and defined $val
defined $key defined $val
Truth table33%1/3
A and B
A= defined $keyB= defined $val
ABresult
0X0
100
111
3394 3 ▶ if (defined $ctx->{defines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ctx->{"defines"}) 3 0 3
3395 3 $ctx->{defines}{$key} = $$args[1];
3396 3 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "$key = $val") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 3 3
3397 # no result here
3398 3 return '#noreturn';
3399 }
3400 }
3401 }
3402 } elsif ($cmd eq 'function_exists') {
3403 # https://php.net/manual/en/function.function-exists.php
3404 #
3405 10 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 10 0 10
3406 10 my $fn = $parser->get_strval($$args[0]);
3407 10 ▶ if (defined $fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fn) 10 0 10
3408 10 my $lfn = lc($fn);
3409  
3410 # php functions are always global
3411 # - so a user defined func is valid also in tainted mode
3412 #
3413 10 ▶ unless ($ctx->{skipundef}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->{"skipundef"}) 9 1 10
3414 9 ▶ if ($ctx->getfun($fn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->getfun($fn)) 2 7 9
3415 2 $res = 1;
3416 }
3417 }
3418 10 ▶ unless (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 8 2 10
3419 8 ▶ if (get_php_func($lfn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (get_php_func($lfn)) 2 6 8
3420 2 $res = 1;
3421 }
3422 }
3423 10 ▶ unless (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 6 4 10
3424 6 ▶ if ($ctx->{tainted}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{'tainted'}) { } 0 6 6
3425 0 $ctx->{warn}->($ctx, 'cmd', $cmd, "$fn not found but ctx tainted -> skip execution");
3426 0 return;
3427 } else {
3428 6 $res = 0;
3429 }
3430 }
3431 10 $to_num = 1;
3432 }
3433 }
3434 } elsif ($cmd eq 'create_function') {
3435 # https://php.net/manual/en/function.create-function.php
3436 # (see also: anonymous functions)
3437 #
3438 # This is basically what PHP does internally:
3439 # function create_function($args, $code) {
3440 # // create a random $functionName
3441 # eval('function ' . $functionName . '($args){$code}');
3442 # return $functionName;
3443 # }
3444 #
3445 # It's why you can do something like this (which works on the same principle as SQL injection):
3446 # $code = 'print "I print repeatedly.\n"; } print "I print once.\n"; if (false) {';
3447 # $function = create_function('', $code);
3448 # call_user_func($function);
3449 # call_user_func($function);
3450 #
3451 # // I print once.
3452 # // I print repeatedly.
3453 # // I print repeatedly.
3454 #
3455 12 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 12 0 12
3456 12 my $params = $parser->get_strval($$args[0]);
3457 12 my $code = $parser->get_strval($$args[1]);
3458 12 ▶ if (defined $args && defined $code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args and defined $code) 9 3 12
Condition66%2/3
defined $args and defined $code
!ll&&!rl&&r
039
MC/DC50%1/2
defined $args and defined $code
defined $args defined $code
Truth table66%2/3
A and B
A= defined $argsB= defined $code
ABresult
0X0
100
111
3459 9 my @arglist;
3460 9 foreach my $p (split(/,/, $params)) {
3461 4 my $stmt = $parser->read_statement([$p], undef);
3462 4 push(@arglist, $stmt);
3463 }
3464 # eval with new parser and without global & local varmap
3465 #
3466 9 my $codestr = $parser->setstr('function ('.$params.') {'.$code.'}');
3467 9 my $parser2 = $parser->subparser();
3468 9 my $ctx2 = $ctx->subctx(globals => {}, varmap => {}, parser => $parser2, tainted => 1, varhist => {});
3469 9 my $block = $ctx2->parse_eval($codestr);
3470 9 my $stmt = $ctx2->exec_eval($block);
3471 9 $stmt = $ctx->exec_statement($stmt);
3472 9 return $stmt;
3473 }
3474 }
3475 } elsif ($cmd eq 'call_user_func') {
3476 # https://php.net/manual/en/function.call-user-func.php
3477 #
3478 3 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 3 0 3
3479 3 my $name = $$args[0];
3480 3 ▶ if (is_strval($name) || is_variable($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name) or is_variable($name)) 3 0 3
Condition33%1/3
is_strval($name) or is_variable($name)
l!l&&r!l&&!r
300
MC/DC0%0/2
is_strval($name) or is_variable($name)
is_strval($name) is_variable($name)
Truth table33%1/3
A or B
A= is_strval($name)B= is_variable($name)
ABresult
1X1
011
000
3481 3 ▶ if (is_strval($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name)) 3 0 3
3482 3 $name = $parser->{strmap}->{$name};
3483 }
3484 3 my @arglist = @$args[1..@$args-1];
3485 3 my $call = $parser->setcall($name, \@arglist);
3486 3 return $call;
3487 }
3488 }
3489 } elsif ($cmd eq 'call_user_func_array') {
3490 # https://php.net/manual/en/function.call-user-func-array.php
3491 #
3492 1 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 1 0 1
3493 1 my $name = $$args[0];
3494 1 my $param = $$args[1];
3495 1 ▶ if ((is_strval($name) || is_variable($name)) && is_array($param)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name) || is_variable($name) and is_array($param)) 1 0 1
Condition33%2/6
is_strval($name) || is_variable($name) and is_array($param)
!ll&&!rl&&r
001
is_strval($name) or is_variable($name)
l!l&&r!l&&!r
100
MC/DC0%0/3
is_strval($name) || is_variable($name) and is_array($param)
is_strval($name) is_variable($name) is_array($param)
Truth table20%1/5
A or B and C
A= is_strval($name)B= is_variable($name)C= is_array($param)
ABCresult
00X0
1X00
0100
1X11
0111
3496 1 my $arr = $parser->{strmap}{$param};
3497 1 my $keys = $arr->get_keys();
3498 1 ▶ if (is_strval($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_strval($name)) 1 0 1
3499 1 $name = $parser->{strmap}->{$name};
3500 }
3501 1 ▶ if (@$keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$keys) 1 0 1
3502 1 my @arglist = ();
3503 1 foreach my $k (@$keys) {
3504 1 my $val = $arr->val($k);
3505 1 my $v = $ctx->exec_statement($val);
3506 1 push(@arglist, $v);
3507 }
3508 1 my $call = $parser->setcall($name, \@arglist);
3509 1 return $call;
3510 }
3511 }
3512 }
3513 } elsif ($cmd eq 'file') {
3514 # https://php.net/manual/en/function.file.php
3515 # - TODO: also URL possible
3516 #
3517 0 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 0 0 0
3518 0 my $filename = $parser->get_strval($$args[0]);
3519 0 my $flags = 0;
3520  
3521 0 ▶ if (scalar @$args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args > 1) 0 0 0
3522 0 $flags = $parser->get_strval($$args[1]);
3523 }
3524 0 ▶ if (defined $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) 0 0 0
3525 0 my ($fh) = $parser->newfh($filename, 'r');
3526 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) 0 0 0
3527 0 my $buf = $parser->{strmap}->{$fh}{buf};
3528 0 $parser->{strmap}->{$fh}{buf} = '';
3529 # split in lines and keep trailing newlines
3530 #
3531 0 my @lines;
3532 0 ▶ if ($flags =~ /FILE_IGNORE_NEW_LINES/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags =~ /FILE_IGNORE_NEW_LINES/) { } 0 0 0
3533 0 @lines = split(/\n/, $buf);
3534 } else {
3535 0 @lines = split(/^/, $buf);
3536 }
3537 0 my $arr = $parser->newarr();
3538  
3539 0 foreach my $p (@lines) {
3540 0 ▶ $ctx->{log}->($ctx, 'cmd', $cmd, "[$filename] line: $p") if $ctx->{log};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"log"} 0 0 0
3541 0 my $k = $parser->setstr($p);
3542 0 $arr->set(undef, $k);
3543 }
3544 0 return $arr->{name};
3545 }
3546 }
3547 }
3548 } elsif ($cmd eq 'file_get_contents') {
3549 # https://php.net/manual/en/function.file-get-contents.php
3550 #
3551 1 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 1 0 1
3552 1 my $filename = $parser->get_strval($$args[0]);
3553  
3554 1 ▶ if (defined $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) 1 0 1
3555 1 my ($fh) = $parser->newfh($filename, 'r');
3556 1 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) 0 1 1
3557 0 my $buf = $parser->{strmap}->{$fh}{buf};
3558 0 $parser->{strmap}->{$fh}{buf} = '';
3559 0 $res = $buf;
3560 }
3561 }
3562 }
3563 } elsif ($cmd eq 'reset') {
3564 # https://php.net/manual/en/function.reset.php
3565 # reset next()-pointer & return first array element
3566 #
3567 0 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 0 0 0
3568 0 my $basestr = $$args[0];
3569  
3570 0 ▶ if (is_array($basestr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array($basestr)) 0 0 0
3571 0 my $arr = $parser->{strmap}{$basestr};
3572 0 my $keys = $arr->get_keys();
3573  
3574 #my @vals = map { $arr->val($_) } @$keys;
3575 0 $res = $arr->val($keys->[0]);
3576 }
3577 }
3578 } elsif ($cmd eq 'fopen') {
3579 3 ▶ if (scalar @$args >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 2) 2 1 3
3580 2 my $filename = $parser->get_strval($$args[0]);
3581 2 my $mode = $parser->get_strval($$args[1]);
3582 2 ▶ if (defined $filename && defined $mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename and defined $mode) 1 1 2
Condition66%2/3
defined $filename and defined $mode
!ll&&!rl&&r
101
MC/DC50%1/2
defined $filename and defined $mode
defined $filename defined $mode
Truth table66%2/3
A and B
A= defined $filenameB= defined $mode
ABresult
0X0
100
111
3583 1 my ($fh) = $parser->newfh($filename, $mode);
3584 1 return $fh;
3585 }
3586 }
3587 } elsif ($cmd eq 'fclose') {
3588 2 ▶ if (scalar @$args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 1) 2 0 2
3589 2 my $fh = $$args[0];
3590 2 ▶ if ($fh =~ /^(\#fh\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh =~ /^(\#fh\d+)$/) 0 2 2
3591 0 $parser->{strmap}->{$fh}{pos} = 0;
3592 0 $parser->{strmap}->{$fh}{buf} = '';
3593 }
3594 }
3595 } elsif ($cmd eq 'fread') {
3596 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
3597 0 my $fh = $$args[0];
3598 0 my $cnt = $parser->get_strval($$args[1]);
3599 0 ▶ if (($fh =~ /^(\#fh\d+)$/) && defined $cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh =~ /^(\#fh\d+)$/ and defined $cnt) 0 0 0
Condition0%0/3
$fh =~ /^(\#fh\d+)$/ and defined $cnt
!ll&&!rl&&r
000
MC/DC0%0/2
$fh =~ /^(\#fh\d+)$/ and defined $cnt
$fh =~ /^(\#fh\d+)$/ defined $cnt
Truth table0%0/3
A and B
A= $fh =~ /^(\#fh\d+)$/B= defined $cnt
ABresult
0X0
100
111
3600 0 my $pos = $parser->{strmap}->{$fh}{pos};
3601 0 my $buf = $parser->{strmap}->{$fh}{buf};
3602 0 ▶ if ($cnt > length($buf) - $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt > length($buf) - $pos) 0 0 0
3603 0 $cnt = length($buf) - $pos;
3604 }
3605 0 $res = substr($buf, $pos, $cnt);
3606 0 $pos += $cnt;
3607 0 $parser->{strmap}->{$fh}{pos} = $pos;
3608 }
3609 }
3610 } elsif ($cmd eq 'fgets') {
3611 0 ▶ if (scalar @$args >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args >= 1) 0 0 0
3612 0 my $fh = $$args[0];
3613 0 my $cnt;
3614 0 ▶ if (scalar @$args == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$args == 2) 0 0 0
3615 0 $cnt = $parser->get_strval($$args[1]);
3616 }
3617 0 ▶ if ($fh =~ /^(\#fh\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh =~ /^(\#fh\d+)$/) 0 0 0
3618 0 my $pos = $parser->{strmap}->{$fh}{pos};
3619 0 my $buf = $parser->{strmap}->{$fh}{buf};
3620 0 $res = '';
3621  
3622 0 ▶ while ($pos < length($buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length $buf) 0 0 0
3623 0 my $ch = substr($buf, $pos, 1);
3624 0 ▶ if ($ch eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\n") 0 0 0
3625 0 $pos++;
3626 0 last;
3627 }
3628 0 ▶ last if (defined $cnt && (length($res) >= $cnt));
Branch: 1 branch
BranchTrueFalseTotal
if defined $cnt and length $res >= $cnt 0 0 0
Condition0%0/3
defined $cnt and length $res >= $cnt
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cnt and length $res >= $cnt
defined $cnt length $res >= $cnt
Truth table0%0/3
A and B
A= defined $cntB= length $res >= $cnt
ABresult
0X0
100
111
3629 0 $res .= $ch;
3630 0 $pos++;
3631 }
3632 0 $parser->{strmap}->{$fh}{pos} = $pos;
3633 }
3634 }
3635 }
3636  
3637 428 ▶ if (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res) 120 308 428
3638 120 my $k;
3639 120 ▶ if ($to_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_num) { } 80 40 120
3640 80 $k = $parser->setnum($res);
3641 } else {
3642 40 $k = $parser->setstr($res);
3643 }
3644 120 return $k;
3645 }
3646 308 return;
3647 }
3648  
3649 4 1;
3650  
3651 __END__
↑ Summary Decode/Parser.pm »