CallbackAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 0
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A receive() 0 6 2
A send() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Adapter;
11
12
use Transfer\Adapter\Transaction\Request;
13
14
/**
15
 * Source and target adapter implementation with callback support.
16
 */
17
class CallbackAdapter implements SourceAdapterInterface, TargetAdapterInterface
18
{
19
    /**
20
     * @var callback Receive callback
21
     */
22
    protected $receiveCallback;
23
24
    /**
25
     * @var callback Send callback
26
     */
27
    protected $sendCallback;
28
29
    /**
30
     * @param callback|null $receiveCallback Receive callback
31
     * @param callback|null $sendCallback    Send callback
32
     */
33 11
    public function __construct($receiveCallback = null, $sendCallback = null)
34
    {
35 11
        $this->receiveCallback = $receiveCallback;
36 11
        $this->sendCallback = $sendCallback;
37 11
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 10
    public function receive(Request $request)
43
    {
44 10
        if (is_callable($this->receiveCallback)) {
45 9
            return call_user_func_array($this->receiveCallback, array($request));
46
        }
47 1
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 8
    public function send(Request $request)
53
    {
54 8
        if (is_callable($this->sendCallback)) {
55 7
            return call_user_func_array($this->sendCallback, array($request));
56
        }
57 1
    }
58
}
59