Skip to content

Commit 17fdf02

Browse files
Add static constructor
1 parent 39fd6db commit 17fdf02

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
99
### Added
1010

1111
- Added support for PHP 8
12+
- Added static constructor
1213

1314
### Changed
1415

src/Item.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ public function __construct(mixed $value)
1515
}
1616
}
1717

18+
public static function from($value): self
19+
{
20+
return new self($value);
21+
}
22+
1823
public function __call(string $name, array $arguments): mixed
1924
{
2025
return $this->pipe($name, ...$arguments);
2126
}
2227

23-
public function pipe(callable|object|string $callback, mixed ...$arguments): Item|PipeProxy
28+
public function pipe(callable|object|string $callback, mixed ...$arguments): self|PipeProxy
2429
{
2530
if (! is_callable($callback)) {
2631
return new PipeProxy($this, $callback);

tests/Unit/MethodsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,25 @@
44

55
use Closure;
66
use PHPUnit\Framework\TestCase;
7+
use SebastiaanLuca\PipeOperator\Item;
78

89
class MethodsTest extends TestCase
910
{
11+
/**
12+
* @test
13+
*/
14+
public function it can transform using the static constructor(): void
15+
{
16+
$result = Item::from('https://blog.github.com')
17+
->parse_url()
18+
->end()
19+
->explode('.', PIPED_VALUE)
20+
->reset()
21+
->get();
22+
23+
$this->assertSame('blog', $result);
24+
}
25+
1026
/**
1127
* @test
1228
*/

0 commit comments

Comments
 (0)