Do not overwrite method configure()

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2018-05-23 12:24:11 +02:00
parent d85668c359
commit 9c81498395
No known key found for this signature in database
GPG key ID: 221E9281655813A6
8 changed files with 41 additions and 59 deletions

View file

@ -30,17 +30,4 @@ final class DateException extends ValidationException
self::STANDARD => '{{name}} must not be a valid date in the format {{sample}}',
],
];
/**
* {@inheritdoc}
*/
public function configure($name, array $params = [])
{
$params['sample'] = date(
$params['format'],
strtotime('2005-12-30')
);
return parent::configure($name, $params);
}
}

View file

@ -13,8 +13,6 @@ declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use function strtotime;
/**
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
* @author Henrique Moody <henriquemoody@gmail.com>
@ -37,19 +35,6 @@ final class DateTimeException extends ValidationException
],
];
/**
* {@inheritdoc}
*/
public function configure($name, array $params = [])
{
$params['sample'] = date(
(string) $params['format'],
strtotime('2005-12-30 01:02:03')
);
return parent::configure($name, $params);
}
/**
* {@inheritdoc}
*/

View file

@ -28,24 +28,6 @@ class IpException extends ValidationException
],
];
public function configure($name, array $params = [])
{
if ($params['networkRange']) {
$range = $params['networkRange'];
$message = $range['min'];
if (isset($range['max'])) {
$message .= '-'.$range['max'];
} else {
$message .= '/'.long2ip((int) $range['mask']);
}
$params['range'] = $message;
}
return parent::configure($name, $params);
}
public function chooseTemplate(): string
{
if (!$this->getParam('networkRange')) {

View file

@ -29,17 +29,4 @@ final class TimeException extends ValidationException
self::STANDARD => '{{name}} must not be a valid time in the format {{sample}}',
],
];
/**
* {@inheritdoc}
*/
public function configure($name, array $params = [])
{
$params['sample'] = date(
$params['format'],
strtotime('23:59:59')
);
return parent::configure($name, $params);
}
}

View file

@ -34,6 +34,11 @@ final class Date extends AbstractRule
*/
private $format;
/**
* @var string
*/
private $sample;
/**
* Initializes the rule.
*
@ -48,6 +53,7 @@ final class Date extends AbstractRule
}
$this->format = $format;
$this->sample = date($format, strtotime('2005-12-30'));
}
/**

View file

@ -32,6 +32,11 @@ final class DateTime extends AbstractRule
*/
private $format;
/**
* @var string
*/
private $sample;
/**
* Initializes the rule.
*
@ -40,6 +45,7 @@ final class DateTime extends AbstractRule
public function __construct(string $format = null)
{
$this->format = $format;
$this->sample = date($format ?: 'c', strtotime('2005-12-30 01:02:03'));
}
/**

View file

@ -19,6 +19,7 @@ class Ip extends AbstractRule
{
public $ipOptions;
public $range;
public $networkRange;
public function __construct($ipOptions = null)
@ -30,6 +31,28 @@ class Ip extends AbstractRule
}
$this->networkRange = $this->parseRange($ipOptions);
$this->range = $this->createRange();
}
/**
* {@inheritdoc}
*/
public function createRange(): ?string
{
if (!$this->networkRange) {
return null;
}
$range = $this->networkRange;
$message = $range['min'];
if (isset($range['max'])) {
$message .= '-'.$range['max'];
} else {
$message .= '/'.long2ip((int) $range['mask']);
}
return $message;
}
protected function parseRange($input)

View file

@ -33,6 +33,11 @@ final class Time extends AbstractRule
*/
private $format;
/**
* @var string
*/
private $sample;
/**
* Initializes the rule.
*
@ -47,6 +52,7 @@ final class Time extends AbstractRule
}
$this->format = $format;
$this->sample = date($format, strtotime('23:59:59'));
}
/**