ParseDate::parseDate()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 8.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 17
ccs 5
cts 10
cp 0.5
crap 8.125
rs 9.6111
1
<?php
2
3
namespace Ianrizky\MoslemPray\Support;
4
5
use Illuminate\Support\Carbon;
6
use InvalidArgumentException;
7
8
trait ParseDate
9
{
10
    /**
11
     * Parse the given date into a Carbon instance.
12
     *
13
     * @param  mixed  $date
14
     * @return \Illuminate\Support\Carbon
15
     *
16
     * @throws \InvalidArgumentException
17
     */
18 2
    protected static function parseDate($date): Carbon
19
    {
20 2
        if ($date instanceof Carbon) {
21
            return $date;
22
        }
23
24 2
        if (is_string($date)) {
25
            return Carbon::parse($date);
26
        }
27
28 2
        if (is_null($date)) {
29 2
            return Carbon::today();
30
        }
31
32
        throw new InvalidArgumentException(sprintf(
33
            'Parameter $date must be a string or %s instance. %s given.',
34
            Carbon::class, is_object($date) ? get_class($date) : gettype($date)
35
        ));
36
    }
37
}
38