Passed
Push — master ( f17b13...8bf1e0 )
by Radu
01:33
created

Response   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A toJson() 0 4 1
A toArray() 0 12 2
1
<?php
2
namespace WebServCo\Framework\DataTables;
3
4
class Response implements \WebServCo\Framework\Interfaces\JsonInterface
5
{
6
    protected $draw;
7
8
    protected $recordsTotal;
9
10
    protected $recordsFiltered;
11
12
    protected $data;
13
14
    public function __construct($draw, $recordsTotal, $recordsFiltered, $data = [])
15
    {
16
        $this->draw = $draw;
17
        $this->recordsTotal = $recordsTotal;
18
        $this->recordsFiltered = $recordsFiltered;
19
        $this->data = $data;
20
    }
21
22
    public function toArray()
23
    {
24
        $array = [
25
            'draw' => $this->draw,
26
            'recordsTotal' => $this->recordsTotal,
27
            'recordsFiltered' => $this->recordsFiltered,
28
            'data' => []
29
        ];
30
        foreach ($this->data as $item) {
31
            $array['data'][] = $item;
32
        }
33
        return $array;
34
    }
35
36
    public function toJson()
37
    {
38
        $array = $this->toArray();
39
        return json_encode($array);
40
    }
41
}
42