/** * @param string $string A string of the param tag comment, without the param keyword * @param int $posCount Specifies the position of positional param tag. Defaults to 0. * * @return array An array of the param in the form of ["pos" => 0, "name" => "$var", "type" => ["integer", "bool"]] */ public static function parse($string, $posCount = 0) { $param = array_filter(explode(" ", $string)); // Filter excess spaces array_splice($param, 2); // Remove non-essential components e.g. comments if (count($param) === 2 and $param[0][0] === '$') { $name = $param[0]; $type = $param[1]; } else { if (count($param) === 2 and $param[1][0] === '$') { $name = $param[1]; $type = $param[0]; } else { if (count($param) === 1 and $param[0][0] === '$') { $name = $param[0]; $type = ""; } else { if (count($param) === 1 and $param[0][0] !== '$') { $name = '#' . $posCount; $type = $param[0]; } else { // This can also happen sometimes e.g. #0 object EasyRdf_Graph $graphA The first graph to be compared // Notice the lack of | // TODO: But for now, we ignore this error until we can put in better error recovery $name = '#' . $posCount; $type = ""; //throw new \InvalidArgumentException("Invalid comment specified. #$posCount $string"); } } } } $type = DocTypeNormaliser::normalise(explode("|", $type)); return ["pos" => $posCount, "name" => $name, "type" => $type]; }
/** * @param string $string A string of the var tag comment, without the var keyword * * @return array An array of the var type in the form of ["name" => "$var", "type" => ["integer", "bool"]] */ public static function parse($string) { $param = array_filter(explode(" ", $string)); // Filter excess spaces array_splice($param, 2); // Remove non-essential components e.g. comments if (count($param) === 2 and $param[0][0] === '$') { $name = $param[0]; $type = $param[1]; } else { if (count($param) === 2 and $param[1][0] === '$') { $name = $param[1]; $type = $param[0]; } else { if (count($param) === 1 and $param[0][0] === '$') { $name = $param[0]; $type = ""; } else { if (count($param) === 1) { // Whatever comes after has this type. e.g. name is dependent on future assignment $name = null; $type = $param[0]; } else { // TODO: string[] regular expressions for replacing disallowed characters in file name // TODO: Cases like above, we can no longer guarantee that given string will be a type // TODO: We may accidentally inject an invalid type into the index. // But for now, ignore those edge cases. // Whatever comes after has this type. e.g. name is dependent on future assignment $name = null; $type = $param[0]; //throw new \InvalidArgumentException("Invalid comment specified. $string"); } } } } $type = DocTypeNormaliser::normalise(explode("|", $type)); return ["name" => $name, "type" => $type]; }
/** * @param string $string A string of the return tag comment, without the return keyword * * @return array An array of the return types */ public static function parse($string) { return DocTypeNormaliser::normalise(explode("|", strtok($string, " "))); }