CallbackAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getNbResults() 0 4 1
A getSlice() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Pagerfanta package.
5
 *
6
 * (c) Pablo Díez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pagerfanta\Adapter;
13
14
use Pagerfanta\Exception\InvalidArgumentException;
15
16
/**
17
 * @author Adrien Brault <[email protected]>
18
 */
19
class CallbackAdapter implements AdapterInterface
20
{
21
    private $getNbResultsCallback;
22
    private $getSliceCallback;
23
24
    /**
25
     * @param callable $getNbResultsCallback
26
     * @param callable $getSliceCallback
27
     */
28 8
    public function __construct($getNbResultsCallback, $getSliceCallback)
29
    {
30 8
        if (!is_callable($getNbResultsCallback)) {
31 2
            throw new InvalidArgumentException('$getNbResultsCallback should be a callable');
32
        }
33 6
        if (!is_callable($getSliceCallback)) {
34 2
            throw new InvalidArgumentException('$getSliceCallback should be a callable');
35
        }
36
37 4
        $this->getNbResultsCallback = $getNbResultsCallback;
38 4
        $this->getSliceCallback = $getSliceCallback;
39 4
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function getNbResults()
45
    {
46 2
        return call_user_func($this->getNbResultsCallback);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 3
    public function getSlice($offset, $length)
53
    {
54 3
        return call_user_func($this->getSliceCallback, $offset, $length);
55
    }
56
}
57