Passed
Push — master ( 4c5faf...429320 )
by Chris
04:23
created

FormSubmissionCallback   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 46
ccs 0
cts 19
cp 0
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallbacks() 0 3 1
A __construct() 0 3 1
A process() 0 7 2
A addCallBack() 0 5 1
1
<?php
2
3
namespace WebTheory\Saveyour\Processors;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use WebTheory\Saveyour\Contracts\FormDataProcessingCacheInterface;
7
use WebTheory\Saveyour\Contracts\FormDataProcessorInterface;
8
9
class FormSubmissionCallback extends AbstractFormDataProcessor implements FormDataProcessorInterface
10
{
11
    /**
12
     * @var callable[]
13
     */
14
    protected $callbacks = [];
15
16
    public function __construct(callable ...$callbacks)
17
    {
18
        $this->callbacks = $callbacks;
19
    }
20
21
    /**
22
     * Get the value of callbacks
23
     *
24
     * @return callable[]
25
     */
26
    public function getCallbacks(): array
27
    {
28
        return $this->callbacks;
29
    }
30
31
    /**
32
     * add a callback function
33
     *
34
     * @param callable $callback
35
     *
36
     * @return self
37
     */
38
    public function addCallBack(callable $callback)
39
    {
40
        $this->callbacks[] = $callback;
41
42
        return $this;
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function process(ServerRequestInterface $request, array $results): ?FormDataProcessingCacheInterface
49
    {
50
        foreach ($this->callbacks as $cb) {
51
            $cb($request, $results);
52
        }
53
54
        return null;
55
    }
56
}
57