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

Datetime   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 3
A formatToDatabase() 0 6 2
A getDefaultValue() 0 4 1
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