Completed
Push — master ( 7c9586...c8ce39 )
by Oscar
01:44
created

Datetime::getDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SimpleCrud\Fields;
4
5
class Datetime extends Field
6
{
7
    protected $format = 'Y-m-d H:i:s';
8
9
    public function format($value): ?\Datetime
10
    {
11
        if ($value instanceof \Datetime) {
12
            return $value;
13
        }
14
15
        return $value ? new \Datetime($value) : null;
16
    }
17
18
    protected function formatToDatabase($value): ?string
19
    {
20
        $value = $this->format($value);
21
22
        return empty($value) ? null : $value->format($this->format);
23
    }
24
25
    /**
26
     * Return the default value
27
     */
28
    public function getDefaultValue()
29
    {
30
        return null;
31
    }
32
}
33