for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Linio\Component\Input\Transformer;
use Linio\Component\Input\Exception\InvalidConstraintException;
class DateTimeTransformer implements TransformerInterface
{
public function transform($value)
if (empty($value)) {
$this->throwInvalidConstraintExceptionForDateTime($value);
}
try {
$date = new \DateTime($value);
} catch (\Exception $e) {
return $date;
public function throwInvalidConstraintExceptionForDateTime(string $value)
throw new InvalidConstraintException(sprintf(
'Value "%s" is not of type %s',
$value,
\DateTime::class)
);