Skip to content

Commit 78a40dd

Browse files
committed
feat(strings): add new method newLine
1 parent 8edbda4 commit 78a40dd

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/Strings.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,21 @@ public function dd(?callable $callback = null): void
27682768

27692769
exit(1);
27702770
}
2771-
2771+
2772+
/**
2773+
* Append a new line to the string.
2774+
*
2775+
* @param int $count Count of new lines. Default is 1.
2776+
*
2777+
* @return self Returns instance of the Strings class.
2778+
*
2779+
* @access public
2780+
*/
2781+
public function newLine(int $count = 1): self
2782+
{
2783+
return $this->append(str_repeat(PHP_EOL, $count));
2784+
}
2785+
27722786
/**
27732787
* Returns a new ArrayIterator, thus implementing the IteratorAggregate
27742788
* interface. The ArrayIterator's constructor is passed an array of chars

tests/StringsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@
515515
$this->assertEquals('#Stranger Things#', Strings::create('Stranger Things')->wrap('#')->toString());
516516
});
517517

518+
test('test newLine() method', function(): void {
519+
$this->assertEquals('Foo' . PHP_EOL, Strings::create('Foo')->newLine()->toString());
520+
$this->assertEquals('Foo' . PHP_EOL . PHP_EOL, Strings::create('Foo')->newLine(2)->toString());
521+
});
522+
518523
test('test replaceSubstr() method', function (): void {
519524
$this->assertEquals('19-84', Strings::create('1984')->replaceSubstr('-', 2, 0)->toString());
520525
$this->assertEquals('fòô bàř bàz', Strings::create('fòô bàz')->replaceSubstr('bàř ', 4, 0)->toString());

0 commit comments

Comments
 (0)