Skip to content

Commit

Permalink
Merge pull request #22 from fe3dback/new-static-func
Browse files Browse the repository at this point in the history
New static func
  • Loading branch information
fe3dback authored May 24, 2018
2 parents 6a703d0 + a1eb52c commit 2af1942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ class Str
"\xEF\xBE\xA0"],
];

public function __construct($str) { $this->s = $str; }
public function __construct(string $str) { $this->s = $str; }
public function __toString(): string { return $this->s; }
public function getString(): string { return $this->s; }

public static function make(string $str): Str { return new self($str); }

public function substr(int $start = 0, int $length = 0): Str
{
$this->s = \mb_substr($this->s, $start, $length !== 0 ? $length : \mb_strlen($this->s));
Expand Down
3 changes: 3 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public function testGetString()
$this->assertEquals((string)$s, 'Hello world');
$this->assertEquals((string)$s, $s);
$this->assertEquals($s->getString(), 'Hello world');

$s = Str::make('Hii');
$this->assertEquals((string)$s, 'Hii');
}

public function testPrefixSuffix()
Expand Down

0 comments on commit 2af1942

Please sign in to comment.