/** * Sets the given function-parameter for the current scope * * @param PC_Obj_Parameter $p the parameter */ public function set_func_param($p) { if (!$p instanceof PC_Obj_Parameter) { $this->handle_error('$p is invalid'); return; } $var = $this->get_var(PC_Obj_MultiType::create_string($p->get_name())); // give type-hinting the highest prio, because I think its the most trustable type if (!$p->get_mtype()->is_unknown()) { $this->set_var($var, $p->get_mtype()); return; } // if a variable-type is unknown and we're in a function/class, check if we know the type // from the type-scanner $func = $this->env->get_types()->get_method_or_func($this->scope->get_name_of(T_CLASS_C), $this->scope->get_name_of(T_FUNC_C)); // if we have a doc, use it. otherwise use the default-value $doc = $this->get_funcparam_type($func, $p->get_name()); if ($doc !== null) { $this->set_var($var, $doc); } else { $this->set_var($var, $p->get_mtype()); } }
/** * Checks whether $arg is ok for $param * * @param PC_Obj_Location $loc the location * @param PC_Obj_MultiType $arg the argument * @param PC_Obj_Parameter $param the parameter * @return boolean true if so */ private function is_argument_ok($loc, $arg, $param) { // not present but required? if ($arg === null && !$param->is_optional() && !$param->is_first_vararg()) { return false; } // unknown / not present if ($arg === null) { return true; } // callables are special if ($param->get_mtype()->get_first()->get_type() == PC_Obj_Type::TCALLABLE) { if (!$arg->is_unknown()) { $this->check_callable($loc, $arg); return true; } } // arg in the allowed types? return $this->env->get_types()->is_type_conforming($arg, $param->get_mtype()); }