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

SanitizeDate::run()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.0368

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 15
ccs 10
cts 11
cp 0.9091
rs 8.8333
c 0
b 0
f 0
cc 7
nc 8
nop 0
crap 7.0368
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