Esempio n. 1
0
 /**
  * This method creates a PHP_PMD instance and configures this object based
  * on the user's input, then it starts the source analysis.
  *
  * The return value of this method can be used as an exit code. A value
  * equal to <b>EXIT_SUCCESS</b> means that no violations or errors were
  * found in the analyzed code. Otherwise this method will return a value
  * equal to <b>EXIT_VIOLATION</b>.
  *
  * @param PHP_PMD_TextUI_CommandLineOptions $opts The prepared command line
  *                                                arguments.
  *
  * @return integer
  */
 public function run(PHP_PMD_TextUI_CommandLineOptions $opts)
 {
     if ($opts->hasVersion()) {
         fwrite(STDOUT, 'PHPMD @package_version@ by Manuel Pichler' . PHP_EOL);
         return self::EXIT_SUCCESS;
     }
     // Create a report stream
     if ($opts->getReportFile() === null) {
         $stream = STDOUT;
     } else {
         $stream = fopen($opts->getReportFile(), 'wb');
     }
     // Create renderer and configure output
     $renderer = $opts->createRenderer();
     $renderer->setWriter(new PHP_PMD_Writer_Stream($stream));
     // Create a rule set factory
     $ruleSetFactory = new PHP_PMD_RuleSetFactory();
     $ruleSetFactory->setMinimumPriority($opts->getMinimumPriority());
     $phpmd = new PHP_PMD();
     $extensions = $opts->getExtensions();
     if ($extensions !== null) {
         $phpmd->setFileExtensions(explode(',', $extensions));
     }
     $ignore = $opts->getIgnore();
     if ($ignore !== null) {
         $phpmd->setIgnorePattern(explode(',', $ignore));
     }
     $phpmd->processFiles($opts->getInputPath(), $opts->getRuleSets(), array($renderer), $ruleSetFactory);
     if ($phpmd->hasViolations()) {
         return self::EXIT_VIOLATION;
     }
     return self::EXIT_SUCCESS;
 }
 /**
  * testCliOptionsAcceptsStrictArgument
  * 
  * @return void
  * @since 1.2.0
  */
 public function testCliOptionsAcceptsStrictArgument()
 {
     $args = array(__FILE__, '--strict', __FILE__, 'text', 'codesize');
     $opts = new PHP_PMD_TextUI_CommandLineOptions($args);
     self::assertTrue($opts->hasStrict());
 }
Esempio n. 3
0
 /**
  * testCliOptionsAcceptsVersionArgument
  *
  * @return void
  * @covers PHP_PMD_TextUI_CommandLineOptions
  * @group phpmd
  * @group phpmd::textui
  * @group unittest
  */
 public function testCliOptionsAcceptsVersionArgument()
 {
     $args = array(__FILE__, '--version');
     $opts = new PHP_PMD_TextUI_CommandLineOptions($args);
     $this->assertTrue($opts->hasVersion());
 }