From b5c617662f73efdbf0a76b47632c09c2fe0634eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 15 Apr 2020 11:01:49 +0200 Subject: [PATCH] Enhancement: Use DocBlock itself to make it multi-line --- .../PhpUnit/PhpUnitInternalClassFixer.php | 49 ++----------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php index 013cec41043..0680c48bfc9 100644 --- a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php @@ -217,55 +217,12 @@ private function makeDocBlockMultiLineIfNeeded(DocBlock $doc, Tokens $tokens, $d { $lines = $doc->getLines(); if (1 === \count($lines) && empty($doc->getAnnotationsOfType('internal'))) { - $lines = $this->splitUpDocBlock($lines, $tokens, $docBlockIndex); + $indent = $this->detectIndent($tokens, $tokens->getNextNonWhitespace($docBlockIndex)); + $doc->makeMultiLine($indent, $this->whitespacesConfig->getLineEnding()); - return new DocBlock(implode('', $lines)); + return $doc; } return $doc; } - - /** - * Take a one line doc block, and turn it into a multi line doc block. - * - * @param Line[] $lines - * @param int $docBlockIndex - * - * @return Line[] - */ - private function splitUpDocBlock($lines, Tokens $tokens, $docBlockIndex) - { - $lineContent = $this->getSingleLineDocBlockEntry($lines); - $lineEnd = $this->whitespacesConfig->getLineEnding(); - $originalIndent = $this->detectIndent($tokens, $tokens->getNextNonWhitespace($docBlockIndex)); - - return [ - new Line('/**'.$lineEnd), - new Line($originalIndent.' * '.$lineContent.$lineEnd), - new Line($originalIndent.' */'), - ]; - } - - /** - * @param Line[] $line - * - * @return string - */ - private function getSingleLineDocBlockEntry($line) - { - $line = $line[0]; - $line = str_replace('*/', '', $line); - $line = trim($line); - $line = str_split($line); - $i = \count($line); - do { - --$i; - } while ('*' !== $line[$i] && '*' !== $line[$i - 1] && '/' !== $line[$i - 2]); - if (' ' === $line[$i]) { - ++$i; - } - $line = \array_slice($line, $i); - - return implode('', $line); - } }