ParseDate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 5
cts 10
cp 0.5
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseDate() 0 17 5
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