/** * Parses the given method-phpdoc * * @param PC_Obj_Method $func the method to which the phpdoc belongs */ public function parse_method_doc($func) { if (isset($this->funcComments[$func->get_name()])) { $doc = $this->funcComments[$func->get_name()]; // look for params $matches = array(); preg_match_all('/\\@param\\s+([^\\s]+)\\s+(&)?\\s*([^\\s]+)/', $doc, $matches); foreach ($matches[1] as $k => $match) { $param = substr($matches[3][$k], 1); // does the param exist? if (($fp = $func->get_param($param)) !== null) { $mtype = PC_Obj_MultiType::get_type_by_name($match); $fptype = $fp->get_mtype(); $isref = $matches[2][$k] != ''; // don't report that if we only know the type from the default value if ($fp->is_reference() != $isref || !$fp->is_mtype_default() && !$fptype->is_unknown() && !$fptype->equals($mtype)) { $docstr = ($isref ? '&' : '') . $mtype; $this->report_error('PHPDoc (' . $docstr . ') does not match the parameter $' . $param . ' (' . $fp . ')', PC_Obj_Error::E_T_PARAM_DIFFERS_FROM_DOC, $func->get_line()); } $fp->set_mtype($mtype); $fp->set_has_doc(true); } else { $this->report_error('Found PHPDoc for parameter "' . $param . '" (' . $match . '),' . ' but the parameter does not exist', PC_Obj_Error::E_T_DOC_WITHOUT_PARAM, $func->get_line()); } } // look for throws preg_match_all('/\\@throws\\s+([^\\s]+)/', $doc, $matches); foreach ($matches[1] as $k => $match) { $func->add_throw($match, PC_Obj_Method::THROW_SELF); } // look for return-type if (preg_match('/\\@return\\s+&?\\s*([^\\s]+)/', $doc, $matches)) { $mtype = PC_Obj_MultiType::get_type_by_name($matches[1]); if ($mtype !== null) { $rettype = $func->get_return_type(); if ($rettype && !$rettype->is_unknown() && !$rettype->equals($mtype)) { $this->report_error('PHPDoc (' . $mtype . ') does not match the return type (' . $rettype . ')', PC_Obj_Error::E_T_RETURN_DIFFERS_FROM_DOC, $func->get_line()); } if (!$rettype || $rettype->is_unknown()) { $func->set_return_type($mtype); } $func->set_has_return_doc(true); } } unset($this->funcComments[$func->get_name()]); } }
/** * Builds the fields to insert / update in the db * * @param PC_Obj_Method $function the function/method * @param int $class the id of the class the function belongs to * @param int $pid the project-id (default = current) * @return array all fields */ private function get_fields($function, $class, $pid = PC_Project::CURRENT_ID) { $params = serialize($function->get_params()); return array('project_id' => PC_UTils::get_project_id($pid), 'file' => $function->get_file(), 'line' => $function->get_line(), 'class' => $class, 'name' => $function->get_name(), 'abstract' => $function->is_abstract() ? 1 : 0, 'final' => $function->is_final() ? 1 : 0, 'static' => $function->is_static() ? 1 : 0, 'anonymous' => $function->is_anonymous() ? 1 : 0, 'visibility' => $function->get_visibility(), 'return_type' => serialize(array($function->has_return_doc(), $function->get_return_type())), 'throws' => serialize($function->get_throws()), 'params' => $params, 'min_version' => serialize($function->get_version()->get_min()), 'max_version' => serialize($function->get_version()->get_max())); }