/** * Performs an analysis of the given code. * * @param string $code the code to analyze * @param PC_Engine_Options $options the options * @return array the following array: array( * 0 => <functions>, * 1 => <classes>, * 2 => <vars>, * 3 => <calls>, * 4 => <errors>, * ) */ protected function analyze($code, $options = null) { if ($options === null) { $options = new PC_Engine_Options(); } $env = new PC_Engine_Env($options); $tscanner = new PC_Engine_TypeScannerFrontend($env); $tscanner->scan($code); $fin = new PC_Engine_TypeFinalizer($env); $fin->finalize(); $stmt = new PC_Engine_StmtScannerFrontend($env); $stmt->scan($code); return array($env->get_types()->get_functions(), $env->get_types()->get_classes(), $stmt->get_vars(), $env->get_types()->get_calls(), $env->get_errors()->get()); }
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(); }