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

Source for file ExactMatch.php

Documentation is available at ExactMatch.php

  1. <?php
  2. /**
  3.  * An abstract filter class for checking files and folders against exact matches.
  4.  *
  5.  * Supports both whitelists and blacklists.
  6.  *
  7.  * @author    Greg Sherwood <gsherwood@squiz.net>
  8.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  9.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  10.  */
  11.  
  12. namespace PHP_CodeSniffer\Filters;
  13.  
  14. use PHP_CodeSniffer\Util;
  15.  
  16. abstract class ExactMatch extends Filter
  17. {
  18.  
  19.     /**
  20.      * A list of files to exclude.
  21.      *
  22.      * @var array 
  23.      */
  24.     private $blacklist = null;
  25.  
  26.     /**
  27.      * A list of files to include.
  28.      *
  29.      * If the whitelist is empty, only files in the blacklist will be excluded.
  30.      *
  31.      * @var array 
  32.      */
  33.     private $whitelist = null;
  34.  
  35.  
  36.     /**
  37.      * Check whether the current element of the iterator is acceptable.
  38.      *
  39.      * If a file is both blacklisted and whitelisted, it will be deemed unacceptable.
  40.      *
  41.      * @return bool 
  42.      */
  43.     public function accept()
  44.     {
  45.         if (parent::accept(=== false{
  46.             return false;
  47.         }
  48.  
  49.         if ($this->blacklist === null{
  50.             $this->blacklist $this->getblacklist();
  51.         }
  52.  
  53.         if ($this->whitelist === null{
  54.             $this->whitelist $this->getwhitelist();
  55.         }
  56.  
  57.         $filePath = Util\Common::realpath($this->current());
  58.  
  59.         // If file is both blacklisted and whitelisted, the blacklist takes precedence.
  60.         if (isset($this->blacklist[$filePath]=== true{
  61.             return false;
  62.         }
  63.  
  64.         if (empty($this->whitelist=== true && empty($this->blacklist=== false{
  65.             // We are only checking a blacklist, so everything else should be whitelisted.
  66.             return true;
  67.         }
  68.  
  69.         return isset($this->whitelist[$filePath]);
  70.  
  71.     }//end accept()
  72.  
  73.  
  74.     /**
  75.      * Returns an iterator for the current entry.
  76.      *
  77.      * Ensures that the blacklist and whitelist are preserved so they don't have
  78.      * to be generated each time.
  79.      *
  80.      * @return \RecursiveIterator 
  81.      */
  82.     public function getChildren()
  83.     {
  84.         $children            = parent::getChildren();
  85.         $children->blacklist = $this->blacklist;
  86.         $children->whitelist = $this->whitelist;
  87.         return $children;
  88.  
  89.     }//end getChildren()
  90.  
  91.  
  92.     /**
  93.      * Get a list of blacklisted file paths.
  94.      *
  95.      * @return array 
  96.      */
  97.     abstract protected function getBlacklist();
  98.  
  99.  
  100.     /**
  101.      * Get a list of whitelisted file paths.
  102.      *
  103.      * @return array 
  104.      */
  105.     abstract protected function getWhitelist();
  106.  
  107.  
  108. }//end class

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