Skip to content

Commit

Permalink
Merge pull request #2 from transprime-research/bugfix/prevent-executi…
Browse files Browse the repository at this point in the history
…ng-function-call-on-first-data-string

Prevent string function call on first piped data
  • Loading branch information
omitobi authored Apr 29, 2020
2 parents ed5afe6 + b20d31a commit c9dde00
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 c9dde00

Please sign in to comment.