Skip to content

Commit 965b5d7

Browse files
committed
Switch processor argument order
Allows variadic type checking.
1 parent 64fb0cd commit 965b5d7

7 files changed

+23
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
* Now requires PHP 7.1 or newer.
1212
* Pipeline requires processor as first argument.
13+
* Processor requires payload as first argument.
1314

1415
## 0.3.0 - 2016-10-13
1516

spec/FingersCrossedProcessorSpec.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function it_is_initializable()
1515

1616
function it_should_process_stages()
1717
{
18-
$this->process([
18+
$this->process(
19+
2,
1920
function ($payload) { return $payload * 2; }
20-
], 2)->shouldBe(4);
21+
)->shouldBe(4);
2122
}
2223
}

spec/InterruptibleProcessorSpec.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ function let()
2121

2222
function it_should_interrupt()
2323
{
24-
$this->process([
24+
$this->process(
25+
5,
2526
function ($payload) { return $payload + 2; },
2627
function ($payload) { return $payload * 10; },
27-
function ($payload) { return $payload * 10; },
28-
], 5)->shouldBe(70);
28+
function ($payload) { return $payload * 10; }
29+
)->shouldBe(70);
2930

30-
$this->process([
31-
function ($payload) { return $payload + 2; },
32-
], 5)->shouldBe(7);
31+
$this->process(
32+
5,
33+
function ($payload) { return $payload + 2; }
34+
)->shouldBe(7);
3335
}
3436
}

src/FingersCrossedProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
class FingersCrossedProcessor implements ProcessorInterface
77
{
8-
public function process(array $stages, $payload)
8+
public function process($payload, callable ...$stages)
99
{
1010
foreach ($stages as $stage) {
11-
$payload = call_user_func($stage, $payload);
11+
$payload = $stage($payload);
1212
}
1313

1414
return $payload;

src/InterruptibleProcessor.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ public function __construct(callable $check)
1515
$this->check = $check;
1616
}
1717

18-
public function process(array $stages, $payload)
18+
public function process($payload, callable ...$stages)
1919
{
20+
$check = $this->check;
21+
2022
foreach ($stages as $stage) {
21-
$payload = call_user_func($stage, $payload);
23+
$payload = $stage($payload);
2224

23-
if (true !== call_user_func($this->check, $payload)) {
25+
if (true !== $check($payload)) {
2426
return $payload;
2527
}
2628
}

src/Pipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function pipe(callable $stage): PipelineInterface
3131

3232
public function process($payload)
3333
{
34-
return $this->processor->process($this->stages, $payload);
34+
return $this->processor->process($payload, ...$this->stages);
3535
}
3636

3737
public function __invoke($payload)

src/ProcessorInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
interface ProcessorInterface
77
{
88
/**
9-
* @param array $stages
9+
* Process the payload using multiple stages.
10+
*
1011
* @param mixed $payload
1112
*
1213
* @return mixed
1314
*/
14-
public function process(array $stages, $payload);
15+
public function process($payload, callable ...$stages);
1516
}

0 commit comments

Comments
 (0)