Passed
Push — develop ( c34e50...445d6d )
by Paul
06:42
created

SanitizeDate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 7
eloc 11
dl 0
loc 17
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 15 7
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Sanitizers;
4
5
use GeminiLabs\SiteReviews\Modules\Date;
6
7
class SanitizeDate extends StringSanitizer
8
{
9 43
    public function run(): string
10
    {
11 43
        $date = $this->value();
12 43
        $format = empty($this->args[0]) ? 'Y-m-d H:i:s' : $this->args[0];
13 43
        if (glsr(Date::class)->isDate($date, $format)) {
14 17
            return $date;
15
        }
16 43
        if (glsr(Date::class)->isTimestamp($date)) {
17
            return wp_date($format, (int) $date) ?: '';
18
        }
19 43
        $timestamp = strtotime($date);
20 43
        if (false === $timestamp) {
21 43
            return '';
22
        }
23 1
        return wp_date($format, $timestamp) ?: '';
24
    }
25
}
26