Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/phpactor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ini_set('display_errors', 'stderr');

if (!isset($autoloadFile)) {
echo sprintf(
'Phpactor dependencies not installed. Run `composer install` (https://getcomposer.org) in "%s"' . PHP_EOL,
'Phpactor dependencies not installed. Run `composer install` (https://getcomposer.org) in "%s"' . "\n",
realpath(__DIR__ . '/..')
);
exit(255);
Expand All @@ -32,7 +32,7 @@ if (!isset($autoloadFile)) {
$minVersion = '8.1.0';

if (version_compare(PHP_VERSION, $minVersion) < 0) {
fwrite(STDERR, sprintf('Phpactor requires at least PHP %s', $minVersion) . PHP_EOL);
fwrite(STDERR, sprintf('Phpactor requires at least PHP %s', $minVersion) . "\n");
exit(255);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/ClassMover/Domain/SourceCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function addNamespace(FullyQualifiedName $namespace): SourceCode
if (null !== $phpDeclarationLineNb) {
return $this->insertAfter(
$phpDeclarationLineNb,
PHP_EOL . sprintf('namespace %s;', (string) $namespace)
"\n" . sprintf('namespace %s;', (string) $namespace)
);
}

Expand All @@ -54,11 +54,11 @@ public function addUseStatement(FullyQualifiedName $classToUse): SourceCode
}

if ($namespaceLineNb) {
return $this->insertAfter($namespaceLineNb, PHP_EOL.$useStmt);
return $this->insertAfter($namespaceLineNb, "\n".$useStmt);
}

if (null !== $phpDeclarationLineNb) {
return $this->insertAfter($phpDeclarationLineNb, PHP_EOL.$useStmt);
return $this->insertAfter($phpDeclarationLineNb, "\n".$useStmt);
}

throw new InvalidArgumentException(
Expand All @@ -73,7 +73,7 @@ public function replaceSource(string $source): self

private function insertAfter(int $lineNb, string $text): self
{
$lines = explode(PHP_EOL, $this->source);
$lines = explode("\n", $this->source);
$newLines = [];
foreach ($lines as $index => $line) {
if ($line === $text) {
Expand All @@ -86,13 +86,13 @@ private function insertAfter(int $lineNb, string $text): self
}
}

return $this->replaceSource(implode(PHP_EOL, $newLines));
return $this->replaceSource(implode("\n", $newLines));
}

/** @return array{int|null, int|null, int|null} */
private function significantLineNumbers(): array
{
$lines = explode(PHP_EOL, $this->source);
$lines = explode("\n", $this->source);
$phpDeclarationLineNb = $namespaceLineNb = $lastUseLineNb = null;

foreach ($lines as $index => $line) {
Expand Down
10 changes: 5 additions & 5 deletions lib/CodeBuilder/Adapter/TolerantParser/TolerantUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function updateNamespace(Edits $edits, SourceCode $prototype, SourceFile
}

$startTag = $node->getFirstChildNode(InlineHtml::class);
$edits->after($startTag, 'namespace ' . (string) $prototype->namespace() . ';' . PHP_EOL.PHP_EOL);
$edits->after($startTag, 'namespace ' . (string) $prototype->namespace() . ';' . "\n"."\n");
}

private function updateClasses(Edits $edits, SourceCode $prototype, SourceFileNode $node): void
Expand Down Expand Up @@ -147,14 +147,14 @@ private function updateClasses(Edits $edits, SourceCode $prototype, SourceFileNo

$index = 0;
foreach ($classes as $classPrototype) {
if (substr($lastStatement->getText(), -1) !== PHP_EOL) {
$edits->after($lastStatement, PHP_EOL);
if (substr($lastStatement->getText(), -1) !== "\n") {
$edits->after($lastStatement, "\n");
}

if ($index > 0 && $index + 1 == count($classes)) {
$edits->after($lastStatement, PHP_EOL);
$edits->after($lastStatement, "\n");
}
$edits->after($lastStatement, PHP_EOL . $this->renderer->render($classPrototype));
$edits->after($lastStatement, "\n" . $this->renderer->render($classPrototype));
$index++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype,
}

if ($newLine) {
$edits->after($lastMember, PHP_EOL);
$edits->after($lastMember, "\n");
}

foreach ($methodPrototypes as $methodPrototype) {
Expand All @@ -112,24 +112,24 @@ public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype,
if ($lastNonMethodMember === null) {
$edits->after(
$this->memberDeclarationsNode($classNode)->openBrace,
PHP_EOL.$edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1).PHP_EOL
"\n".$edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1)."\n"
);
} else {
$edits->after(
$lastNonMethodMember,
PHP_EOL.PHP_EOL.$edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1)
"\n"."\n".$edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1)
);
}
continue;
}

$edits->after(
$lastMember,
PHP_EOL . $edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1)
"\n" . $edits->indent($this->renderMethod($this->renderer, $methodPrototype), 1)
);

if (false === $classPrototype->methods()->isLast($methodPrototype)) {
$edits->after($lastMember, PHP_EOL);
$edits->after($lastMember, "\n");
}
}
}
Expand All @@ -154,7 +154,7 @@ private function appendLinesToMethod(Edits $edits, Method $method, Node $bodyNod

foreach ($method->body()->lines() ?? [] as $line) {
// do not add duplicate lines
$bodyNodeLines = explode(PHP_EOL, $bodyNode->getText());
$bodyNodeLines = explode("\n", $bodyNode->getText());

foreach ($bodyNodeLines as $bodyNodeLine) {
if (trim($bodyNodeLine) == trim((string) $line)) {
Expand All @@ -164,7 +164,7 @@ private function appendLinesToMethod(Edits $edits, Method $method, Node $bodyNod

$edits->after(
$lastStatement,
PHP_EOL . $edits->indent((string) $line, 2)
"\n" . $edits->indent((string) $line, 2)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ protected function updateProperties(Edits $edits, ClassLikePrototype $classProto
foreach ($classPrototype->properties()->notIn($existingPropertyNames) as $property) {
// if property type exists then the last property has a docblock - add a line break
if ($lastProperty instanceof PropertyDeclaration && $property->type() != Type::none()) {
$edits->after($lastProperty, PHP_EOL);
$edits->after($lastProperty, "\n");
}

$edits->after(
$lastProperty,
PHP_EOL . $edits->indent($this->renderer->render($property), 1)
"\n" . $edits->indent($this->renderer->render($property), 1)
);

if ($classPrototype->properties()->isLast($property) && $nextMember instanceof MethodDeclaration) {
$edits->after($lastProperty, PHP_EOL);
$edits->after($lastProperty, "\n");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function memberDeclarationsNode(ClassLike $classNode)
public function renderMethod(Renderer $renderer, Method $method): string
{
return $renderer->render($method) .
PHP_EOL .
"\n" .
$renderer->render($method->body());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ protected function updateConstants(Edits $edits, ClassPrototype $classPrototype,

$edits->after(
$lastConstant,
PHP_EOL . $edits->indent($this->renderer->render($constant), 1)
"\n" . $edits->indent($this->renderer->render($constant), 1)
);

if ($classPrototype->constants()->isLast($constant) && (
$nextMember instanceof MethodDeclaration ||
$nextMember instanceof PropertyDeclaration
)) {
$edits->after($lastConstant, PHP_EOL);
$edits->after($lastConstant, "\n");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public function updateCases(
foreach ($classPrototype->cases()->notIn($existingCasesNames) as $case) {
$edits->after(
$lastConstant,
PHP_EOL . $edits->indent($this->renderer->render($case), 1)
"\n" . $edits->indent($this->renderer->render($case), 1)
);

if ($classPrototype->cases()->isLast($case) && (
$nextMember instanceof MethodDeclaration ||
$nextMember instanceof EnumCaseDeclaration
)) {
$edits->after($lastConstant, PHP_EOL);
$edits->after($lastConstant, "\n");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function updateUseStatements(Edits $edits, SourceCode $prototype, SourceF

if ($startNode instanceof NamespaceDefinition) {
// Add a new line to be in the same case that if it was an InlineHtml node
$edits->after($startNode, PHP_EOL);
$edits->after($startNode, "\n");
}

foreach ($usePrototypes as $usePrototype) {
Expand Down Expand Up @@ -90,7 +90,7 @@ public function updateUseStatements(Edits $edits, SourceCode $prototype, SourceF
if ($cmp > 0) {
// Add before one of the use import and add a new
// line so the new import is on its own line
$edits->before($childNode, $editText . PHP_EOL);
$edits->before($childNode, $editText . "\n");
continue 3;
}
}
Expand All @@ -102,14 +102,14 @@ public function updateUseStatements(Edits $edits, SourceCode $prototype, SourceF
// Since it will add before the lasts new line of the node we
// preprend with another one so that the use statement is on its
// own line
$newUseStatement = PHP_EOL . $editText;
$newUseStatement = "\n" . $editText;
$edits->after($startNode, $newUseStatement);
}

if ($startNode instanceof InlineHtml) {
// Add a new line after the last use statement so that it's on its
// own line
$edits->after($startNode, PHP_EOL);
$edits->after($startNode, "\n");
}

// Add another new line to separate the new use declaration from
Expand All @@ -118,7 +118,7 @@ public function updateUseStatements(Edits $edits, SourceCode $prototype, SourceF
!$startNode instanceof NamespaceUseDeclaration &&
$bodyNode && NodeHelper::emptyLinesPrecedingNode($bodyNode) === 0
) {
$edits->after($startNode, PHP_EOL);
$edits->after($startNode, "\n");
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/CodeBuilder/Domain/Prototype/Docblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function asLines(): array
return [];
}

return explode(PHP_EOL, $this->docblock);
return explode("\n", $this->docblock);
}
}
2 changes: 1 addition & 1 deletion lib/CodeBuilder/Domain/Prototype/Lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Lines extends Collection
{
public function __toString(): string
{
return implode(PHP_EOL, $this->items);
return implode("\n", $this->items);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeBuilder/Tests/Adapter/GeneratorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class GeneratorTestCase extends TestCase
public function testRender(Prototype $prototype, string $expectedCode): void
{
$code = $this->renderer()->render($prototype);
$this->assertEquals(rtrim(Code::fromString($expectedCode), PHP_EOL), rtrim($code, PHP_EOL));
$this->assertEquals(rtrim(Code::fromString($expectedCode), "\n"), rtrim($code, "\n"));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/CodeBuilder/Tests/Adapter/UpdaterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2030,8 +2030,8 @@ abstract protected function updater(): Updater;

private function assertUpdate(string $existingCode, SourceCode $prototype, string $expectedCode): void
{
$existingCode = '<?php'.PHP_EOL.$existingCode;
$existingCode = '<?php'."\n".$existingCode;
$edits = $this->updater()->textEditsFor($prototype, Code::fromString($existingCode));
$this->assertEquals('<?php' . PHP_EOL . $expectedCode, $edits->apply($existingCode));
$this->assertEquals('<?php' . "\n" . $expectedCode, $edits->apply($existingCode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ private function fixNamespace(SourceFileNode $rootNode, string $correctNamespace
$scriptStart = $rootNode->getFirstDescendantNode(InlineHtml::class);
$scriptStart = $scriptStart ? $scriptStart->getEndPosition() : 0;

$statement = PHP_EOL . $statement . PHP_EOL;
$statement = "\n" . $statement . "\n";

if (0 === $scriptStart) {
$statement = '<?php' . PHP_EOL . $statement;
$statement = '<?php' . "\n" . $statement;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function extractExpression(SourceCode $source, int $offsetStart, ?int $of
$endPosition = $expression->getEndPosition();

$extractedString = rtrim(trim($source->extractSelection($startPosition, $endPosition)), ';');
$assigment = sprintf('$%s = %s;', $variableName, $extractedString) . PHP_EOL;
$assigment = sprintf('$%s = %s;', $variableName, $extractedString) . "\n";

$statement = $expression->getFirstAncestor(StatementNode::class);
assert($statement instanceof StatementNode);
Expand Down
6 changes: 3 additions & 3 deletions lib/CodeTransform/Domain/Utils/TextUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TextUtils
public static function removeIndentation(string $string): string
{
$indentation = null;
$lines = explode(PHP_EOL, $string);
$lines = explode("\n", $string);

foreach ($lines as $i => $line) {
if ($line === '') {
Expand Down Expand Up @@ -36,12 +36,12 @@ public static function removeIndentation(string $string): string
$line = substr($line, $indentation);
}

return trim(implode(PHP_EOL, $lines), PHP_EOL);
return trim(implode("\n", $lines), "\n");
}

public static function stringIndentation(string $string): int
{
$lines = explode(PHP_EOL, $string);
$lines = explode("\n", $string);

if (empty($lines)) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function format(ObjectFormatter $formatter, object $object): string
$paramInfo[] = '$' . $object->name();

if ($object->default()->isDefined()) {
$paramInfo[] = '= '. str_replace(PHP_EOL, '', var_export($object->default()->value(), true));
$paramInfo[] = '= '. str_replace("\n", '', var_export($object->default()->value(), true));
}
return implode(' ', $paramInfo);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Completion/Tests/Benchmark/Code/Example1.php.test
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Example1
private function getOffetToReflect($source, $offset)
{
/** @var string $source */
$source = str_replace(PHP_EOL, ' ', $source);
$source = str_replace("\n", ' ', $source);
$untilCursor = substr($source, 0, $offset);

$pos = strlen($untilCursor) - 1;
Expand Down Expand Up @@ -123,7 +123,7 @@ class Example1
$paramInfo[] = '$' . $parameter->name();

if ($parameter->default()->isDefined()) {
$paramInfo[] = '= '. str_replace(PHP_EOL, '', var_export($parameter->default()->value(), true));
$paramInfo[] = '= '. str_replace("\n", '', var_export($parameter->default()->value(), true));
}
$paramInfos[] = implode(' ', $paramInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Completion/Tests/Unit/Core/Util/OffsetHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function provideReturnsLastNonWhitespaceOffset()
];

yield 'extra newline' => [
'foobar<>' . PHP_EOL,
'foobar<>' . "\n",
];

yield 'extra windows newline' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function serializeReference(string $code, MemberReference $reference): a
*/
private function line(string $code, int $offset):array
{
$lines = explode(PHP_EOL, $code);
$lines = explode("\n", $code);
$number = 0;
$startPosition = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Extension/ClassMover/Application/ClassReferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function serializeReference(string $code, ClassReference $reference): ar
/** @return array{int, int, string} */
private function line(string $code, int $offset): array
{
$lines = explode(PHP_EOL, $code);
$lines = explode("\n", $code);
$lineNumber = 0;
$startPosition = 0;

Expand Down
Loading