Completed
Push — master ( a51ab2...247c5c )
by Antonio Carlos
03:22
created

Carbon   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 12 2
A serializeUsing() 0 4 1
1
<?php
2
3
namespace IlluminateAgnostic\Str\Support;
4
5
use JsonSerializable;
6
use Carbon\Carbon as BaseCarbon;
7
use IlluminateAgnostic\Str\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 2
    public function jsonSerialize()
26
    {
27 2
        if (static::$serializer) {
28 1
            return call_user_func(static::$serializer, $this);
29
        }
30
31 1
        $carbon = $this;
32
33 1
        return call_user_func(function () use ($carbon) {
34 1
            return get_object_vars($carbon);
35 1
        });
36
    }
37
38
    /**
39
     * JSON serialize all Carbon instances using the given callback.
40
     *
41
     * @param  callable  $callback
42
     * @return void
43
     */
44 9
    public static function serializeUsing($callback)
45
    {
46 9
        static::$serializer = $callback;
47 9
    }
48
}
49