PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/script/lib/PHP/Depend/TextUI/ResultPrinter.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 255 lines | 82 code | 23 blank | 150 comment | 7 complexity | f340b6f56abbbb5d9a2862fbe923ee4f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0
  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: 0.9.19
  60. * @link http://pdepend.org/
  61. */
  62. class PHP_Depend_TextUI_ResultPrinter extends PHP_Depend_Visitor_AbstractListener implements PHP_Depend_ProcessListenerI
  63. {
  64. /**
  65. * The step size.
  66. */
  67. const STEP_SIZE = 20;
  68. /**
  69. * Number of processed items.
  70. *
  71. * @var integer $_count
  72. */
  73. private $_count = 0;
  74. /**
  75. * Is called when PDepend starts the file parsing process.
  76. *
  77. * @param PHP_Depend_BuilderI $builder The used node builder instance.
  78. *
  79. * @return void
  80. */
  81. public function startParseProcess(PHP_Depend_BuilderI $builder)
  82. {
  83. $this->_count = 0;
  84. echo "Parsing source files:\n";
  85. }
  86. /**
  87. * Is called when PDepend has finished the file parsing process.
  88. *
  89. * @param PHP_Depend_BuilderI $builder The used node builder instance.
  90. *
  91. * @return void
  92. */
  93. public function endParseProcess(PHP_Depend_BuilderI $builder)
  94. {
  95. $this->finish();
  96. }
  97. /**
  98. * Is called when PDepend starts parsing of a new file.
  99. *
  100. * @param PHP_Depend_TokenizerI $tokenizer The used tokenizer instance.
  101. *
  102. * @return void
  103. */
  104. public function startFileParsing(PHP_Depend_TokenizerI $tokenizer)
  105. {
  106. $this->step();
  107. }
  108. /**
  109. * Is called when PDepend has finished a file.
  110. *
  111. * @param PHP_Depend_TokenizerI $tokenizer The used tokenizer instance.
  112. *
  113. * @return void
  114. */
  115. public function endFileParsing(PHP_Depend_TokenizerI $tokenizer)
  116. {
  117. }
  118. /**
  119. * Is called when PDepend starts the analyzing process.
  120. *
  121. * @return void
  122. */
  123. public function startAnalyzeProcess()
  124. {
  125. }
  126. /**
  127. * Is called when PDepend has finished the analyzing process.
  128. *
  129. * @return void
  130. */
  131. public function endAnalyzeProcess()
  132. {
  133. }
  134. /**
  135. * Is called when PDepend starts the logging process.
  136. *
  137. * @return void
  138. */
  139. public function startLogProcess()
  140. {
  141. echo "Generating pdepend log files, this may take a moment.\n";
  142. }
  143. /**
  144. * Is called when PDepend has finished the logging process.
  145. *
  146. * @return void
  147. */
  148. public function endLogProcess()
  149. {
  150. }
  151. /**
  152. * Is called when PDepend starts a new analyzer.
  153. *
  154. * @param PHP_Depend_Metrics_AnalyzerI $analyzer The context analyzer instance.
  155. *
  156. * @return void
  157. */
  158. public function startAnalyzer(PHP_Depend_Metrics_AnalyzerI $analyzer)
  159. {
  160. $this->_count = 0;
  161. $name = substr(get_class($analyzer), 19, - 9);
  162. echo "Executing {$name}-Analyzer:\n";
  163. }
  164. /**
  165. * Is called when PDepend has finished one analyzing process.
  166. *
  167. * @param PHP_Depend_Metrics_AnalyzerI $analyzer The context analyzer instance.
  168. *
  169. * @return void
  170. */
  171. public function endAnalyzer(PHP_Depend_Metrics_AnalyzerI $analyzer)
  172. {
  173. $this->finish(self :: STEP_SIZE);
  174. }
  175. /**
  176. * Generic notification method that is called for every node start.
  177. *
  178. * @param PHP_Depend_Code_NodeI $node The context node instance.
  179. *
  180. * @return void
  181. * @see PHP_Depend_Visitor_AbstractVisitor::startVisitNode()
  182. */
  183. public function startVisitNode(PHP_Depend_Code_NodeI $node)
  184. {
  185. $this->step(self :: STEP_SIZE);
  186. }
  187. /**
  188. * Prints a single dot for the current step.
  189. *
  190. * @param integer $size The number of processed items that result in a new dot.
  191. *
  192. * @return void
  193. */
  194. protected function step($size = 1)
  195. {
  196. if ($this->_count > 0 && $this->_count % $size === 0)
  197. {
  198. echo '.';
  199. }
  200. if ($this->_count > 0 && $this->_count % ($size * 60) === 0)
  201. {
  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. {
  218. printf(".% 6s\n\n", $this->_count);
  219. }
  220. else
  221. if ($size === 1)
  222. {
  223. $indent = 66 - ceil($diff / $size);
  224. printf(".% {$indent}s\n\n", $this->_count);
  225. }
  226. else
  227. {
  228. $indent = 66 - ceil($diff / $size) + 1;
  229. printf("% {$indent}s\n\n", $this->_count);
  230. }
  231. }
  232. }