Example #1
0
  protected function findName(DocBlox_TokenIterator $tokens)
  {
    $name = $tokens->findNextByType(T_STRING, 5, array('{', ';'));
    $this->setType($name ? 'function' : 'closure');

    return $name ? $name->getContent() : 'Closure';
  }
Example #2
0
  public function testFindNextByType()
  {
    $this->object->seek(0);
    try
    {
      $token = $this->object->findNextByType(T_CLASS, -1);
      $this->fail('Expected an InvalidArgumentException when passing a negative number for the max_count argument');
    } catch (InvalidArgumentException $e)
    {
    }

    $this->object->seek(0);
    $token = $this->object->findNextByType(T_CLASS, 0);
    $this->assertType('DocBlox_Token', $token, 'Expected to find a T_CLASS in the dataset');
    $this->assertEquals(0, $this->object->key(), 'Expected the key to equal the starting position');

    $this->object->seek(0);
    $token = $this->object->findNextByType(T_CLASS, 40);
    $this->assertType('DocBlox_Token', $token, 'Expected to find a T_CLASS in the dataset within 40 tokens');
    $this->assertEquals(0, $this->object->key(), 'Expected the key to equal the starting position');

    $this->object->seek(0);
    $token = $this->object->findNextByType(T_CLASS, 40, T_REQUIRE);
    $this->assertType('DocBlox_Token', $token, 'Expected to find a T_CLASS in the dataset within 40 tokens before a T_REQUIRE is encountered');
    $this->assertEquals(0, $this->object->key(), 'Expected the key to equal the starting position');

    $this->object->seek(0);
    $token = $this->object->findNextByType(T_CLASS, 40, T_NAMESPACE);
    $this->assertFalse($token, 'Expected to fail finding a T_CLASS in the dataset within 40 tokens before a T_NAMESPACE is encountered');
    $this->assertEquals(0, $this->object->key(), 'Expected the key to be at the starting position');
  }
Example #3
0
  public function findDocBlock(DocBlox_TokenIterator $tokens)
  {
    $docblock = $tokens->findNextByType(T_DOC_COMMENT, 10, array(T_CLASS, T_NAMESPACE));

    try
    {
      $result = $docblock ? new Zend_Reflection_Docblock($docblock->getContent()) : null;
    }
    catch (Exception $e)
    {
      $this->log($e->getMessage(), Zend_Log::CRIT);
    }

    // TODO: add a check if a class immediately follows this docblock, if so this is not a page level docblock but a class docblock

    // even with a docblock at top (which may belong to some other component) does it
    // need to have a package tag to classify
    if ($result && !$result->hasTag('package'))
    {
      $result = null;
    }

    if (!$result)
    {
      $this->log('No Page-level DocBlock was found for '.$this->getName(), Zend_Log::ERR);
    }

    return $result;
  }
Example #4
0
  /**
   * Find the Default value for this object.
   *
   * Usually used with variables or arguments.
   * Please note that the iterator cursor does not change due to this method
   *
   * @param  DocBlox_TokenIterator $tokens
   * @return string|null
   */
  protected function findDefault(DocBlox_TokenIterator $tokens)
  {
    // check if a string is found
    $default_token        = $tokens->findNextByType(T_STRING, 5, array(',', ')'));
    if (!$default_token)
    {
      // check for a constant
      $default_token      = $tokens->findNextByType(T_CONSTANT_ENCAPSED_STRING, 5, array(',', ')'));
    }
    if (!$default_token)
    {
      // check for a number
      $default_token      = $tokens->findNextByType(T_LNUMBER, 5, array(',', ')'));
    }
    if (!$default_token)
    {
      // check for an array definition
      $default_token      = $tokens->findNextByType(T_ARRAY, 5, array(',', ')'));
    }

    // remove any surrounding single or double quotes before returning the data
    return $default_token ? trim($default_token->getContent(), '\'"') : null;
  }