/**
  * Run a full system test based on phpcs output.
  *
  * @return void
  */
 public function test__main()
 {
     $controller = new CbCLIController(null, array(PHPCB_SOURCE), PHPCB_TEST_OUTPUT, array(), array(), array(), new CbIOHelper(), Log::singleton('null'), array('php'));
     $controller->addErrorPlugins(array('CbErrorCheckstyle', 'CbErrorPMD', 'CbErrorCPD', 'CbErrorPadawan', 'CbErrorCoverage', 'CbErrorCRAP'));
     $controller->run();
     $this->assertFileExists(PHPCB_TEST_OUTPUT . '/index.html');
     $this->assertFileExists(PHPCB_TEST_OUTPUT . '/CLIController.php.html');
     $this->assertFileExists(PHPCB_TEST_OUTPUT . '/css');
 }
    /**
     * Main method called by script
     *
     * @return void
     */
    public static function main()
    {
        $parser = self::createCommandLineParser();
        try {
            $opts = $parser->parse()->options;
        } catch (Exception $e) {
            $parser->displayError($e->getMessage());
        }
        $errors = self::errorsForOpts($opts);
        if ($errors) {
            foreach ($errors as $e) {
                error_log("[Error] {$e}\n");
            }
            exit(1);
        }
        // Convert the --ignore arguments to patterns
        if (null !== $opts['ignore']) {
            $dirSep = preg_quote(DIRECTORY_SEPARATOR, '/');
            foreach (explode(',', $opts['ignore']) as $ignore) {
                $ig = realpath($ignore);
                if (!$ig) {
                    error_log("[Warning] {$ignore} does not exists");
                } else {
                    $ig = preg_quote($ig, '/');
                    $opts['excludePCRE'][] = "/^{$ig}({$dirSep}|\$)/";
                }
            }
        }
        // init new CLIController
        $controller = new CbCLIController($opts['log'], $opts['source'] ? $opts['source'] : array(), $opts['output'], $opts['excludePCRE'] ? $opts['excludePCRE'] : array(), $opts['excludePattern'] ? $opts['excludePattern'] : array(), $opts['crapThreshold'] ? array('CRAP' => array('threshold' => $opts['crapThreshold'])) : array(), new CbIOHelper(), $opts['debugExcludes'] ? Log::factory('console', '', 'PHPCB') : Log::factory('null'), $opts['phpSuffixes'] ? explode(',', $opts['phpSuffixes']) : array('php'), $opts['excludeOK'] ? $opts['excludeOK'] : false);
        $plugins = self::getAvailablePlugins();
        if ($opts['disablePlugin']) {
            foreach ($opts['disablePlugin'] as $idx => $val) {
                $opts['disablePlugin'][$idx] = strtolower($val);
            }
            foreach ($plugins as $pluginKey => $plugin) {
                $name = substr($plugin, strlen('CbError'));
                if (in_array(strtolower($name), $opts['disablePlugin'])) {
                    // Remove it from the plugins list
                    unset($plugins[$pluginKey]);
                }
            }
        }
        $controller->addErrorPlugins($plugins);
        try {
            $controller->run();
        } catch (Exception $e) {
            error_log(<<<HERE
[Error] {$e->getMessage()}

{$e->getTraceAsString()}
HERE
);
        }
    }
Example #3
0
    /**
     * Main method called by script
     *
     * @return void
     */
    public static function main()
    {
        // register autoloader
        spl_autoload_register(array(new CbAutoloader(), 'autoload'));
        $parser = self::createCommandLineParser();
        try {
            $opts = $parser->parse()->options;
        } catch (Exception $e) {
            $parser->displayError($e->getMessage());
        }
        $errors = self::errorsForOpts($opts);
        if ($errors) {
            foreach ($errors as $e) {
                error_log("[Error] {$e}\n");
            }
            exit(1);
        }
        // init new CLIController
        $controller = new CbCLIController($opts['log'], isset($opts['source']) ? $opts['source'] : array(), $opts['output'], isset($opts['excludePCRE']) ? $opts['excludePCRE'] : array(), isset($opts['excludePattern']) ? $opts['excludePattern'] : array(), new CbIOHelper());
        $controller->addErrorPlugins(array('CbErrorCheckstyle', 'CbErrorPMD', 'CbErrorCPD', 'CbErrorPadawan', 'CbErrorCoverage', 'CbErrorCRAP'));
        try {
            $controller->run();
        } catch (Exception $e) {
            error_log(<<<HERE
[Error] {$e->getMessage()}

{$e->getTraceAsString()}
HERE
);
        }
    }
 /**
  * Main method called by script
  *
  * @return void
  */
 public static function main()
 {
     $xmlLogDir = null;
     $sourceFolder = null;
     $htmlOutput = null;
     $xmlFileName = 'cbCodeBrowser.xml';
     // register autoloader
     spl_autoload_register(array(new CbAutoloader(), 'autoload'));
     $argv = $_SERVER['argv'];
     foreach ($argv as $key => $argument) {
         switch ($argument) {
             case '--log':
                 $xmlLogDir = $argv[$key + 1];
                 break;
             case '--source':
                 $sourceFolder = isset($argv[$key + 1]) ? $argv[$key + 1] : NULL;
                 break;
             case '--output':
                 $htmlOutput = $argv[$key + 1];
                 break;
             case '--help':
             case '-h':
                 self::printHelp();
                 break;
             case '--version':
                 self::printVersion();
                 break;
         }
     }
     // Check for directories
     if (!is_dir($xmlLogDir) || !is_dir($htmlOutput) || isset($sourceFolder) && !is_dir($sourceFolder)) {
         printf("Error: \n%s%s%s\n", !is_dir($xmlLogDir) ? "- xml log directory [{$xmlLogDir}] not found\n" : '', isset($sourceFolder) && !is_dir($sourceFolder) ? "- project source directory [{$sourceFolder}] not found\n" : '', !is_dir($htmlOutput) ? "- output directory [{$htmlOutput}] not found\n" : '');
         self::printHelp();
     }
     printf("Generating PHP_CodeBrowser files\n");
     // init new CLIController
     $controller = new CbCLIController($xmlLogDir, $sourceFolder, $htmlOutput, $htmlOutput . '/' . $xmlFileName);
     $controller->addErrorPlugins(array('CbErrorCheckstyle', 'CbErrorPMD', 'CbErrorCPD', 'CbErrorPadawan'));
     try {
         $controller->run();
     } catch (Exception $e) {
         printf("PHP-CodeBrowser Error: \n%s\n", $e->getMessage());
     }
     print "\n" . PHP_Timer::resourceUsage() . "\n";
 }