DateFormat   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B dateFormat() 0 20 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sdibble
5
 * Date: 12/12/2016
6
 * Time: 12:11 PM.
7
 */
8
9
namespace SET\Handlers;
10
11
use Carbon\Carbon;
12
13
trait DateFormat
14
{
15
    public function dateFormat($date)
16
    {
17
        if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)) {
18
            return $date;
19
        }
20
21
        if ($date instanceof Carbon || $date instanceof \DateTime) {
22
            return $date->format('Y-m-d');
23
        }
24
25
        // sqlite
26
        if ($carbonDate = \DateTime::createFromFormat('Y-m-d H:i:s', $date)) {
27
            return $carbonDate->format('Y-m-d');
28
        }
29
30
        // JPAS
31
        if ($carbonDate = \DateTime::createFromFormat('n/j/Y G:i', $date)) {
32
            return $carbonDate->format('Y-m-d');
33
        }
34
    }
35
}
36