/** * Run tool for files specified * * @param array $whiteList Files/directories to be inspected * @param array $blackList Files/directories to be excluded from the inspection * @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'... * * @return int */ public function run(array $whiteList, array $blackList = array(), array $extensions = array()) { $commandLineArguments = array('run_file_mock', implode(',', $whiteList), 'xml', $this->_rulesetFile, '--exclude', str_replace('/', DIRECTORY_SEPARATOR, implode(',', $blackList)), '--reportfile', $this->_reportFile); $options = new PHP_PMD_TextUI_CommandLineOptions($commandLineArguments); $command = new PHP_PMD_TextUI_Command(); return $command->run($options); }
/** * Run tool for files specified * * @param array $whiteList Files/directories to be inspected * @param array $blackList Files/directories to be excluded from the inspection * @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'... * * @return int */ public function run(array $whiteList, array $blackList = array(), array $extensions = array()) { $commandLineArguments = array('run_file_mock', implode(',', $whiteList), 'xml', $this->_rulesetFile, '--exclude', implode(',', $blackList), '--reportfile', $this->_reportFile); $options = new \PHP_PMD_TextUI_CommandLineOptions($commandLineArguments); $command = new \PHP_PMD_TextUI_Command(); return $command->run($options, new \PHP_PMD_RuleSetFactory()); }
/** * (non-PHPdoc) * @see MageUC_Console_Task::execute() */ public function execute() { print '[phpmd] Lancement de PHPMD : ' . $this->getArgument('to_check') . PHP_EOL; $options = new PHP_PMD_TextUI_CommandLineOptions($this->_getOptions()); $command = new PHP_PMD_TextUI_Command(); $command->run($options); print '[phpmd] done' . PHP_EOL; }
/** * testReportContainsGotoStatementWarning * * @return void * @outputBuffering enabled */ public function testReportContainsGotoStatementWarning() { $file = self::createTempFileUri(); PHP_PMD_TextUI_Command::main(array(__FILE__, $this->createCodeResourceUriForTest(), 'text', 'design', '--reportfile', $file)); self::assertContains('utilizes a goto statement.', file_get_contents($file)); }
/** * Runs the PHPMD command line interface and returns the report content. * * @return string */ protected static function runCommandLine() { $inputfile = self::createResourceUriForTest('inputfile.txt'); $reportfile = self::createTempFileUri(); self::changeWorkingDirectory(dirname($inputfile)); var_dump(getcwd()); PHP_PMD_TextUI_Command::main(array(__FILE__, 'text', 'unusedcode', '--reportfile', $reportfile, '--inputfile', $inputfile)); return file_get_contents($reportfile); }
set_include_path(dirname(__FILE__) . '/../main/php' . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib/pdepend/src/main/php' . PATH_SEPARATOR . '.'); } } // Allow as much memory as possible by default if (extension_loaded('suhosin') && is_numeric(ini_get('suhosin.memory_limit'))) { $limit = ini_get('memory_limit'); if (preg_match('(^(\\d+)([BKMGT]))', $limit, $match)) { $shift = array('B' => 0, 'K' => 10, 'M' => 20, 'G' => 30, 'T' => 40); $limit = $match[1] * (1 << $shift[$match[2]]); } if (ini_get('suhosin.memory_limit') > $limit && $limit > -1) { ini_set('memory_limit', ini_get('suhosin.memory_limit')); } } else { ini_set('memory_limit', -1); } // Check php setup for cli arguments if (!isset($_SERVER['argv']) && !isset($argv)) { fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini', PHP_EOL); exit(1); } else { if (!isset($argv)) { $argv = $_SERVER['argv']; } } set_include_path(__DIR__); // Load command line utility require_once 'PHP/PMD/TextUI/Command.php'; // Run command line interface exit(PHP_PMD_TextUI_Command::main($argv));
/** * The main method that can be used by a calling shell script, the return * value can be used as exit code. * * @param array $args The raw command line arguments array. * * @return integer */ public static function main(array $args) { try { $options = new PHP_PMD_TextUI_CommandLineOptions($args); $command = new PHP_PMD_TextUI_Command(); $exitCode = $command->run($options); } catch (Exception $e) { fwrite(STDERR, $e->getMessage()); fwrite(STDERR, PHP_EOL); $exitCode = self::EXIT_EXCEPTION; } return $exitCode; }
/** * The main method that can be used by a calling shell script, the return * value can be used as exit code. * * @param array $args The raw command line arguments array. * * @return integer */ public static function main(array $args) { try { $ruleSetFactory = new PHP_PMD_RuleSetFactory(); $options = new PHP_PMD_TextUI_CommandLineOptions($args, $ruleSetFactory->listAvailableRuleSets()); $command = new PHP_PMD_TextUI_Command(); $exitCode = $command->run($options, $ruleSetFactory); } catch (Exception $e) { fwrite(STDERR, $e->getMessage()); fwrite(STDERR, PHP_EOL); $exitCode = self::EXIT_EXCEPTION; } return $exitCode; }
/** * testMainReturnsViolationExitCodeForSourceWithNPathViolation * * @return void * @covers PHP_PMD_TextUI_Command * @group phpmd * @group phpmd::textui * @group unittest */ public function testMainReturnsViolationExitCodeForSourceWithNPathViolation() { $exitCode = PHP_PMD_TextUI_Command::main(array(__FILE__, self::createFileUri('source/source_with_npath_violation.php'), 'text', 'codesize', '--reportfile', sys_get_temp_dir() . '/phpmd.txt')); $this->assertEquals(PHP_PMD_TextUI_Command::EXIT_VIOLATION, $exitCode); }
/** * testReportContainsCouplingBetweenObjectsWarning * * @return void * @outputBuffering enabled */ public function testReportContainsCouplingBetweenObjectsWarning() { $file = self::createTempFileUri(); PHP_PMD_TextUI_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)); }
* */ error_reporting(0); chdir('/Applications/MAMP/bin/php/php5.3.6/share/pear/'); $values[0] = '/usr/bin/phpmd'; //path to pmd //tmp report file $values[1] = '--reportfile'; $values[2] = '/tmp/mess.html'; //current file being edited $values[3] = getenv('CODA_FILEPATH'); //report format: text,xml,html $values[4] = 'html'; //rulesets: codesize,unusedcode,naming,design //or path to custom ruleset $values[5] = 'codesize,unusedcode,naming,design'; //END OF USER CONFIGURABLE OPTIONS/// $path = 'PHP/PMD/TextUI/Command.php'; if (!file_exists($path)) { echo 'File not found: ' . $path . '. Pear must be in your path. If not you need to set the correct path to Pear\'s PMD. ' . 'Included paths: ' . get_include_path() . '. Change it in this file: ' . __FILE__; die; } require_once $path; // Run command line interface $error = PHP_PMD_TextUI_Command::main($values); if ($error) { echo file_get_contents($values[2]); } else { echo 'PMD says Ok! :)'; }
/** * Mess detector * * @return void */ public function phpmd() { if (!empty($this->params['version'])) { //return passthru('php '.VENDORS."PHP".DS."scripts".DS.'phpmd --help'); } // Allow as much memory as possible by default if (extension_loaded('suhosin') && is_numeric(ini_get('suhosin.memory_limit'))) { $limit = ini_get('memory_limit'); if (preg_match('(^(\\d+)([BKMGT]))', $limit, $match)) { $shift = ['B' => 0, 'K' => 10, 'M' => 20, 'G' => 30, 'T' => 40]; $limit = $match[1] * (1 << $shift[$match[2]]); } if (ini_get('suhosin.memory_limit') > $limit && $limit > -1) { ini_set('memory_limit', ini_get('suhosin.memory_limit')); } } else { ini_set('memory_limit', -1); } // Check php setup for cli arguments if (!isset($_SERVER['argv']) && !isset($argv)) { fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini', PHP_EOL); exit(1); } $_SERVER['argv'] = []; $_SERVER['argv'][] = 'phpcs'; $_SERVER['argv'][] = VENDORS . 'PHP' . DS; $_SERVER['argv'][] = 'xml'; $_SERVER['argv'][] = 'codesize'; //$_SERVER['argv'][] = '--error-severity=1'; //$_SERVER['argv'][] = '--warning-severity=1'; //$_SERVER['argv'][] = '--config-show'; $_SERVER['argc'] = count($_SERVER['argv']); // Load command line utility require_once 'PHP/PMD/TextUI/Command.php'; // Run command line interface exit(PHP_PMD_TextUI_Command::main($_SERVER['argv'])); }