PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/pdepend/PHP/Depend/TextUI/ResultPrinter.php

https://github.com/JohnMurray/VulnScan
PHP | 249 lines | 76 code | 23 blank | 150 comment | 8 complexity | e1f71252db60294696c83a6a598727ee MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of PHP_Depend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @category QualityAssurance
  40. * @package PHP_Depend
  41. * @subpackage TextUI
  42. * @author Manuel Pichler <mapi@pdepend.org>
  43. * @copyright 2008-2010 Manuel Pichler. All rights reserved.
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. * @version SVN: $Id$
  46. * @link http://pdepend.org/
  47. */
  48. require_once 'PHP/Depend/ProcessListenerI.php';
  49. require_once 'PHP/Depend/Visitor/AbstractListener.php';
  50. /**
  51. * Prints current the PDepend status informations.
  52. *
  53. * @category QualityAssurance
  54. * @package PHP_Depend
  55. * @subpackage TextUI
  56. * @author Manuel Pichler <mapi@pdepend.org>
  57. * @copyright 2008-2010 Manuel Pichler. All rights reserved.
  58. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  59. * @version Release: @package_version@
  60. * @link http://pdepend.org/
  61. */
  62. class PHP_Depend_TextUI_ResultPrinter
  63. extends PHP_Depend_Visitor_AbstractListener
  64. implements PHP_Depend_ProcessListenerI
  65. {
  66. /**
  67. * The step size.
  68. */
  69. const STEP_SIZE = 20;
  70. /**
  71. * Number of processed items.
  72. *
  73. * @var integer $_count
  74. */
  75. private $_count = 0;
  76. /**
  77. * Is called when PDepend starts the file parsing process.
  78. *
  79. * @param PHP_Depend_BuilderI $builder The used node builder instance.
  80. *
  81. * @return void
  82. */
  83. public function startParseProcess(PHP_Depend_BuilderI $builder)
  84. {
  85. $this->_count = 0;
  86. echo "Parsing source files:\n";
  87. }
  88. /**
  89. * Is called when PDepend has finished the file parsing process.
  90. *
  91. * @param PHP_Depend_BuilderI $builder The used node builder instance.
  92. *
  93. * @return void
  94. */
  95. public function endParseProcess(PHP_Depend_BuilderI $builder)
  96. {
  97. $this->finish();
  98. }
  99. /**
  100. * Is called when PDepend starts parsing of a new file.
  101. *
  102. * @param PHP_Depend_TokenizerI $tokenizer The used tokenizer instance.
  103. *
  104. * @return void
  105. */
  106. public function startFileParsing(PHP_Depend_TokenizerI $tokenizer)
  107. {
  108. $this->step();
  109. }
  110. /**
  111. * Is called when PDepend has finished a file.
  112. *
  113. * @param PHP_Depend_TokenizerI $tokenizer The used tokenizer instance.
  114. *
  115. * @return void
  116. */
  117. public function endFileParsing(PHP_Depend_TokenizerI $tokenizer)
  118. {
  119. }
  120. /**
  121. * Is called when PDepend starts the analyzing process.
  122. *
  123. * @return void
  124. */
  125. public function startAnalyzeProcess()
  126. {
  127. }
  128. /**
  129. * Is called when PDepend has finished the analyzing process.
  130. *
  131. * @return void
  132. */
  133. public function endAnalyzeProcess()
  134. {
  135. }
  136. /**
  137. * Is called when PDepend starts the logging process.
  138. *
  139. * @return void
  140. */
  141. public function startLogProcess()
  142. {
  143. echo "Generating pdepend log files, this may take a moment.\n";
  144. }
  145. /**
  146. * Is called when PDepend has finished the logging process.
  147. *
  148. * @return void
  149. */
  150. public function endLogProcess()
  151. {
  152. }
  153. /**
  154. * Is called when PDepend starts a new analyzer.
  155. *
  156. * @param PHP_Depend_Metrics_AnalyzerI $analyzer The context analyzer instance.
  157. *
  158. * @return void
  159. */
  160. public function startAnalyzer(PHP_Depend_Metrics_AnalyzerI $analyzer)
  161. {
  162. $this->_count = 0;
  163. $name = substr(get_class($analyzer), 19, -9);
  164. echo "Executing {$name}-Analyzer:\n";
  165. }
  166. /**
  167. * Is called when PDepend has finished one analyzing process.
  168. *
  169. * @param PHP_Depend_Metrics_AnalyzerI $analyzer The context analyzer instance.
  170. *
  171. * @return void
  172. */
  173. public function endAnalyzer(PHP_Depend_Metrics_AnalyzerI $analyzer)
  174. {
  175. $this->finish(self::STEP_SIZE);
  176. }
  177. /**
  178. * Generic notification method that is called for every node start.
  179. *
  180. * @param PHP_Depend_Code_NodeI $node The context node instance.
  181. *
  182. * @return void
  183. * @see PHP_Depend_Visitor_AbstractVisitor::startVisitNode()
  184. */
  185. public function startVisitNode(PHP_Depend_Code_NodeI $node)
  186. {
  187. $this->step(self::STEP_SIZE);
  188. }
  189. /**
  190. * Prints a single dot for the current step.
  191. *
  192. * @param integer $size The number of processed items that result in a new dot.
  193. *
  194. * @return void
  195. */
  196. protected function step($size = 1)
  197. {
  198. if ($this->_count > 0 && $this->_count % $size === 0) {
  199. echo '.';
  200. }
  201. if ($this->_count > 0 && $this->_count % ($size * 60) === 0) {
  202. printf("% 6s\n", $this->_count);
  203. }
  204. ++$this->_count;
  205. }
  206. /**
  207. * Closes the current dot line.
  208. *
  209. * @param integer $size The number of processed items that result in a new dot.
  210. *
  211. * @return void
  212. */
  213. protected function finish($size = 1)
  214. {
  215. $diff = ($this->_count % ($size * 60));
  216. if ($diff === 0) {
  217. printf(".% 6s\n\n", $this->_count);
  218. } else if ($size === 1) {
  219. $indent = 66 - ceil($diff / $size);
  220. printf(".% {$indent}s\n\n", $this->_count);
  221. } else {
  222. $indent = 66 - ceil($diff / $size) + 1;
  223. printf("% {$indent}s\n\n", $this->_count);
  224. }
  225. }
  226. }