SayHello   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 12
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 5 1
1
<?php
2
3
namespace Examples;
4
5
use AlexManno\Remix\Pipelines\Interfaces\PayloadInterface;
6
use AlexManno\Remix\Pipelines\Interfaces\StageInterface;
7
use AlexManno\Remix\Pipelines\Pipeline;
8
use AlexManno\Remix\Pipelines\SimplePayload;
9
10
require_once __DIR__ . '/../vendor/autoload.php';
11
12
class SayHello implements StageInterface
13
{
14
    /**
15
     * @param PayloadInterface $payload
16
     *
17
     * @return PayloadInterface
18
     */
19
    public function __invoke(PayloadInterface $payload): PayloadInterface
20
    {
21
        $payload->setData('Hello!');
22
23
        return $payload;
24
    }
25
}
26
27
class SayMyNameIsAlessandro implements StageInterface
28
{
29
    /**
30
     * @param PayloadInterface $payload
31
     *
32
     * @return PayloadInterface
33
     */
34
    public function __invoke(PayloadInterface $payload): PayloadInterface
35
    {
36
        $data = $payload->getData();
37
        $payload->setData($data . ' My name is Alessandro');
38
39
        return $payload;
40
    }
41
}
42
43
44
$pipeline = new Pipeline();
45
$payload = new SimplePayload();
46
47
$pipeline
48
    ->pipe(new SayHello)                // Append "Hello!" to TextState
49
    ->pipe(new SayMyNameIsAlessandro);  // Append "My name is Alessandro" to TextState
50
$payload = $pipeline($payload);         // Pass an initial State
51
52
echo $payload->getData();               // Print: Hello! My name is Alessandro!
53