/** * Creates a tokenizer representing the code that is the best candidate for representing the function. It uses * reflection to find the file and lines of the code and then puts that code into the tokenizer. * * @return \FunctionParser\Tokenizer The tokenizer of the function's code. */ protected function fetchTokenizer() { // Load the file containing the code for the function $file = new \SplFileObject($this->reflection->getFileName()); // Identify the first and last lines of the code for the function $first_line = $this->reflection->getStartLine(); $last_line = $this->reflection->getEndLine(); // Retrieve all of the lines that contain code for the function $code = ''; $file->seek($first_line - 1); while ($file->key() < $last_line) { $code .= $file->current(); $file->next(); } // Setup the tokenizer with the code from the file $tokenizer = new Tokenizer($code); // Eliminate tokens that are definitely not a part of the function code $start = $tokenizer->findToken(T_FUNCTION); $finish = $tokenizer->findToken('}', -1); $tokenizer = $tokenizer->getTokenRange($start, $finish + 1); return $tokenizer; }