noregression/callable-comparator

View on GitHub
src/PHPUnit/Comparator/Callables/IsDateTime.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace NoRegression\PHPUnit\Comparator\Callables;

use \SebastianBergmann\Comparator\ComparisonFailure;

class IsDateTime extends BaseCallable
{
    public function isValid($actual)
    {
        $parsedDate = date_parse($actual);
        $isValid = (bool)$parsedDate && $parsedDate['error_count'] === 0 && $parsedDate['warning_count'] === 0;

        if ($isValid) {
            return $this->isValid = true;
        }

        throw new ComparisonFailure(
            (string)$this,
            $actual,
            '',
            '',
            false,
            sprintf('Failed asserting that \'%s\' is a valid DateTime', $actual)
        );
    }
}