TapCallbacks::onRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LazyJsonPages\Services;
6
7
use Closure;
8
9
/**
10
 * The collection of callbacks to run by the tap middleware.
11
 */
12
final class TapCallbacks
13
{
14
    /**
15
     * The callbacks to handle the sending request.
16
     *
17
     * @var Closure[]
18
     */
19
    private array $onRequestCallbacks = [];
20
21
    /**
22
     * The callbacks to handle the received response.
23
     *
24
     * @var Closure[]
25
     */
26
    private array $onResponseCallbacks = [];
27
28
    /**
29
     * The callbacks to handle a transaction error.
30
     *
31
     * @var Closure[]
32
     */
33
    private array $onErrorCallbacks = [];
34
35
    /**
36
     * Add the given callback to handle the sending request.
37
     *
38
     * @param Closure $callback
39
     */
40 5
    public function onRequest(Closure $callback): self
41
    {
42 5
        $this->onRequestCallbacks[] = $callback;
43
44 5
        return $this;
45
    }
46
47
    /**
48
     * Add the given callback to handle the received response.
49
     */
50 4
    public function onResponse(Closure $callback): self
51
    {
52 4
        $this->onResponseCallbacks[] = $callback;
53
54 4
        return $this;
55
    }
56
57
    /**
58
     * Add the given callback to handle a transaction error.
59
     */
60 3
    public function onError(Closure $callback): self
61
    {
62 3
        $this->onErrorCallbacks[] = $callback;
63
64 3
        return $this;
65
    }
66
67
    /**
68
     * Retrieve the callbacks to handle the sending request.
69
     *
70
     * @return Closure[]
71
     */
72 6
    public function onRequestCallbacks(): array
73
    {
74 6
        return $this->onRequestCallbacks;
75
    }
76
77
    /**
78
     * Retrieve the callbacks to handle the received response.
79
     *
80
     * @return Closure[]
81
     */
82 4
    public function onResponseCallbacks(): array
83
    {
84 4
        return $this->onResponseCallbacks;
85
    }
86
87
    /**
88
     * Retrieve the callbacks to handle a transaction error.
89
     *
90
     * @return Closure[]
91
     */
92 2
    public function onErrorCallbacks(): array
93
    {
94 2
        return $this->onErrorCallbacks;
95
    }
96
}
97