PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/php-bartlett-PHP-CompatInfo-2.5.0/PHP_CompatInfo-2.5.0/PHP/CompatInfo/Report.php

#
PHP | 167 lines | 83 code | 17 blank | 67 comment | 11 complexity | 1737e4b674ab07f6440d0c981d0a09f5 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Base class to produce report of type requested
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PHP_CompatInfo
  9. * @author Laurent Laville <pear@laurent-laville.org>
  10. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  11. * @version SVN: $Id$
  12. * @link http://php5.laurent-laville.org/compatinfo/
  13. */
  14. require_once 'PHP/Timer.php';
  15. /**
  16. * Abstract base class of each report
  17. *
  18. * @category PHP
  19. * @package PHP_CompatInfo
  20. * @author Laurent Laville <pear@laurent-laville.org>
  21. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  22. * @version Release: 2.5.0
  23. * @link http://php5.laurent-laville.org/compatinfo/
  24. */
  25. abstract class PHP_CompatInfo_Report
  26. {
  27. /**
  28. * @var int Report character width (default to 79)
  29. */
  30. protected $width = 79;
  31. /**
  32. * @var array PHP Minimum and Maximum versions
  33. */
  34. protected $globalVersions;
  35. /**
  36. * @var int Total of elements excluded from scope due to rulesets
  37. */
  38. protected $totalExcludes;
  39. /**
  40. * @var array Elements found on scope
  41. */
  42. protected $total;
  43. /**
  44. * Class constructor for each report
  45. *
  46. * @param string $source Data source
  47. * @param array $options Options for parser
  48. * @param array $warnings List of warning messages already produced
  49. */
  50. public function __construct($source, $options, $warnings)
  51. {
  52. $pci = new PHP_CompatInfo($options);
  53. if ($pci->parse($source) === true) {
  54. $report = $pci->toArray();
  55. $base = realpath($source);
  56. if (is_file($base)) {
  57. $base = dirname($base);
  58. }
  59. } else {
  60. $report = array();
  61. $base = false;
  62. }
  63. $allWarnings = array_unique(
  64. array_merge($warnings, $pci->getWarnings())
  65. );
  66. if (isset($options['reportFile'])) {
  67. ob_start();
  68. }
  69. $this->generate($report, $base, $options['verbose']);
  70. if (isset($options['reportFile'])) {
  71. $generatedReport = ob_get_clean();
  72. file_put_contents(
  73. $options['reportFile'], $generatedReport,
  74. $options['reportFileFlags']
  75. );
  76. }
  77. if (count($allWarnings) > 0 && $options['verbose'] > 0) {
  78. echo 'Warning messages : (' . count($allWarnings) . ')' . PHP_EOL;
  79. echo PHP_EOL;
  80. foreach ($allWarnings as $warn) {
  81. if (in_array($warn, $warnings)) {
  82. // other listeners need to be notifed about console warnings
  83. $pci->addWarning($warn);
  84. }
  85. echo ' ' . $warn . PHP_EOL;
  86. }
  87. }
  88. }
  89. /**
  90. * Abstract function to implement on each report to produce results of type
  91. * reference, extension, interface, class, function, constant
  92. *
  93. * @param array $report Report data to produce
  94. * @param string $base Base directory of data source
  95. * @param int $verbose Verbose level (0: none, 1: warnings, ...)
  96. *
  97. * @return void
  98. */
  99. abstract public function generate($report, $base, $verbose);
  100. /**
  101. * Returns conditional code number
  102. *
  103. * @param array $conditions Conditional code uses
  104. *
  105. * @return int
  106. */
  107. protected function getCCN($conditions)
  108. {
  109. $ccn = 0;
  110. foreach ($conditions as $category => $count) {
  111. if ($count > 0) {
  112. switch ($category) {
  113. case 'function_exists':
  114. $ccn = $ccn | 1;
  115. break;
  116. case 'extension_loaded':
  117. $ccn = $ccn | 2;
  118. break;
  119. case 'defined':
  120. $ccn = $ccn | 4;
  121. break;
  122. case 'method_exists':
  123. $ccn = $ccn | 16;
  124. break;
  125. case 'class_exists':
  126. $ccn = $ccn | 32;
  127. break;
  128. case 'interface_exists':
  129. $ccn = $ccn | 64;
  130. break;
  131. }
  132. }
  133. }
  134. return $ccn;
  135. }
  136. /**
  137. * Update the base version if current ref version is greater
  138. *
  139. * @param string $current Current version
  140. * @param string &$base Base version
  141. *
  142. * @return void
  143. */
  144. protected function updateVersion($current, &$base)
  145. {
  146. if (version_compare($current, $base, 'gt')) {
  147. $base = $current;
  148. }
  149. }
  150. }