CallbackAdapter::receive()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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