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

Response::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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