Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 83 lines (78 sloc) 2.917 kB
70c8343 Save coverage to database
jakubvrana authored
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="cs">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>Coverage</title>
6 </head>
7
8 <body>
9
10 <?php
11 function xhtml_open_tags($s) {
12 // returns array of opened tags in $s
13 $return = array();
14 preg_match_all('~<([^>]+)~', $s, $matches);
15 foreach ($matches[1] as $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
16 if ($val[0] == "/") {
70c8343 Save coverage to database
jakubvrana authored
17 array_pop($return);
18 } elseif (substr($val, -1) != "/") {
19 $return[] = $val;
20 }
21 }
22 return $return;
23 }
24
be9c98a Save coverage to temporary file
jakubvrana authored
25 $coverage_filename = sys_get_temp_dir() . "/adminer_coverage.ser";
70c8343 Save coverage to database
jakubvrana authored
26 if (!extension_loaded("xdebug")) {
27 echo "<p class='error'>Xdebug has to be enabled.</p>\n";
28 } elseif ($_GET["coverage"] === "0") {
be9c98a Save coverage to temporary file
jakubvrana authored
29 file_put_contents($coverage_filename, serialize(array()));
70c8343 Save coverage to database
jakubvrana authored
30 echo "<p class='message'>Coverage started.</p>\n";
31 } elseif (preg_match('~^(adminer|editor)/(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) {
32 // highlight single file
33 $filename = $_GET["coverage"];
be9c98a Save coverage to temporary file
jakubvrana authored
34 $coverage = (file_exists($coverage_filename) ? unserialize(file_get_contents($coverage_filename)) : array());
70c8343 Save coverage to database
jakubvrana authored
35 $file = explode("<br />", highlight_file($filename, true));
6591d48 @vrana Replace isset($var) by $var !== null
authored
36 $prev_color = null;
70c8343 Save coverage to database
jakubvrana authored
37 $s = "";
38 for ($l=0; $l <= count($file); $l++) {
39 $line = $file[$l];
40 $color = "#C0FFC0"; // tested
be9c98a Save coverage to temporary file
jakubvrana authored
41 switch ($coverage[realpath($filename)][$l+1]) {
70c8343 Save coverage to database
jakubvrana authored
42 case -1: $color = "#FFC0C0"; break; // untested
43 case -2: $color = "Silver"; break; // dead code
44 case null: $color = ""; break; // not executable
45 }
6591d48 @vrana Replace isset($var) by $var !== null
authored
46 if ($prev_color === null) {
70c8343 Save coverage to database
jakubvrana authored
47 $prev_color = $color;
48 }
6591d48 @vrana Replace isset($var) by $var !== null
authored
49 if ($prev_color != $color || $line === null) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
50 echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">$s";
70c8343 Save coverage to database
jakubvrana authored
51 $open_tags = xhtml_open_tags($s);
52 foreach (array_reverse($open_tags) as $tag) {
53 echo "</" . preg_replace('~ .*~', '', $tag) . ">";
54 }
55 echo "</div>\n";
56 $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
57 $prev_color = $color;
58 }
59 $s .= "$line<br />\n";
60 }
61 } else {
be9c98a Save coverage to temporary file
jakubvrana authored
62 if (file_exists($coverage_filename)) {
63 // display list of files
64 $coverage = unserialize(file_get_contents($coverage_filename));
70c8343 Save coverage to database
jakubvrana authored
65 echo "<table border='1' cellspacing='0'>\n";
66 foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php"), glob("editor/*.php"), glob("editor/include/*.php")) as $filename) {
67 $cov = $coverage[realpath($filename)];
68 $ratio = 0;
69 if (is_array($cov)) {
70 $values = array_count_values($cov);
be9c98a Save coverage to temporary file
jakubvrana authored
71 $ratio = round(100 - 100 * $values[-1] / (count($cov) - $values[-2]));
70c8343 Save coverage to database
jakubvrana authored
72 }
73 echo "<tr><td align='right' style='background-color: " . ($ratio < 50 ? "Red" : ($ratio < 75 ? "#FFEA20" : "#A7FC9D")) . ";'>$ratio%</td><td><a href='coverage.php?coverage=$filename'>$filename</a></td></tr>\n";
74 }
75 echo "</table>\n";
76 }
77 echo "<p><a href='coverage.php?coverage=0'>Start new coverage</a></p>\n";
78 }
79 ?>
80
81 </body>
82 </html>
Something went wrong with that request. Please try again.