Completed
Push — master ( 78beec...4922f7 )
by Antonio Carlos
02:16
created

Carbon::__set_state()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace IlluminateAgnostic\Arr\Support;
4
5
use JsonSerializable;
6
use Carbon\Carbon as BaseCarbon;
7
use IlluminateAgnostic\Arr\Support\Traits\Macroable;
8
9
class Carbon extends BaseCarbon implements JsonSerializable
10
{
11
    use Macroable;
12
13
    /**
14
     * The custom Carbon JSON serializer.
15
     *
16
     * @var callable|null
17
     */
18
    protected static $serializer;
19
20
    /**
21
     * Prepare the object for JSON serialization.
22
     *
23
     * @return array|string
24
     */
25
    public function jsonSerialize()
26
    {
27
        if (static::$serializer) {
28
            return call_user_func(static::$serializer, $this);
29
        }
30
31
        $carbon = $this;
32
33
        return call_user_func(function () use ($carbon) {
34
            return get_object_vars($carbon);
35
        });
36
    }
37
38
    /**
39
     * JSON serialize all Carbon instances using the given callback.
40
     *
41
     * @param  callable  $callback
42
     * @return void
43
     */
44
    public static function serializeUsing($callback)
45
    {
46
        static::$serializer = $callback;
47
    }
48
}
49