classes/phing/tasks/ext/phpmd/PHPMDTask.php
public function main()
    {
        $className = $this->loadDependencies();

        if (!isset($this->file) and count($this->filesets) == 0) {
            throw new BuildException('Missing either a nested fileset or attribute "file" set');
        }

        if (count($this->formatters) == 0) {
            // turn legacy format attribute into formatter
            $fmt = new PHPMDFormatterElement();
            $fmt->setType($this->format);
            $fmt->setUseFile(false);

            $this->formatters[] = $fmt;
        }

        $reportRenderers = [];

        foreach ($this->formatters as $fe) {
            if ($fe->getType() == '') {
                throw new BuildException('Formatter missing required "type" attribute.');
            }

            if ($fe->getUsefile() && $fe->getOutfile() === null) {
                throw new BuildException('Formatter requires "outfile" attribute when "useFile" is true.');
            }

            $reportRenderers[] = $fe->getRenderer();
        }

        if ($this->newVersion && $this->cache) {
            $reportRenderers[] = new PHPMDRendererRemoveFromCache($this->cache);
        } else {
            $this->cache = null; // cache not compatible to old version
        }

        // Create a rule set factory
        if ($this->newVersion) {
            $ruleSetFactory = new \PHPMD\RuleSetFactory();
        } else {
            if (!class_exists("PHP_PMD_RuleSetFactory")) {
                @include 'PHP/PMD/RuleSetFactory.php';
            }
            $ruleSetFactory = new PHP_PMD_RuleSetFactory();
        }
        $ruleSetFactory->setMinimumPriority($this->minimumPriority);

        /**
         * @var PHPMD\PHPMD $phpmd
         */
        $phpmd = new $className();
        $phpmd->setFileExtensions($this->allowedFileExtensions);
        $phpmd->setIgnorePattern($this->ignorePatterns);

        $filesToParse = $this->getFilesToParse();

        if (count($filesToParse) > 0) {
            $inputPath = implode(',', $filesToParse);

            $this->log('Processing files...');

            $phpmd->processFiles($inputPath, $this->rulesets, $reportRenderers, $ruleSetFactory);

            if ($this->cache) {
                $this->cache->commit();
            }

            $this->log('Finished processing files');
        } else {
            $this->log('No files to process');
        }
    }
public function main()
    {
        $className = $this->loadDependencies();

        if (!isset($this->file) and count($this->filesets) == 0) {
            throw new BuildException('Missing either a nested fileset or attribute "file" set');
        }

        if (count($this->formatters) == 0) {
            // turn legacy format attribute into formatter
            $fmt = new PHPMDFormatterElement();
            $fmt->setType($this->format);
            $fmt->setUseFile(false);

            $this->formatters[] = $fmt;
        }

        $reportRenderers = [];

        foreach ($this->formatters as $fe) {
            if ($fe->getType() == '') {
                throw new BuildException('Formatter missing required "type" attribute.');
            }

            if ($fe->getUsefile() && $fe->getOutfile() === null) {
                throw new BuildException('Formatter requires "outfile" attribute when "useFile" is true.');
            }

            $reportRenderers[] = $fe->getRenderer();
        }

        if ($this->newVersion && $this->cache) {
            $reportRenderers[] = new PHPMDRendererRemoveFromCache($this->cache);
        } else {
            $this->cache = null; // cache not compatible to old version
        }

        // Create a rule set factory
        if ($this->newVersion) {
            $ruleSetFactory = new \PHPMD\RuleSetFactory();
        } else {
            if (!class_exists("PHP_PMD_RuleSetFactory")) {
                @include 'PHP/PMD/RuleSetFactory.php';
            }
            $ruleSetFactory = new PHP_PMD_RuleSetFactory();
        }
        $ruleSetFactory->setMinimumPriority($this->minimumPriority);

        /**
         * @var PHPMD\PHPMD $phpmd
         */
        $phpmd = new $className();
        $phpmd->setFileExtensions($this->allowedFileExtensions);
        $phpmd->setIgnorePattern($this->ignorePatterns);

        $filesToParse = $this->getFilesToParse();

        if (count($filesToParse) > 0) {
            $inputPath = implode(',', $filesToParse);

            $this->log('Processing files...');

            $phpmd->processFiles($inputPath, $this->rulesets, $reportRenderers, $ruleSetFactory);

            if ($this->cache) {
                $this->cache->commit();
            }

            $this->log('Finished processing files');
        } else {
            $this->log('No files to process');
        }
    }
public function main ( ) { $ className = $ this -> loadDependencies ( ) ; if ( ! isset ( $ this -> file ) and count ( $ this -> filesets ) == 0 ) { throw new BuildException ( 'Missing either a nested fileset or attribute "file" set' ) ; } if ( count ( $ this -> formatters ) == 0 ) { // turn legacy format attribute into formatter $ fmt = new PHPMDFormatterElement ( ) ; $ fmt -> setType ( $ this -> format ) ; $ fmt -> setUseFile ( false ) ; $ this -> formatters [ ] = $ fmt ; } $ reportRenderers = [ ] ; foreach ( $ this -> formatters as $ fe ) { if ( $ fe -> getType ( ) == '' ) { throw new BuildException ( 'Formatter missing required "type" attribute.' ) ; } if ( $ fe -> getUsefile ( ) && $ fe -> getOutfile ( ) === null ) { throw new BuildException ( 'Formatter requires "outfile" attribute when "useFile" is true.' ) ; } $ reportRenderers [ ] = $ fe -> getRenderer ( ) ; } if ( $ this -> newVersion && $ this -> cache ) { $ reportRenderers [ ] = new PHPMDRendererRemoveFromCache ( $ this -> cache ) ; } else { $ this -> cache = null ; // cache not compatible to old version } // Create a rule set factory if ( $ this -> newVersion ) { $ ruleSetFactory = new \ PHPMD \ RuleSetFactory ( ) ; } else { if ( ! class_exists ( "PHP_PMD_RuleSetFactory" ) ) { @ include 'PHP/PMD/RuleSetFactory.php' ; } $ ruleSetFactory = new PHP_PMD_RuleSetFactory ( ) ; } $ ruleSetFactory -> setMinimumPriority ( $ this -> minimumPriority ) ; /**
         * @var PHPMD\PHPMD $phpmd
         */ $ phpmd = new $ className ( ) ; $ phpmd -> setFileExtensions ( $ this -> allowedFileExtensions ) ; $ phpmd -> setIgnorePattern ( $ this -> ignorePatterns ) ; $ filesToParse = $ this -> getFilesToParse ( ) ; if ( count ( $ filesToParse ) > 0 ) { $ inputPath = implode ( ',' , $ filesToParse ) ; $ this -> log ( 'Processing files...' ) ; $ phpmd -> processFiles ( $ inputPath , $ this -> rulesets , $ reportRenderers , $ ruleSetFactory ) ; if ( $ this -> cache ) { $ this -> cache -> commit ( ) ; } $ this -> log ( 'Finished processing files' ) ; } else { $ this -> log ( 'No files to process' ) ; } }
Executes PHPMD against PhingFile or a FileSet

@throws BuildException - if the phpmd classes can't be loaded.
Executes PHPMD against PhingFile or a FileSet