Changeset 168d505


Ignore:
Timestamp:
12/21/11 20:50:14 (5 months ago)
Author:
mrook
Branches:
master
Children:
3fc5fa8
Parents:
ddec066
git-author:
Michiel Rook <mrook@…> (12/21/11 20:50:14)
git-committer:
Michiel Rook <mrook@…> (12/21/11 20:50:14)
Message:

Refs #837 - move PMD dependency to main() method

Location:
classes/phing/tasks/ext/phpmd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • classes/phing/tasks/ext/phpmd/PHPMDFormatterElement.php

    r17e42b0 r168d505  
    2121 
    2222require_once 'phing/system/io/PhingFile.php'; 
    23 require_once 'PHP/PMD/Writer/Stream.php'; 
    2423 
    2524/** 
     
    174173        } 
    175174 
     175        require_once 'PHP/PMD/Writer/Stream.php'; 
     176         
    176177        $renderer->setWriter(new PHP_PMD_Writer_Stream($stream)); 
    177178 
  • classes/phing/tasks/ext/phpmd/PHPMDTask.php

    rddec066 r168d505  
    2121 
    2222require_once 'phing/Task.php'; 
     23require_once 'phing/tasks/ext/phpmd/PHPMDFormatterElement.php'; 
    2324 
    2425/** 
     
    5960     * @var integer 
    6061     */ 
    61     protected $minimumPriority = 5; 
     62    protected $minimumPriority = 0; 
    6263 
    6364    /** 
     
    9091 
    9192    /** 
    92      * Load the necessary environment for running PHPMD. 
     93     * Set the input source file or directory. 
     94     * 
     95     * @param PhingFile $file The input source file or directory. 
     96     * 
     97     * @return void 
     98     */ 
     99    public function setFile(PhingFile $file) 
     100    { 
     101        $this->file = $file; 
     102    } 
     103 
     104    /** 
     105     * Nested creator, adds a set of files (nested fileset attribute). 
     106     * 
     107     * @return FileSet The created fileset object 
     108     */ 
     109    public function createFileSet() 
     110    { 
     111        $num = array_push($this->filesets, new FileSet()); 
     112        return $this->filesets[$num-1]; 
     113    } 
     114 
     115    /** 
     116     * Sets the minimum rule priority. 
     117     * 
     118     * @param integer $minimumPriority Minimum rule priority. 
     119     * 
     120     * @return void 
     121     */ 
     122    public function setMinimumPriority($minimumPriority) 
     123    { 
     124        $this->minimumPriority = $minimumPriority; 
     125    } 
     126 
     127    /** 
     128     * Sets the rule-sets. 
     129     * 
     130     * @param string $ruleSetFileNames Comma-separated string of rule-set filenames 
     131     *                                 or identifier. 
     132     * 
     133     * @return void 
     134     */ 
     135    public function setRulesets($ruleSetFileNames) 
     136    { 
     137        $this->rulesets = $ruleSetFileNames; 
     138    } 
     139 
     140    /** 
     141     * Sets a list of filename extensions for valid php source code files. 
     142     * 
     143     * @param string $fileExtensions List of valid file extensions without leading dot. 
     144     * 
     145     * @return void 
     146     */ 
     147    public function setAllowedFileExtensions($fileExtensions) 
     148    { 
     149        $this->allowedFileExtensions = array(); 
     150 
     151        $token = ' ,;'; 
     152        $ext   = strtok($fileExtensions, $token); 
     153 
     154        while ($ext !== false) { 
     155            $this->allowedFileExtensions[] = $ext; 
     156            $ext = strtok($token); 
     157        } 
     158    } 
     159 
     160    /** 
     161     * Sets a list of ignore patterns that is used to exclude directories from 
     162     * the source analysis. 
     163     * 
     164     * @param string $ignorePatterns List of ignore patterns. 
     165     * 
     166     * @return void 
     167     */ 
     168    public function setIgnorePatterns($ignorePatterns) 
     169    { 
     170        $this->ignorePatterns = array(); 
     171 
     172        $token   = ' ,;'; 
     173        $pattern = strtok($ignorePatterns, $token); 
     174 
     175        while ($pattern !== false) { 
     176            $this->ignorePatterns[] = $pattern; 
     177            $pattern = strtok($token); 
     178        } 
     179    } 
     180 
     181    /** 
     182     * Create object for nested formatter element. 
     183     * 
     184     * @return PHPMDFormatterElement 
     185     */ 
     186    public function createFormatter() 
     187    { 
     188        $num = array_push($this->formatters, new PHPMDFormatterElement()); 
     189        return $this->formatters[$num-1]; 
     190    } 
     191 
     192    /** 
     193     * Executes PHPMD against PhingFile or a FileSet 
    93194     * 
    94195     * @throws BuildException - if the phpmd classes can't be loaded. 
    95      */ 
    96     public function init() 
     196     * @return void 
     197     */ 
     198    public function main() 
    97199    { 
    98200        /** 
    99          * Determine PHPMD version number 
     201         * Find PHPMD 
    100202         */ 
    101203        @include_once 'PHP/PMD.php'; 
     
    107209            ); 
    108210        } 
    109  
    110         /*$version = PHP_PMD::VERSION; 
    111  
    112         if (version_compare($version, '0.2.1') < 0) { 
    113             throw new BuildException( 
    114                 "PHPMDTask requires PHPMD version >= 0.2.1", 
    115                 $this->getLocation() 
    116             ); 
    117         }*/ 
    118  
    119         /** 
    120          * Other dependencies that should only be loaded when class is actually used. 
    121          */ 
    122         require_once 'phing/tasks/ext/phpmd/PHPMDFormatterElement.php'; 
     211         
    123212        require_once 'PHP/PMD/AbstractRule.php'; 
    124213 
    125         $this->minimumPriority = PHP_PMD_AbstractRule::LOWEST_PRIORITY; 
    126     } 
    127  
    128     /** 
    129      * Set the input source file or directory. 
    130      * 
    131      * @param PhingFile $file The input source file or directory. 
    132      * 
    133      * @return void 
    134      */ 
    135     public function setFile(PhingFile $file) 
    136     { 
    137         $this->file = $file; 
    138     } 
    139  
    140     /** 
    141      * Nested creator, adds a set of files (nested fileset attribute). 
    142      * 
    143      * @return FileSet The created fileset object 
    144      */ 
    145     public function createFileSet() 
    146     { 
    147         $num = array_push($this->filesets, new FileSet()); 
    148         return $this->filesets[$num-1]; 
    149     } 
    150  
    151     /** 
    152      * Sets the minimum rule priority. 
    153      * 
    154      * @param integer $minimumPriority Minimum rule priority. 
    155      * 
    156      * @return void 
    157      */ 
    158     public function setMinimumPriority($minimumPriority) 
    159     { 
    160         $this->minimumPriority = $minimumPriority; 
    161     } 
    162  
    163     /** 
    164      * Sets the rule-sets. 
    165      * 
    166      * @param string $ruleSetFileNames Comma-separated string of rule-set filenames 
    167      *                                 or identifier. 
    168      * 
    169      * @return void 
    170      */ 
    171     public function setRulesets($ruleSetFileNames) 
    172     { 
    173         $this->rulesets = $ruleSetFileNames; 
    174     } 
    175  
    176     /** 
    177      * Sets a list of filename extensions for valid php source code files. 
    178      * 
    179      * @param string $fileExtensions List of valid file extensions without leading dot. 
    180      * 
    181      * @return void 
    182      */ 
    183     public function setAllowedFileExtensions($fileExtensions) 
    184     { 
    185         $this->allowedFileExtensions = array(); 
    186  
    187         $token = ' ,;'; 
    188         $ext   = strtok($fileExtensions, $token); 
    189  
    190         while ($ext !== false) { 
    191             $this->allowedFileExtensions[] = $ext; 
    192             $ext = strtok($token); 
    193         } 
    194     } 
    195  
    196     /** 
    197      * Sets a list of ignore patterns that is used to exclude directories from 
    198      * the source analysis. 
    199      * 
    200      * @param string $ignorePatterns List of ignore patterns. 
    201      * 
    202      * @return void 
    203      */ 
    204     public function setIgnorePatterns($ignorePatterns) 
    205     { 
    206         $this->ignorePatterns = array(); 
    207  
    208         $token   = ' ,;'; 
    209         $pattern = strtok($ignorePatterns, $token); 
    210  
    211         while ($pattern !== false) { 
    212             $this->ignorePatterns[] = $pattern; 
    213             $pattern = strtok($token); 
    214         } 
    215     } 
    216  
    217     /** 
    218      * Create object for nested formatter element. 
    219      * 
    220      * @return PHPMDFormatterElement 
    221      */ 
    222     public function createFormatter() 
    223     { 
    224         $num = array_push($this->formatters, new PHPMDFormatterElement()); 
    225         return $this->formatters[$num-1]; 
    226     } 
    227  
    228     /** 
    229      * Executes PHPMD against PhingFile or a FileSet 
    230      * 
    231      * @return void 
    232      */ 
    233     public function main() 
    234     { 
     214        if (!$this->minimumPriority) { 
     215            $this->minimumPriority = PHP_PMD_AbstractRule::LOWEST_PRIORITY; 
     216        } 
     217         
    235218        if (!isset($this->file) and count($this->filesets) == 0) { 
    236219            throw new BuildException("Missing either a nested fileset or attribute 'file' set"); 
Note: See TracChangeset for help on using the changeset viewer.