Test Failed
Push — main ( 8c8b4f...d1ea7b )
by Paul
12:11 queued 05:48
created

SanitizeDate::run()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7.0283

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 10
c 2
b 1
f 0
dl 0
loc 15
ccs 11
cts 12
cp 0.9167
rs 8.8333
cc 7
nc 8
nop 0
crap 7.0283
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Sanitizers;
4
5
use GeminiLabs\SiteReviews\Modules\Date;
6
7 34
class SanitizeDate extends StringSanitizer
8
{
9 34
    public function run(): string
10 34
    {
11 34
        $date = $this->value();
12 34
        $format = empty($this->args[0]) ? 'Y-m-d H:i:s' : $this->args[0];
13 24
        if (glsr(Date::class)->isDate($date, $format)) {
14
            return $date;
15 34
        }
16 34
        if (glsr(Date::class)->isTimestamp($date)) {
17 34
            return wp_date($format, (int) $date) ?: '';
18
        }
19 1
        $timestamp = strtotime($date);
20 1
        if (false === $timestamp) {
21
            return '';
22
        }
23 1
        return wp_date($format, $timestamp) ?: '';
24
    }
25
}
26