public function run($args) { $project = FWS_Props::get()->project(); $options = new PC_Engine_Options(); $options->add_project($project->get_id()); foreach ($project->get_project_deps() as $pid) { $options->add_project($pid); } $types = new PC_Engine_TypeContainer($options); $storage = new PC_Engine_TypeStorage_DB(); $env = new PC_Engine_Env($options, $types, $storage); $types->prefetch(); $fin = new PC_Engine_TypeFinalizer($env); $fin->finalize(); }
/** * Fetches the page from the specified file and parses it for information about the function */ public function finalize() { $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $typecon = new PC_Engine_TypeContainer($options); $typecon->prefetch(); foreach ($this->versions as $vinfo) { list($classname, $funcname, $version) = $vinfo; $class = $typecon->get_class($classname); if ($class !== null) { $func = $class->get_method($funcname); if ($func !== null) { if ($func->get_version()->is_empty()) { $func->get_version()->set($version->get_min(), $version->get_max()); } PC_DAO::get_functions()->update($func, $class->get_id()); } } } // inherit version info to methods, if still empty foreach ($typecon->get_classes() as $c) { $version = $c->get_version(); foreach ($c->get_methods() as $m) { if ($m->get_version()->is_empty()) { $m->get_version()->set($version->get_min(), $version->get_max()); PC_DAO::get_functions()->update($m, $c->get_id()); } } } foreach ($this->aliases as $alias) { list($funcname, $aliasclass, $aliasfunc) = $alias; $aliasf = null; if ($aliasclass) { $class = $typecon->get_class($aliasclass); if ($class !== null) { $aliasf = $class->get_method($aliasfunc); } } else { $aliasf = $typecon->get_function($aliasfunc); } if ($aliasf !== null) { $aliasf->set_name($funcname); PC_DAO::get_functions()->create($aliasf, 0, PC_Project::PHPREF_ID); } } }
public function test_pecl_versions() { $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $code = '<?php $pdo = new PDO("host","login","pw"); $sth = $pdo->prepare("SELECT * FROM mytable"); $count = $sth->columnCount(); ?>'; $opt = clone $options; $opt->add_min_req('PHP', '5.2.0'); $opt->add_max_req('PHP', '8.0.0'); list(, , , , $errors) = $this->analyze($code, $opt); self::assert_equals(3, count($errors)); $error = $errors[0]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_NEWER, $error->get_type()); self::assert_equals('PDO->__construct(string=host, string=login, string=pw) requires PECL pdo >= 0.1.0', $error->get_msg()); $error = $errors[1]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_NEWER, $error->get_type()); self::assert_equals('PDO->prepare(string=SELECT * FROM mytable) requires PECL pdo >= 0.1.0', $error->get_msg()); $error = $errors[2]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_NEWER, $error->get_type()); self::assert_equals('PDOStatement->columnCount() requires PECL pdo >= 0.2.0', $error->get_msg()); $code = '<?php $pdo = new PDO("host","login","pw"); $sth = $pdo->prepare("SELECT * FROM mytable"); $count = $sth->columnCount(); ?>'; $opt = clone $options; $opt->add_min_req('PHP', '5.2.0'); $opt->add_max_req('PHP', '8.0.0'); $opt->add_min_req('PECL pdo', '0.1.0'); list(, , , , $errors) = $this->analyze($code, $opt); self::assert_equals(1, count($errors)); $error = $errors[0]; self::assert_equals(PC_Obj_Error::E_S_REQUIRES_NEWER, $error->get_type()); self::assert_equals('PDOStatement->columnCount() requires PECL pdo >= 0.2.0, but you target PECL pdo >= 0.1.0', $error->get_msg()); }
public function run($args) { $project = FWS_Props::get()->project(); $options = new PC_Engine_Options(); foreach ($project->get_project_deps() as $pid) { $options->add_project($pid); } $env = new PC_Engine_Env($options); $tscanner = new PC_Engine_TypeScannerFrontend($env); $msgs = array(); foreach ($args as $file) { try { $tscanner->scan_file($file); } catch (PC_Engine_Exception $e) { $msgs[] = $e->__toString(); } } foreach ($env->get_types()->get_classes() as $class) { PC_DAO::get_classes()->create($class); } foreach ($env->get_types()->get_constants() as $const) { PC_DAO::get_constants()->create($const); } foreach ($env->get_types()->get_functions() as $func) { PC_DAO::get_functions()->create($func); } foreach ($env->get_errors()->get() as $err) { PC_DAO::get_errors()->create($err); } // write msgs 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 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(); }
/** * Returns the (free) constant with given name. Will fetch it from db if not already present * * @param string $name the constant-name * @return PC_Obj_Constant the constant or null if not found */ public function get_constant($name) { if (empty($name)) { return null; } $lname = strtolower($name); if (!isset($this->missing['consts'][$lname])) { if (!isset($this->constants[$lname])) { foreach ($this->options->get_projects() as $pid) { $c = PC_DAO::get_constants()->get_by_name($name, $pid); if ($c) { $this->constants[$lname] = $c; break; } } } } if (isset($this->constants[$lname])) { return $this->constants[$lname]; } $this->missing['consts'][$lname] = true; return null; }
public function test_varvars() { $code = '<?php class foo { const ABC = 5; public $XYZ = 4; public static function test() { } } class bar {} function foo() {} function bar() {} $a = "foo"; ${$a} = "bar"; ${"bar"} = 2; ${"foo"."bar"} = 3; ${$a + 1} = $a::$XYZ; ${1.2} = $a::ABC; ${$_} = 1; $a(); ${$a}(); $_(); new $a(); new ${$a}(); new $_(); $a::test(); $Bar = "b"; $Foo = "Bar"; $World = "Foo"; $Hello = "World"; $b = "Hello"; $c = $b; $d = $$b; $e = $$$b; $f = $$$$b; $g = $$$$$b; $h = $$$$$$b; $i = $$$$$$$b; ?>'; $options = new PC_Engine_Options(); $options->add_project(PC_Project::PHPREF_ID); $options->add_min_req('PHP', '5'); list(, , $vars, $calls, $errors) = $this->analyze($code, $options); self::assert_equals(0, count($errors)); $global = $vars[PC_Obj_Variable::SCOPE_GLOBAL]; self::assert_equals(18, count($global)); self::assert_equals('string=foo', (string) $global['a']->get_type()); self::assert_equals('string=bar', (string) $global['foo']->get_type()); self::assert_equals('integer=2', (string) $global['bar']->get_type()); self::assert_equals('integer=3', (string) $global['foobar']->get_type()); self::assert_equals('integer=4', (string) $global['1']->get_type()); self::assert_equals('integer=5', (string) $global['1.2']->get_type()); self::assert_equals('string=Hello', (string) $global['b']->get_type()); self::assert_equals('string=Hello', (string) $global['c']->get_type()); self::assert_equals('string=World', (string) $global['d']->get_type()); self::assert_equals('string=Foo', (string) $global['e']->get_type()); self::assert_equals('string=Bar', (string) $global['f']->get_type()); self::assert_equals('string=b', (string) $global['g']->get_type()); self::assert_equals('string=Hello', (string) $global['h']->get_type()); self::assert_equals('string=World', (string) $global['i']->get_type()); self::assert_equals(5, count($calls)); self::assert_equals('foo()', (string) $calls[0]); self::assert_equals('bar()', (string) $calls[1]); self::assert_equals('foo->__construct()', (string) $calls[2]); self::assert_equals('bar->__construct()', (string) $calls[3]); self::assert_equals('foo::test()', (string) $calls[4]); }