CarbonCast::setAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\Casts;
4
5
use Carbon\Carbon;
6
use DateTime;
7
use Exception;
8
use Vkovic\LaravelCustomCasts\CustomCastBase;
9
10
class CarbonCast extends CustomCastBase
11
{
12
    /**
13
     * Store value as time code string.
14
     *
15
     * @param  mixed  $value
16
     * @return DateTime
17
     */
18
    public function setAttribute($value): ?DateTime
19
    {
20
        return $value;
21
    }
22
23
    /**
24
     * Retrieve value as Carbon instance.
25
     *
26
     * @param  mixed  $value
27
     * @return Carbon
28
     *
29
     * @throws Exception
30
     */
31
    public function castAttribute($value): ?Carbon
32
    {
33
        return ! is_null($value) ? new Carbon($value) : null;
34
    }
35
}
36