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

Source for file Generator.php

Documentation is available at Generator.php

  1. <?php
  2. /**
  3.  * The base class for all PHP_CodeSniffer documentation generators.
  4.  *
  5.  * Documentation generators are used to print documentation about code sniffs
  6.  * in a standard.
  7.  *
  8.  * @author    Greg Sherwood <gsherwood@squiz.net>
  9.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  10.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  11.  */
  12.  
  13. namespace PHP_CodeSniffer\Generators;
  14.  
  15. use PHP_CodeSniffer\Ruleset;
  16. use PHP_CodeSniffer\Autoload;
  17. use PHP_CodeSniffer\Util\Common;
  18.  
  19. abstract class Generator
  20. {
  21.  
  22.     /**
  23.      * The ruleset used for the run.
  24.      *
  25.      * @var \PHP_CodeSniffer\Ruleset 
  26.      */
  27.     public $ruleset = null;
  28.  
  29.     /**
  30.      * XML documentation files used to produce the final output.
  31.      *
  32.      * @var string[] 
  33.      */
  34.     public $docFiles = array();
  35.  
  36.  
  37.     /**
  38.      * Constructs a doc generator.
  39.      *
  40.      * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
  41.      *
  42.      * @see generate()
  43.      */
  44.     public function __construct(Ruleset $ruleset)
  45.     {
  46.         $this->ruleset $ruleset;
  47.  
  48.         $standardFiles = array();
  49.         foreach ($ruleset->sniffs as $className => $sniffClass{
  50.             $file    = Autoload::getLoadedFileName($className);
  51.             $docFile str_replace(
  52.                 DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR,
  53.                 DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR,
  54.                 $file
  55.             );
  56.             $docFile str_replace('Sniff.php''Standard.xml'$docFile);
  57.  
  58.             if (is_file($docFile=== true{
  59.                 $this->docFiles[$docFile;
  60.             }
  61.         }
  62.  
  63.     }//end __construct()
  64.  
  65.  
  66.     /**
  67.      * Retrieves the title of the sniff from the DOMNode supplied.
  68.      *
  69.      * @param \DOMNode $doc The DOMNode object for the sniff.
  70.      *                       It represents the "documentation" tag in the XML
  71.      *                       standard file.
  72.      *
  73.      * @return string 
  74.      */
  75.     protected function getTitle(\DOMNode $doc)
  76.     {
  77.         return $doc->getAttribute('title');
  78.  
  79.     }//end getTitle()
  80.  
  81.  
  82.     /**
  83.      * Generates the documentation for a standard.
  84.      *
  85.      * It's probably wise for doc generators to override this method so they
  86.      * have control over how the docs are produced. Otherwise, the processSniff
  87.      * method should be overridden to output content for each sniff.
  88.      *
  89.      * @return void 
  90.      * @see    processSniff()
  91.      */
  92.     public function generate()
  93.     {
  94.         foreach ($this->docFiles as $file{
  95.             $doc = new \DOMDocument();
  96.             $doc->load($file);
  97.             $documentation $doc->getElementsByTagName('documentation')->item(0);
  98.             $this->processSniff($documentation);
  99.         }
  100.  
  101.     }//end generate()
  102.  
  103.  
  104.     /**
  105.      * Process the documentation for a single sniff.
  106.      *
  107.      * Doc generators must implement this function to produce output.
  108.      *
  109.      * @param \DOMNode $doc The DOMNode object for the sniff.
  110.      *                       It represents the "documentation" tag in the XML
  111.      *                       standard file.
  112.      *
  113.      * @return void 
  114.      * @see    generate()
  115.      */
  116.     abstract protected function processSniff(\DOMNode $doc);
  117.  
  118.  
  119. }//end class

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