DateSetter::setDay()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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