Completed
Push — master ( 467d47...6f2bb4 )
by Anton
14s
created

AbstractSource::getSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
nc 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
c 0
b 0
f 0
cc 2
eloc 4
nop 0
crap 2.0625
rs 9.4285
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Grid\Source;
12
13
use Bluz\Grid\Data;
14
use Bluz\Grid\Grid;
15
use Bluz\Grid\GridException;
16
17
/**
18
 * Adapter
19
 *
20
 * @package  Bluz\Grid
21
 * @author   Anton Shevchuk
22
 */
23
abstract class AbstractSource
24
{
25
    /**
26
     * @var mixed source for build grid
27
     */
28
    protected $source;
29
30
    /**
31
     * @var array available filters
32
     */
33
    protected $filters = [
34
        Grid::FILTER_EQ => '=',
35
        Grid::FILTER_NE => '!=',
36
        Grid::FILTER_GT => '>',
37
        Grid::FILTER_GE => '>=',
38
        Grid::FILTER_LT => '<',
39
        Grid::FILTER_LE => '<=',
40
        Grid::FILTER_LIKE => 'like',
41
    ];
42
43
    /**
44
     * Process source
45
     *
46
     * @param int   $page
47
     * @param int   $limit
48
     * @param array $filters
49
     * @param array $orders
50
     *
51
     * @return Data
52
     */
53
    abstract public function process(int $page, int $limit, array $filters = [], array $orders = []) : Data;
54
55
    /**
56
     * Setup source adapter
57
     *
58
     * @param  mixed $source
59
     *
60
     * @return void
61
     */
62 34
    public function setSource($source) : void
63
    {
64 34
        $this->source = $source;
65 34
    }
66
67
    /**
68
     * Get source adapter
69
     *
70
     * @return mixed
71
     * @throws GridException
72
     */
73 14
    public function getSource()
74
    {
75 14
        if (!$this->source) {
76
            throw new GridException('Source Adapter should be initialized by `setSource` method');
77
        }
78 14
        return $this->source;
79
    }
80
}
81