public function run($args) { $project = FWS_Props::get()->project(); $options = new PC_Engine_Options(); $options->set_report_unused(true); $options->set_report_argret_strictly($project->get_report_argret_strictly()); $options->add_project($project->get_id()); foreach ($project->get_project_deps() as $pid) { $options->add_project($pid); } foreach ($project->get_req() as $r) { if ($r['type'] == 'min') { $options->add_min_req($r['name'], $r['version']); } else { $options->add_max_req($r['name'], $r['version']); } } $env = new PC_Engine_Env($options); $ascanner = new PC_Engine_StmtScannerFrontend($env); $msgs = array(); foreach ($args as $file) { try { $ascanner->scan_file($file); } catch (PC_Engine_Exception $e) { $msgs[] = $e->__toString(); } } if (count($env->get_types()->get_calls())) { PC_DAO::get_calls()->create_bulk($env->get_types()->get_calls()); } foreach ($env->get_errors()->get() as $err) { PC_DAO::get_errors()->create($err); } foreach ($ascanner->get_vars() as $vars) { foreach ($vars as $var) { PC_DAO::get_vars()->create($var); } } // write messages to shared data $mutex = new FWS_MutexFile(PC_CLI_MUTEX_FILE); $mutex->aquire(); $data = unserialize($mutex->read()); /* @var $data PC_JobData */ $data->add_errors($msgs); $mutex->write(serialize($data)); $mutex->close(); }
public function test_unused() { $code = '<?php $a = 1; $b = 2; $c = 3; $d = 4; $e = 5; $f = 1; $g = 1; $h = 1; $i = "foo bar $f test $g{5} $_{$h}"; $b += 1; $c = $c + 2; ++$d; $e++; /** * @param int $p1 * @param int $p2 * @return int */ function test($p1,$p2) { $p1 = 1; $a = 0; $b = 1; return $a + $p2; } class A { /** @var int */ private $foo; /** * @param int $a * @return int */ public function test($a) { $this->foo++; return $x = $a; } } interface I { /** @param int $x */ public abstract function foo($x); } class C implements I { public function foo($x) { } } class B extends A { public function test($a) { return 1; } } if(preg_match("/foo/",$_,$m)) echo $m[0]; /** @param int &$a */ function myref(&$a) { $a = 1; } myref($n); echo $n; ?>'; $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $options->set_report_unused(true); $options->add_min_req('PHP', '5'); list(, , $vars, , $errors) = $this->analyze($code, $options); self::assert_equals(5, count($errors)); $error = $errors[0]; self::assert_equals(PC_Obj_Error::E_S_PARAM_UNUSED, $error->get_type()); self::assert_regex('/The parameter \\$p1 in #test# is unused/', $error->get_msg()); $error = $errors[1]; self::assert_equals(PC_Obj_Error::E_S_VAR_UNUSED, $error->get_type()); self::assert_regex('/The variable \\$b in #test# is unused/', $error->get_msg()); $error = $errors[2]; self::assert_equals(PC_Obj_Error::E_S_VAR_UNUSED, $error->get_type()); self::assert_regex('/The variable \\$x in #A::test# is unused/', $error->get_msg()); $error = $errors[3]; self::assert_equals(PC_Obj_Error::E_S_VAR_UNUSED, $error->get_type()); self::assert_regex('/The variable \\$a in ##global# is unused/', $error->get_msg()); $error = $errors[4]; self::assert_equals(PC_Obj_Error::E_S_VAR_UNUSED, $error->get_type()); self::assert_regex('/The variable \\$i in ##global# is unused/', $error->get_msg()); $var = $vars[PC_Obj_Variable::SCOPE_GLOBAL]['m']; self::assert_equals('array', (string) $var->get_type()); }