/vendor/phpunit/php-code-coverage/src/Report/Html/Renderer/Directory.php

https://bitbucket.org/alan_cordova/api-sb-map · PHP · 101 lines · 66 code · 14 blank · 21 comment · 4 complexity · c249ddabdeed209047693548555755e7 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the php-code-coverage package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\CodeCoverage\Report\Html;
  11. use SebastianBergmann\CodeCoverage\Node\AbstractNode as Node;
  12. use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
  13. /**
  14. * Renders a directory node.
  15. */
  16. class Directory extends Renderer
  17. {
  18. /**
  19. * @param DirectoryNode $node
  20. * @param string $file
  21. */
  22. public function render(DirectoryNode $node, $file)
  23. {
  24. $template = new \Text_Template($this->templatePath . 'directory.html', '{{', '}}');
  25. $this->setCommonTemplateVariables($template, $node);
  26. $items = $this->renderItem($node, true);
  27. foreach ($node->getDirectories() as $item) {
  28. $items .= $this->renderItem($item);
  29. }
  30. foreach ($node->getFiles() as $item) {
  31. $items .= $this->renderItem($item);
  32. }
  33. $template->setVar(
  34. [
  35. 'id' => $node->getId(),
  36. 'items' => $items
  37. ]
  38. );
  39. $template->renderTo($file);
  40. }
  41. /**
  42. * @param Node $node
  43. * @param bool $total
  44. *
  45. * @return string
  46. */
  47. protected function renderItem(Node $node, $total = false)
  48. {
  49. $data = [
  50. 'numClasses' => $node->getNumClassesAndTraits(),
  51. 'numTestedClasses' => $node->getNumTestedClassesAndTraits(),
  52. 'numMethods' => $node->getNumMethods(),
  53. 'numTestedMethods' => $node->getNumTestedMethods(),
  54. 'linesExecutedPercent' => $node->getLineExecutedPercent(false),
  55. 'linesExecutedPercentAsString' => $node->getLineExecutedPercent(),
  56. 'numExecutedLines' => $node->getNumExecutedLines(),
  57. 'numExecutableLines' => $node->getNumExecutableLines(),
  58. 'testedMethodsPercent' => $node->getTestedMethodsPercent(false),
  59. 'testedMethodsPercentAsString' => $node->getTestedMethodsPercent(),
  60. 'testedClassesPercent' => $node->getTestedClassesAndTraitsPercent(false),
  61. 'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent()
  62. ];
  63. if ($total) {
  64. $data['name'] = 'Total';
  65. } else {
  66. if ($node instanceof DirectoryNode) {
  67. $data['name'] = sprintf(
  68. '<a href="%s/index.html">%s</a>',
  69. $node->getName(),
  70. $node->getName()
  71. );
  72. $data['icon'] = '<span class="glyphicon glyphicon-folder-open"></span> ';
  73. } else {
  74. $data['name'] = sprintf(
  75. '<a href="%s.html">%s</a>',
  76. $node->getName(),
  77. $node->getName()
  78. );
  79. $data['icon'] = '<span class="glyphicon glyphicon-file"></span> ';
  80. }
  81. }
  82. return $this->renderItemTemplate(
  83. new \Text_Template($this->templatePath . 'directory_item.html', '{{', '}}'),
  84. $data
  85. );
  86. }
  87. }