/** * 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); }
/** * 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)); }
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));
/** * 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'])); }