Merge pull request #296 from phpDocumentor/fix/287-line-endings

Improve line-endings for windows.
This commit is contained in:
Jaap van Otterdijk
2021-09-17 08:30:37 +02:00
committed by GitHub
12 changed files with 53 additions and 36 deletions
+1 -2
View File
@@ -17,7 +17,6 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use phpDocumentor\Reflection\Utils;
use function count;
use function explode;
use function implode;
use function ltrim;
use function min;
@@ -146,7 +145,7 @@ class DescriptionFactory
*/
private function removeSuperfluousStartingWhitespace(string $contents): string
{
$lines = explode("\n", $contents);
$lines = Utils::pregSplit("/\r\n?|\n/", $contents);
// if there is only one line then we don't have lines with superfluous whitespace and
// can use the contents as-is
+7 -2
View File
@@ -42,6 +42,8 @@ class Serializer
/** @var Formatter A custom tag formatter. */
protected $tagFormatter;
/** @var string */
private $lineEnding;
/**
* Create a Serializer instance.
@@ -51,19 +53,22 @@ class Serializer
* @param bool $indentFirstLine Whether to indent the first line.
* @param int|null $lineLength The max length of a line or NULL to disable line wrapping.
* @param Formatter $tagFormatter A custom tag formatter, defaults to PassthroughFormatter.
* @param string $lineEnding Line ending used in the output, by default \n is used.
*/
public function __construct(
int $indent = 0,
string $indentString = ' ',
bool $indentFirstLine = true,
?int $lineLength = null,
?Formatter $tagFormatter = null
?Formatter $tagFormatter = null,
string $lineEnding = "\n"
) {
$this->indent = $indent;
$this->indentString = $indentString;
$this->isFirstLineIndented = $indentFirstLine;
$this->lineLength = $lineLength;
$this->tagFormatter = $tagFormatter ?: new PassthroughFormatter();
$this->lineEnding = $lineEnding;
}
/**
@@ -96,7 +101,7 @@ class Serializer
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
return $comment . $indent . ' */';
return str_replace("\n", $this->lineEnding, $comment . $indent . ' */');
}
private function removeTrailingSpaces(string $indent, string $text): string
-1
View File
@@ -21,7 +21,6 @@ interface Tag
/**
* @return Tag|mixed Class that implements Tag
*
* @phpstan-return ?Tag
*/
public static function create(string $body);
+1 -4
View File
@@ -59,7 +59,6 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param array<int, array<string, Type|string>> $arguments
*
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*/
public function __construct(
@@ -186,7 +185,6 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @return array<int, array<string, Type|string>>
*
* @phpstan-return array<int, array{name: string, type: Type}>
*/
public function getArguments(): array
@@ -239,10 +237,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param mixed[][]|string[] $arguments
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*
* @return mixed[][]
*
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
* @phpstan-return array<int, array{name: string, type: Type}>
*/
private function filterArguments(array $arguments = []): array
+1 -1
View File
@@ -14,8 +14,8 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\Exception\PcreException;
use Webmozart\Assert\Assert;
use function preg_last_error;
use function preg_split as php_preg_split;