BetfairSerializable::jsonSerialize()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 4
nc 6
nop 0
1
<?php
2
/**
3
 * This file is part of the Betfair library.
4
 *
5
 * (c) Daniele D'Angeli <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Betfair\Model;
11
12
class BetfairSerializable implements \JsonSerializable
13
{
14
    /**
15
     * (PHP 5 &gt;= 5.4.0)<br/>
16
     * Specify data which should be serialized to JSON
17
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
18
     * @return mixed data which can be serialized by <b>json_encode</b>,
19
     * which is a value of any type other than a resource.
20
     */
21
    public function jsonSerialize()
22
    {
23
        $array = array();
24
        $properties = get_object_vars($this);
25
        foreach ($properties as $key => $value) {
26
            if (null !== $value) {
27
                $array[$key] = $value;
28
            }
29
        }
30
31
        if (count($array) == 0) {
32
            return new \StdClass;
33
        }
34
35
        return $array;
36
    }
37
}
38