Completed
Push — master ( 1c3927...202e6d )
by Artem
02:05
created

DataTableResults::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2015 Artem Rodygin
6
//
7
//  This file is part of DataTables Symfony bundle.
8
//
9
//  You should have received a copy of the MIT License along with
10
//  the bundle. If not, see <http://opensource.org/licenses/MIT>.
11
//
12
//----------------------------------------------------------------------
13
14
namespace DataTables;
15
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
/**
19
 * Data to return to DataTables plugin.
20
 *
21
 * @see https://www.datatables.net/manual/server-side
22
 *
23
 * @property    int   $recordsTotal    Total records, before filtering.
24
 * @property    int   $recordsFiltered Total records, after filtering.
25
 * @property    array $data            The data to be displayed in the table.
26
 */
27
class DataTableResults implements \JsonSerializable
28
{
29
    /**
30
     * @Assert\NotNull()
31
     * @Assert\GreaterThanOrEqual(value = "0")
32
     */
33
    public $recordsTotal = 0;
34
35
    /**
36
     * @Assert\NotNull()
37
     * @Assert\GreaterThanOrEqual(value = "0")
38
     */
39
    public $recordsFiltered = 0;
40
41
    /**
42
     * @Assert\NotNull()
43
     * @Assert\Type(type = "array")
44
     */
45
    public $data = [];
46
47
    /**
48
     * @Assert\NotNull()
49
     * @Assert\GreaterThanOrEqual(value = "0")
50
     */
51
    private $draw = 0;
52
53
    /**
54
     * Convert results into array as expected by DataTables plugin.
55
     *
56
     * @return  array
57
     */
58 1
    public function jsonSerialize()
59
    {
60
        return [
61 1
            'draw'            => (int) $this->draw,
62 1
            'recordsTotal'    => (int) $this->recordsTotal,
63 1
            'recordsFiltered' => (int) $this->recordsFiltered,
64 1
            'data'            => $this->data,
65
        ];
66
    }
67
}
68