Skip to content

Commit a4037ba

Browse files
committed
refactor: rename limit to truncate
1 parent 8f48060 commit a4037ba

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Tempest/Support/src/StringHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,20 +657,20 @@ public function excerpt(int $from, int $to, bool $asArray = false): self|ArrayHe
657657
}
658658

659659
/**
660-
* Limits the number of characters of the instance.
660+
* Truncates the instance to the specified amount of characters.
661661
*
662662
* ### Example
663663
* ```php
664-
* str('Lorem ipsum')->limit(5, end: '...'); // Lorem...
664+
* str('Lorem ipsum')->truncate(5, end: '...'); // Lorem...
665665
* ```
666666
*/
667-
public function limit(int $characters, string $end = ''): self
667+
public function truncate(int $characters, string $end = ''): self
668668
{
669669
if (mb_strwidth($this->string, 'UTF-8') <= $characters) {
670670
return $this;
671671
}
672672

673-
return new self(rtrim(mb_strimwidth($this->string, 0, $characters, '', 'UTF-8')) . $end);
673+
return new self(rtrim(mb_strimwidth($this->string, 0, $characters, encoding: 'UTF-8')) . $end);
674674
}
675675

676676
/**

src/Tempest/Support/tests/StringHelperTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ public function test_start(): void
484484

485485
public function test_limit(): void
486486
{
487-
$this->assertSame('Lorem', str('Lorem ipsum')->limit(5)->toString());
488-
$this->assertSame('Lorem...', str('Lorem ipsum')->limit(5, end: '...')->toString());
489-
$this->assertSame('...', str('Lorem ipsum')->limit(0, end: '...')->toString());
490-
$this->assertSame('L...', str('Lorem ipsum')->limit(1, end: '...')->toString());
491-
$this->assertSame('Lorem ipsum', str('Lorem ipsum')->limit(100)->toString());
492-
$this->assertSame('Lorem ipsum', str('Lorem ipsum')->limit(100, end: '...')->toString());
487+
$this->assertSame('Lorem', str('Lorem ipsum')->truncate(5)->toString());
488+
$this->assertSame('Lorem...', str('Lorem ipsum')->truncate(5, end: '...')->toString());
489+
$this->assertSame('...', str('Lorem ipsum')->truncate(0, end: '...')->toString());
490+
$this->assertSame('L...', str('Lorem ipsum')->truncate(1, end: '...')->toString());
491+
$this->assertSame('Lorem ipsum', str('Lorem ipsum')->truncate(100)->toString());
492+
$this->assertSame('Lorem ipsum', str('Lorem ipsum')->truncate(100, end: '...')->toString());
493493
}
494494

495495
public function test_substr(): void

0 commit comments

Comments
 (0)