Ensured dates parsing does not mask actual validation errors

This commit is contained in:
Alejandro Celaya
2019-12-06 22:38:22 +01:00
parent 30780f9c5f
commit 05a64b8d9e
4 changed files with 22 additions and 18 deletions

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Rest\Action\ShortUrl;
use Cake\Chronos\Chronos;
use Psr\Http\Message\ServerRequestInterface as Request;
use Shlinkio\Shlink\Core\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Core\Exception\ValidationException;
@@ -32,8 +31,8 @@ class CreateShortUrlAction extends AbstractCreateShortUrlAction
try {
$meta = ShortUrlMeta::createFromParams(
$this->getOptionalDate($postData, 'validSince'),
$this->getOptionalDate($postData, 'validUntil'),
$postData['validSince'] ?? null,
$postData['validUntil'] ?? null,
$postData['customSlug'] ?? null,
$postData['maxVisits'] ?? null,
$postData['findIfExists'] ?? null,
@@ -45,9 +44,4 @@ class CreateShortUrlAction extends AbstractCreateShortUrlAction
throw new InvalidArgumentException('Provided meta data is not valid', -1, $e);
}
}
private function getOptionalDate(array $postData, string $fieldName): ?Chronos
{
return isset($postData[$fieldName]) ? Chronos::parse($postData[$fieldName]) : null;
}
}