PHPMD\TextUI\Command::main PHP Method

main() public static method

The main method that can be used by a calling shell script, the return value can be used as exit code.
public static main ( array $args ) : integer
$args array The raw command line arguments array.
return integer
    public static function main(array $args)
    {
        try {
            $ruleSetFactory = new RuleSetFactory();
            $options = new CommandLineOptions($args, $ruleSetFactory->listAvailableRuleSets());
            $command = new Command();
            $exitCode = $command->run($options, $ruleSetFactory);
        } catch (\Exception $e) {
            fwrite(STDERR, $e->getMessage());
            fwrite(STDERR, PHP_EOL);
            $exitCode = self::EXIT_EXCEPTION;
        }
        return $exitCode;
    }

Usage Example

 /**
  * testReportContainsCouplingBetweenObjectsWarning
  *
  * @return void
  * @outputBuffering enabled
  */
 public function testReportContainsCouplingBetweenObjectsWarning()
 {
     $file = self::createTempFileUri();
     Command::main(array(__FILE__, $this->createCodeResourceUriForTest(), 'text', 'design', '--reportfile', $file));
     self::assertContains('has a coupling between objects value of 14. ' . 'Consider to reduce the number of dependencies under 13.', file_get_contents($file));
 }
All Usage Examples Of PHPMD\TextUI\Command::main