public function testFindPreviousByType() { $pos = 20; $this->object->seek($pos); $token = $this->object->findPreviousByType(T_CLASS, 0); $this->assertInstanceOf('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->assertInstanceOf('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->assertInstanceOf('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'); }
/** * Returns the first docblock preceding the active token within 10 tokens. * * Please note that the iterator cursor does not change with to this method. * * @param DocBlox_Token_Iterator $tokens * * @return DocBlox_Reflection_DocBlock|null */ protected function findDocBlock(DocBlox_Token_Iterator $tokens) { $result = null; $docblock = $tokens->findPreviousByType(T_DOC_COMMENT, 10, array('{', '}', ';')); try { $result = $docblock ? new DocBlox_Reflection_DocBlock($docblock->getContent()) : null; if ($result) { // attach line number to class, the DocBlox_Reflection_DocBlock does not know the number $result->line_number = $docblock->getLineNumber(); } } catch (Exception $e) { $this->log($e->getMessage(), Zend_Log::CRIT); } $this->validateDocBlock($this->filename, $docblock ? $docblock->getLineNumber() : 0, $result); // if the object has no DocBlock _and_ is not a Closure; throw a warning $type = substr(get_class($this), strrpos(get_class($this), '_') + 1); if (!$result && ($type !== 'Function' && $this->getName() !== 'Closure')) { $this->log('No DocBlock was found for ' . $type . ' ' . $this->getName() . ' in file ' . $tokens->getFilename() . ' on line ' . $this->getLineNumber(), Zend_Log::ERR); } return $result; }
/** * Searches for visibility specifiers with the current token. * * @param DocBlox_Token_Iterator $tokens Token iterator to search in. * * @return string public|private|protected */ protected function findVisibility(DocBlox_Token_Iterator $tokens) { $result = 'public'; $result = $tokens->findPreviousByType(T_PRIVATE, 5, array('{', ';')) ? 'private' : $result; $result = $tokens->findPreviousByType(T_PROTECTED, 5, array('{', ';')) ? 'protected' : $result; return $result; }