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->assertInstanceOf('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->assertInstanceOf('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->assertInstanceOf('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'); }
/** * Finds the name of this function starting from the T_FUNCTION token. * * If a function has no name it is probably a Closure and will have the name Closure. * * @param DocBlox_Token_Iterator $tokens * * @return string */ protected function findName(DocBlox_Token_Iterator $tokens) { $name = $tokens->findNextByType(T_STRING, 5, array('{', ';')); $this->setType($name ? self::TYPE_FUNCTION : self::TYPE_CLOSURE); return $name ? $name->content : 'Closure'; }
/** * Tries to find the DocBlox belonging to this file (page-level DocBlock). * * A page level DocBlock is a DocBlock that is at the top of a file and * is not directly followed by a class definition. * Page level DocBlocks MUST contain a @package tag or they are * 'disqualified'. * * If no page level docblox is found we throw a warning to indicate to the * user that this is missing. * * @param DocBlox_Token_Iterator $tokens Token array to parse. * * @return DocBlox_Reflection_DocBlock|null */ public function findDocBlock(DocBlox_Token_Iterator $tokens) { $result = null; $docblock = $tokens->findNextByType(T_DOC_COMMENT, 10, array(T_CLASS, T_NAMESPACE)); try { $result = $docblock ? new DocBlox_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 $valid = $this->validateDocBlock($this->filename, $docblock ? $docblock->getLineNumber() : 0, $result); if (!$valid) { $result = null; } return $result; }
/** * 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_Token_Iterator $tokens * @return string|null */ protected function findDefault(DocBlox_Token_Iterator $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 integer $default_token = $tokens->findNextByType(T_LNUMBER, 5, array(',', ')')); } if (!$default_token) { // check for a float $default_token = $tokens->findNextByType(T_DNUMBER, 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->content, '\'"') : null; }