Skip to content

Commit

Permalink
Prevent string function call on first piped data
Browse files Browse the repository at this point in the history
  • Loading branch information
omitobi committed Apr 29, 2020
1 parent ed5afe6 commit b20d31a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Piper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function up(callable $action = null)

$result = $this->piped[0];

if (is_callable($result)) {
if (is_callable($result) && !is_string($result)) {
$result = $result();
}

Expand Down
12 changes: 11 additions & 1 deletion tests/PiperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ public function testPiperOnStaticCreation()
->up()
);
}

public function testStringPassedIntoFirstPipeShouldBeTreatedAsString()
{
$this->assertEquals(
'STRMANIPULATOR::STRTOLOWER',
Piper::on('StrManipulator::strToLower')
->to('strtoupper')
->up()
);
}
}

class StrManipulator
Expand All @@ -170,7 +180,7 @@ public function __invoke(string $value)
return $this->strToLower($value);
}

public static function strToLower(string $value)
public static function strToLower(string $value = '')
{
return strtolower($value);
}
Expand Down

0 comments on commit b20d31a

Please sign in to comment.