Ejemplo n.º 1
0
 /**
  * Extracts the arguments from this function.
  *
  * @param DocBlox_Reflection_TokenIterator $tokens
  *
  * @return void
  */
 public function processVariable(DocBlox_Reflection_TokenIterator $tokens)
 {
     // is the variable occurs within arguments parenthesis then it is an argument
     if ($tokens->key() > $this->arguments_token_start && $tokens->key() < $this->arguments_token_end) {
         $this->resetTimer('variable');
         $argument = new DocBlox_Reflection_Argument();
         $argument->parseTokenizer($tokens);
         $this->arguments[$argument->getName()] = $argument;
         if ($this->getDocBlock()) {
             /** @var DocBlox_Reflection_DocBlock_Tag $params  */
             $params = $this->getDocBlock()->getTagsByName('param');
             if (!isset($params[count($this->arguments) - 1])) {
                 $this->logParserError('NOTICE', 'Argument ' . $argument->getName() . ' is missing from the function Docblock', $argument->getLineNumber());
             } else {
                 $param_name = $params[count($this->arguments) - 1]->getVariableName();
                 if ($param_name != $argument->getName()) {
                     if ($param_name == '') {
                         $params[count($this->arguments) - 1]->setVariableName($argument->getName());
                     } else {
                         $this->logParserError('NOTICE', 'Name of argument ' . $argument->getName() . ' does not match with function Docblock', $argument->getLineNumber());
                     }
                 }
             }
         }
         $this->debugTimer('>> Processed argument ' . $argument->getName(), 'variable');
     }
 }
 public function testFindPreviousByType()
 {
     $pos = 20;
     $this->object->seek($pos);
     $token = $this->object->findPreviousByType(T_CLASS, 0);
     $this->assertInstanceOf('DocBlox_Reflection_Token', $token, 'Expected to find a T_CLASS in the dataset');
     $this->assertEquals($pos, $this->object->key(), 'Expected the key to have a different position');
     $this->object->seek($pos);
     $token = $this->object->findPreviousByType(T_CLASS, $pos);
     $this->assertInstanceOf('DocBlox_Reflection_Token', $token, 'Expected to find a T_CLASS in the dataset within ' . $pos . ' tokens');
     $this->assertEquals($pos, $this->object->key(), 'Expected the key to have a different position');
     $this->object->seek($pos);
     $token = $this->object->findPreviousByType(T_CLASS, $pos, T_NAMESPACE);
     $this->assertInstanceOf('DocBlox_Reflection_Token', $token, 'Expected to find a T_CLASS in the dataset within ' . $pos . ' tokens before a T_NAMESPACE is encountered');
     $this->assertEquals($pos, $this->object->key(), 'Expected the key to have a different position');
     $this->object->seek($pos);
     $token = $this->object->findPreviousByType(T_CLASS, $pos, T_FUNCTION);
     $this->assertFalse($token, 'Expected to fail finding a T_CLASS in the dataset within ' . $pos . ' tokens before a T_FUNCTION is encountered');
     $this->assertEquals($pos, $this->object->key(), 'Expected the key to be at the starting position');
 }
Ejemplo n.º 3
0
 /**
  * Generic method which iterates through all tokens between the braces following the current position in the token
  * iterator.
  *
  * Please note: This method will also move the cursor position in the token iterator forward.
  * When a token is encountered this method will invoke the processToken method, which is defined in the
  * DocBlox_Reflection_Abstract class. Literals are ignored.
  *
  * @see    DocBlox_Reflection_Abstract
  *
  * @param  DocBlox_Reflection_TokenIterator $tokens
  *
  * @return int[]
  */
 public function processTokens(DocBlox_Reflection_TokenIterator $tokens)
 {
     $level = -1;
     $start = 0;
     $end = 0;
     $token = null;
     // parse class contents
     $this->debug('>> Processing tokens');
     while ($tokens->valid()) {
         /** @var DocBlox_Reflection_Token $token */
         $token = $token === null ? $tokens->current() : $tokens->next();
         $token_type = false;
         $token_content = false;
         if ($token instanceof DocBlox_Reflection_Token) {
             $token_type = $token->type;
             $token_content = $token->content;
         }
         // if we encounter a semi-colon before we have an opening brace then this is an abstract or interface function
         // which have no body; stop looking!
         if ($token_type === null && $token_content === ';' && $level === -1) {
             return array($start, $end);
         }
         if ($token_type == T_CURLY_OPEN || $token_type == T_DOLLAR_OPEN_CURLY_BRACES) {
             $token_content = '{';
         }
         // determine where the 'braced' section starts and end.
         // the first open brace encountered is considered the opening brace for the block and processing will
         // be 'breaked' when the closing brace is encountered
         if ((!$token_type || $token_type == T_CURLY_OPEN || $token_type == T_DOLLAR_OPEN_CURLY_BRACES) && ($token_content == '{' || $token_content == '}')) {
             switch ($token_content) {
                 case '{':
                     // expect the first brace to be an opening brace
                     if ($level == -1) {
                         $level++;
                         $start = $tokens->key();
                     }
                     $level++;
                     break;
                 case '}':
                     if ($level == -1) {
                         continue;
                     }
                     $level--;
                     // reached the end; break from the while
                     if ($level === 0) {
                         $end = $tokens->key();
                         break 2;
                         // time to say goodbye
                     }
                     break;
             }
             continue;
         }
         if ($token && $token_type) {
             // if a token is encountered and it is not a literal, invoke the processToken method
             $this->processToken($token, $tokens);
         }
     }
     // return the start and end token index
     return array($start, $end);
 }
Ejemplo n.º 4
0
 /**
  * Scans all tokens within the scope of the current token and invokes the process* methods.
  *
  * This is a base class which may be overridden in sub-classes to scan the scope of the current token
  * (i.e. the method body in case of the method)
  *
  * @param DocBlox_Reflection_TokenIterator $tokens iterator with the current position
  *
  * @return int[] Start and End token id
  */
 protected function processTokens(DocBlox_Reflection_TokenIterator $tokens)
 {
     return array($tokens->key(), $tokens->key());
 }