/** * @dataProvider getStrings */ public function testConvert($tokens, $unformatted, $formatted) { $tokens = new Tokens($tokens); $this->converter->setIndentSize(0); $this->converter->useColonSpace(false); $this->assertEquals($unformatted, $this->converter->convert($tokens)); $this->converter->setIndentSize(4); $this->converter->useColonSpace(true); $this->assertEquals($formatted, $this->converter->convert($tokens)); }
/** * Compacts the docblock and its annotations. * * @param string $docblock The docblock. * * @return string The compacted docblock. */ private function compactAnnotations($docblock) { $annotations = array(); $index = -1; $inside = 0; $tokens = $this->tokenizer->parse($docblock); if (empty($tokens)) { return str_repeat("\n", substr_count($docblock, "\n")); } foreach ($tokens as $token) { if (0 === $inside && DocLexer::T_AT === $token[0]) { $index++; } elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) { $inside++; } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) { $inside--; } if (!isset($annotations[$index])) { $annotations[$index] = array(); } $annotations[$index][] = $token; } $breaks = substr_count($docblock, "\n"); $docblock = "/**"; foreach ($annotations as $annotation) { $annotation = new Tokens($annotation); $docblock .= "\n" . $this->converter->convert($annotation); } $breaks -= count($annotations); if ($breaks > 0) { $docblock .= str_repeat("\n", $breaks - 1); $docblock .= "\n*/"; } else { $docblock .= ' */'; } return $docblock; }