コード例 #1
0
  /**
   * Returns the first docblock preceding the active token within 10 tokens.
   *
   * Please note that the iterator cursor does not change due to this method
   *
   * @param  DocBlox_TokenIterator $tokens
   * @return Zend_Reflection_DocBlock|null
   */
  protected function findDocBlock(DocBlox_TokenIterator $tokens)
  {
    $result = null;
    $docblock = $tokens->findPreviousByType(T_DOC_COMMENT, 10, array('{'. '}', ';'));
    try
    {
      $result = $docblock ? new Zend_Reflection_Docblock($docblock->getContent()) : null;
      if ($result)
      {
        // attach line number to class, the Zend_Reflection_DocBlock does not know the number
        $result->line_number = $docblock->getLineNumber();
      }
    }
    catch (Exception $e)
    {
      $this->log($e->getMessage(), Zend_Log::CRIT);
    }

    if (!$result)
    {
      $this->log('No DocBlock was found for '.substr(get_class($this), strrpos(get_class($this), '_')+1).' '.$this->getName().' on line '.$this->getLineNumber(), Zend_Log::ERR);
    }

    return $result;
  }
コード例 #2
0
ファイル: TokenIteratorTest.php プロジェクト: namesco/Docblox
  public function testFindPreviousByType()
  {
    $pos = 40;

    $this->object->seek($pos);
    $token = $this->object->findPreviousByType(T_CLASS, 0);
    $this->assertType('DocBlox_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->assertType('DocBlox_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->assertType('DocBlox_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');
  }
コード例 #3
0
ファイル: Abstract.php プロジェクト: namesco/Docblox
  protected function findVisibility(DocBlox_TokenIterator $tokens)
  {
    $result = 'public';
    $result = $tokens->findPreviousByType(T_PRIVATE, 5, array('{', ';')) ? 'private' : $result;
    $result = $tokens->findPreviousByType(T_PROTECTED, 5, array('{', ';')) ? 'protected' : $result;

    return $result;
  }