AbstractSource   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 56
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

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