PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/coverage.php

http://github.com/vrana/adminer
PHP | 82 lines | 60 code | 3 blank | 19 comment | 12 complexity | 8bbefac6e0fa042cca451c5c77d852ef MD5 | raw file
  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. <body>
  8. <?php
  9. function xhtml_open_tags($s) {
  10. // returns array of opened tags in $s
  11. $return = array();
  12. preg_match_all('~<([^>]+)~', $s, $matches);
  13. foreach ($matches[1] as $val) {
  14. if ($val[0] == "/") {
  15. array_pop($return);
  16. } elseif (substr($val, -1) != "/") {
  17. $return[] = $val;
  18. }
  19. }
  20. return $return;
  21. }
  22. $coverage_filename = sys_get_temp_dir() . "/adminer_coverage.ser";
  23. if (!extension_loaded("xdebug")) {
  24. echo "<p class='error'>Xdebug has to be enabled.</p>\n";
  25. } elseif ($_GET["coverage"] === "0") {
  26. file_put_contents($coverage_filename, serialize(array()));
  27. echo "<p class='message'>Coverage started.</p>\n";
  28. } elseif (preg_match('~^(adminer|editor)/(include/)?[-_.a-z0-9]+$~i', $_GET["coverage"])) {
  29. // highlight single file
  30. $filename = $_GET["coverage"];
  31. $coverage = (file_exists($coverage_filename) ? unserialize(file_get_contents($coverage_filename)) : array());
  32. $file = explode("<br />", highlight_file($filename, true));
  33. $prev_color = null;
  34. $s = "";
  35. for ($l=0; $l <= count($file); $l++) {
  36. $line = $file[$l];
  37. $color = "#C0FFC0"; // tested
  38. switch ($coverage[realpath($filename)][$l+1]) {
  39. case -1: $color = "#FFC0C0"; break; // untested
  40. case -2: $color = "Silver"; break; // dead code
  41. case null: $color = ""; break; // not executable
  42. }
  43. if ($prev_color === null) {
  44. $prev_color = $color;
  45. }
  46. if ($prev_color != $color || $line === null) {
  47. echo "<div" . ($prev_color ? " style='background-color: $prev_color;'" : "") . ">$s";
  48. $open_tags = xhtml_open_tags($s);
  49. foreach (array_reverse($open_tags) as $tag) {
  50. echo "</" . preg_replace('~ .*~', '', $tag) . ">";
  51. }
  52. echo "</div>\n";
  53. $s = ($open_tags ? "<" . implode("><", $open_tags) . ">" : "");
  54. $prev_color = $color;
  55. }
  56. $s .= "$line<br />\n";
  57. }
  58. } else {
  59. if (file_exists($coverage_filename)) {
  60. // display list of files
  61. $coverage = unserialize(file_get_contents($coverage_filename));
  62. echo "<table border='1' cellspacing='0'>\n";
  63. foreach (array_merge(glob("adminer/*.php"), glob("adminer/include/*.php"), glob("editor/*.php"), glob("editor/include/*.php")) as $filename) {
  64. $cov = $coverage[realpath($filename)];
  65. $ratio = 0;
  66. if (is_array($cov)) {
  67. $values = array_count_values($cov);
  68. $ratio = round(100 - 100 * $values[-1] / (count($cov) - $values[-2]));
  69. }
  70. 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";
  71. }
  72. echo "</table>\n";
  73. }
  74. echo "<p><a href='coverage.php?coverage=0'>Start new coverage</a></p>\n";
  75. }
  76. ?>
  77. </body>
  78. </html>