Completed
Pull Request — master (#52)
by Shawn
09:41 queued 06:50
created

DateFormat   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 3
c 2
b 2
f 0
lcom 0
cbo 1
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A dateFormat() 0 15 3
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
        // Already Y-m-d
18
        if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)) {
19
            return $date;
20
        }
21
22
        //Convert Carbon to Y-m-d
23
        if ($date instanceof Carbon) {
24
            return $date->format('Y-m-d');
25
        }
26
27
        // sqlite Y-m-d H:i:s to Y-m-d
28
        return Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
29
    }
30
}
31