QA_Peardoc_Coverage
[ class tree: QA_Peardoc_Coverage ] [ index: QA_Peardoc_Coverage ] [ all elements ]

Source for file ExtendetPackageList.php

Documentation is available at ExtendetPackageList.php

  1. <?php
  2. require_once 'QA/Peardoc/Coverage/Renderer.php';
  3.  
  4. /**
  5. * Renders the coverage result in an extendet
  6. * list of packages with its documented state,
  7. * and the classes with their methods.
  8. *
  9. @category QA
  10. @package  QA_Peardoc_Coverage
  11. @author   Christian Weiske <cweiske@php.net>
  12. @license  http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  13. @version  CVS: $Id: ExtendetPackageList.php,v 1.7 2007/07/18 18:52:44 cweiske Exp $
  14. @link     http://pear.php.net/package/QA_Peardoc_Coverage
  15. */
  16.     implements QA_Peardoc_Coverage_Renderer
  17. {
  18.     public static $colNotDocumented '#F00';
  19.     public static $colDocumented    '#0F0';
  20.  
  21.     public static $colMethodDocumented      '#9F9';
  22.     public static $colMethodNotDocumented   '#F99';
  23.     public static $colMethodPartlyDocumented'#FF9';
  24.  
  25.  
  26.  
  27.     /**
  28.     * Returns the color code matching the number.
  29.     *
  30.     * @param float $flNumber Number (x/y), !no! percentage
  31.     *
  32.     * @return string HTML color #0AF
  33.     */
  34.     public static function getColor($flNumber)
  35.     {
  36.         if ($flNumber == 1{
  37.             return '#0F0';
  38.         else if ($flNumber >= 0.9{
  39.             return '#dfff00';
  40.         else if ($flNumber >= 0.5{
  41.             return '#FF0';
  42.         else if ($flNumber >= 0.3{
  43.             return '#F70';
  44.         else {
  45.             return '#F00';
  46.         }
  47.     }//public static function getColor($flNumber)
  48.  
  49.  
  50.  
  51.     /**
  52.     * Returns the manual url (deep link) for
  53.     * the given documentation id.
  54.     *
  55.     * @param string $strDocId Documentation id=""
  56.     *
  57.     * @return string URL to the manual
  58.     */
  59.     public static function getDocUrl($strDocId)
  60.     {
  61.         return 'http://pear.php.net/manual/en/'
  62.             . $strDocId '.php';
  63.     }//public static function getDocUrl($strDocId)
  64.  
  65.  
  66.  
  67.     /**
  68.     * Renders the given coverage array and
  69.     * returns the HTML.
  70.     *
  71.     * @param array $arDoc     Documentation coverage analysis results
  72.     * @param array $arOptions Options
  73.     *
  74.     * @return string HTML
  75.     */
  76.     public function render($arDoc$arOptions = null)
  77.     {
  78.         $n    "\n";
  79.         $out  '';
  80.         $out .= '<?xml version="1.0" encoding="utf-8" ?>' $n
  81.             . '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
  82.             . '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
  83.  
  84.         $out .= '<html><head><title>Extendet PEAR Documentation coverage analysis</title>'
  85.             . '<style type="text/css">th { background-color: black; color: white; }'
  86.             . 'td.class { font-weight:bold;}'
  87.             . '</style></head><body>';
  88.         $out .= '<table border="1"><caption>'
  89.             . 'Extendet PEAR Documentation coverage analysis as of '
  90.             . date('Y-m-d H:i:s'$arDoc['*date*'])
  91.             . '</caption>' $n;
  92.  
  93.         $nPackages       = 0;
  94.         $nDoccedPackages = 0;
  95.         $nCategories     = 0;
  96.         //Package name|Class name|methods|number/percent
  97.  
  98.         foreach ($arDoc as $strCategory => $arCategoryPackages{
  99.             if ($strCategory[0== '*'{
  100.                 continue;
  101.             }
  102.  
  103.             $out .= '<tr><th colspan="3">' ucfirst($strCategory'</th></tr>' $n;
  104.             ++$nCategories;
  105.             $nCategoryPackages       = 0;
  106.             $nCategoryDoccedPackages = 0;
  107.  
  108.             foreach ($arCategoryPackages as $strPackageName => $arPackageCoverage{
  109.                 ++$nCategoryPackages;
  110.                 ++$nPackages;
  111.  
  112.                 $out .= '<tr><td colspan="2">'
  113.                      . '<a href="http://pear.php.net/package/' $strPackageName '" name="' $strPackageName '">'
  114.                      . $strPackageName
  115.                      . '</a>'
  116.                      . '</td>';
  117.                 if ($arPackageCoverage['*docid*'=== null{
  118.                     //not documented
  119.                     $out .= '<td style="background-color:'
  120.                          . self::$colNotDocumented
  121.                          . '">undocumented</td></tr>' $n;
  122.                 else {
  123.                     //documented
  124.                     ++$nDoccedPackages;
  125.                     ++$nCategoryDoccedPackages;
  126.                     $out .= '<td style="background-color:'
  127.                          . self::$colDocumented
  128.                          . '"><a href="'
  129.                          . self::getDocUrl($arPackageCoverage['*docid*'])
  130.                          . '">documented</a></td></tr>' $n;
  131.                     $out .= self::getMethodDocState($arPackageCoverage);
  132.                 }
  133.             }//foreach package in category
  134.             /*
  135.             $col = self::getColor($nCategoryDoccedPackages/$nCategoryPackages);
  136.             $out .= '<tr>'
  137.                     . '<td>' . $nCategoryPackages . '</td>'
  138.                     . '<td style="text-align:right; font-weight:bold; background-color:' . $col . '">'
  139.                         . $nCategoryDoccedPackages . '/' . $nCategoryPackages . '</td>'
  140.                     . '</tr>' . $n;
  141.             */
  142.         }//foreach category
  143.  
  144.         $col  = self::getColor($nDoccedPackages/$nPackages);
  145.         $out .= '<tr style="font-weight:bold; background-color:' $col '">'
  146.               . '<td rowspan="2">' $nCategories ' categories</td>'
  147.               . '<td style="text-align:right;">Packages documented: ' $nDoccedPackages '/' $nPackages '</td>'
  148.               . '</tr>' $n;
  149.         $out .= '<tr style="font-weight:bold; background-color:' $col '">'
  150.               . '<td style="text-align:right;">' number_format($nDoccedPackages/$nPackages * 1002'%</td>'
  151.               . '</tr>' $n;
  152.  
  153.         $out .= '</table>';
  154.  
  155.         $out .= '</body></html>';
  156.  
  157.         return $out;
  158.     }//public function render($arDoc)
  159.  
  160.  
  161.  
  162.     /**
  163.     * Generates the class/method coverage html
  164.     *
  165.     * @return string Class and method coverage HTML
  166.     */
  167.     public static function getMethodDocState($arPackageCoverage)
  168.     {
  169.         $n              "\n";
  170.         $out            '';
  171.         $nClasses       = 0;
  172.         $nClassesDocced = 0;
  173.         foreach ($arPackageCoverage as $strClass => $arMethods{
  174.             if ($strClass[0== '*'{
  175.                 continue;
  176.             }
  177.             ++$nClasses;
  178.  
  179.             if ($arMethods === null{
  180.                 //FIXME: display not docced
  181.                 $out .= '<tr><td></td><td class="class">'
  182.                     . $strClass
  183.                     . '</td><td style="background-color:' . self::$colMethodNotDocumented'">undocumented</td></tr>' $n;
  184.                 continue;
  185.             }
  186.  
  187.             $nMethods       = 0;
  188.             $nMethodsDocced = 0;
  189.             $strDocced      '';
  190.             $strNotDocced   '';
  191.             foreach ($arMethods as $strMethod => $bDocumented{
  192.                 if ($strMethod[0== '_'{
  193.                     continue;
  194.                 }
  195.  
  196.                 ++$nMethods;
  197.                 if ($bDocumented{
  198.                     ++$nMethodsDocced;
  199.                     $strDocced .= $strMethod ', ';
  200.                 else {
  201.                     $strNotDocced .= $strMethod ', ';
  202.                 }
  203.             }
  204.  
  205.             //class
  206.             $mout '';
  207.             if ($nMethods > 0 && $nMethods != $nMethodsDocced{
  208.                 if ($nMethodsDocced > 0{
  209.                     //docced
  210.                     $mout .= '<tr><td></td>'
  211.                         . '<td style="background-color:' . self::$colMethodDocumented '">'
  212.                         . $strDocced '</td>'
  213.                         . '<td>' $nMethodsDocced '</td></tr>' $n;
  214.  
  215.                 }
  216.                 //undocced
  217.                 $mout .= '<tr><td></td>'
  218.                     . '<td style="background-color:' . self::$colMethodNotDocumented '">'
  219.                     . $strNotDocced '</td>'
  220.                     . '<td>' ($nMethods $nMethodsDocced'</td></tr>' $n;
  221.             }
  222.  
  223.             if ($nMethods == $nMethodsDocced{
  224.                 $strState 'perfect (' $nMethodsDocced ')';
  225.                 $col = self::$colMethodDocumented;
  226.             else if ($nMethodsDocced == 0{
  227.                 $strState 'poor (' $nMethods ')';
  228.                 $col = self::$colMethodNotDocumented;
  229.             else {
  230.                 $strState 'partly';
  231.                 $col = self::$colMethodPartlyDocumented;
  232.             }
  233.  
  234.             $out .= '<tr><td></td>'
  235.                 . '<td class="class">' $strClass '</td>'
  236.                 . '<td style="background-color:' $col '">' $strState '</td></tr>' $n;
  237.             $out .= $mout;
  238.         }
  239.  
  240.         return $out;
  241.     }//public static function getMethodDocState($arPackageCoverage)
  242.  
  243. }//class QA_Peardoc_Coverage_Renderer_ExtendetPackageList
  244. ?>

Documentation generated on Mon, 11 Mar 2019 15:10:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.