Passed
Push — master ( c72848...3af666 )
by Stephen
03:25 queued 01:13
created

DateSetter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatetime() 0 2 1
A setDay() 0 3 2
1
<?php
2
3
4
namespace Sfneal\ViewModels\Traits;
5
6
7
use Illuminate\Http\Request;
8
9
trait DateSetter
10
{
11
    /**
12
     * Set a search value for $start or $end property
13
     *
14
     * @param Request $request
15
     * @param string $key
16
     * @param string $time
17
     * @return false|string
18
     */
19
    private function setDay(Request $request, string $key, string $time = '00:00:00') {
20
        if (!is_null($day = $request->input($key))) {
21
            return self::getDatetime($day, $time);
22
        }
23
    }
24
25
    /**
26
     * Retrieve the datetime for a date at midnight
27
     *
28
     * @param string $date
29
     * @param string $time
30
     * @return string
31
     */
32
    private static function getDatetime(string $date, string $time = '00:00:00') {
33
        return date('Y-m-d', strtotime($date)) . ' ' . $time;
34
    }
35
}
36