Convert message keys to string

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2018-05-23 10:07:41 +02:00
parent c26db7287f
commit d85668c359
No known key found for this signature in database
GPG key ID: 221E9281655813A6
20 changed files with 56 additions and 54 deletions

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class AlphaException extends ValidationException
{
public const EXTRA = 1;
public const EXTRA = 'extra';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -28,7 +28,7 @@ class AlphaException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('additionalChars') ? static::EXTRA : static::STANDARD;
}

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class AlwaysInvalidException extends ValidationException
{
public const SIMPLE = 1;
public const SIMPLE = 'simple';
public static $defaultTemplates = [
self::MODE_DEFAULT => [

View file

@ -15,8 +15,9 @@ namespace Respect\Validation\Exceptions;
class AttributeException extends NestedValidationException implements NonOmissibleExceptionInterface
{
public const NOT_PRESENT = 0;
public const INVALID = 1;
public const NOT_PRESENT = 'not_present';
public const INVALID = 'invalid';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::NOT_PRESENT => 'Attribute {{name}} must be present',
@ -28,7 +29,7 @@ class AttributeException extends NestedValidationException implements NonOmissib
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('hasReference') ? static::INVALID : static::NOT_PRESENT;
}

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class CreditCardException extends ValidationException
{
public const BRANDED = 1;
public const BRANDED = 'branded';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -28,7 +28,7 @@ class CreditCardException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
if (!$this->getParam('brand')) {
return static::STANDARD;

View file

@ -21,7 +21,7 @@ use function strtotime;
*/
final class DateTimeException extends ValidationException
{
public const FORMAT = 1;
public const FORMAT = 'format';
/**
* {@inheritdoc}
@ -53,7 +53,7 @@ final class DateTimeException extends ValidationException
/**
* {@inheritdoc}
*/
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('format') ? static::FORMAT : static::STANDARD;
}

View file

@ -15,8 +15,8 @@ namespace Respect\Validation\Exceptions;
class GroupedValidationException extends NestedValidationException
{
public const NONE = 0;
public const SOME = 1;
public const NONE = 'none';
public const SOME = 'some';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -29,7 +29,7 @@ class GroupedValidationException extends NestedValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
$numRules = $this->getParam('passed');
$numFailed = $this->getRelated()->count();

View file

@ -15,8 +15,7 @@ namespace Respect\Validation\Exceptions;
class IpException extends ValidationException
{
public const STANDARD = 0;
public const NETWORK_RANGE = 1;
public const NETWORK_RANGE = 'network_range';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -47,7 +46,7 @@ class IpException extends ValidationException
return parent::configure($name, $params);
}
public function chooseTemplate()
public function chooseTemplate(): string
{
if (!$this->getParam('networkRange')) {
return static::STANDARD;

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class KeySetException extends GroupedValidationException implements NonOmissibleExceptionInterface
{
public const STRUCTURE = 2;
public const STRUCTURE = 'structure';
/**
* @var array
@ -36,7 +36,7 @@ class KeySetException extends GroupedValidationException implements NonOmissible
/**
* {@inheritdoc}
*/
public function chooseTemplate()
public function chooseTemplate(): string
{
if (0 === $this->getRelated()->count()) {
return static::STRUCTURE;

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class KeyValueException extends ValidationException
{
public const COMPONENT = 1;
public const COMPONENT = 'component';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -28,7 +28,7 @@ class KeyValueException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('component') ? static::COMPONENT : static::STANDARD;
}

View file

@ -15,10 +15,10 @@ namespace Respect\Validation\Exceptions;
class LengthException extends ValidationException
{
public const BOTH = 0;
public const LOWER = 1;
public const GREATER = 2;
public const EXACT = 3;
public const BOTH = 'both';
public const LOWER = 'lower';
public const GREATER = 'greater';
public const EXACT = 'exact';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -35,7 +35,7 @@ class LengthException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
if (!$this->getParam('minValue')) {
return static::GREATER;

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class MaxException extends ValidationException
{
public const INCLUSIVE = 1;
public const INCLUSIVE = 'inclusive';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -28,7 +28,7 @@ class MaxException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD;
}

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class MinException extends ValidationException
{
public const INCLUSIVE = 1;
public const INCLUSIVE = 'inclusive';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -28,7 +28,7 @@ class MinException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->getParam('inclusive') ? static::INCLUSIVE : static::STANDARD;
}

View file

@ -15,8 +15,7 @@ namespace Respect\Validation\Exceptions;
class NotBlankException extends ValidationException
{
public const STANDARD = 0;
public const NAMED = 1;
public const NAMED = 'named';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -29,7 +28,7 @@ class NotBlankException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->hasName() ? static::NAMED : static::STANDARD;
}

View file

@ -19,8 +19,8 @@ namespace Respect\Validation\Exceptions;
*/
final class NotEmptyException extends ValidationException
{
public const STANDARD = 0;
public const NAMED = 1;
public const NAMED = 'named';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'The value must not be empty',
@ -32,7 +32,7 @@ final class NotEmptyException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->hasName() ? static::NAMED : static::STANDARD;
}

View file

@ -15,8 +15,7 @@ namespace Respect\Validation\Exceptions;
class NotOptionalException extends ValidationException
{
public const STANDARD = 0;
public const NAMED = 1;
public const NAMED = 'named';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -29,7 +28,7 @@ class NotOptionalException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->hasName() ? static::NAMED : static::STANDARD;
}

View file

@ -18,8 +18,7 @@ namespace Respect\Validation\Exceptions;
*/
final class NullableException extends ValidationException
{
public const STANDARD = 0;
public const NAMED = 1;
public const NAMED = 'named';
/**
* {@inheritdoc}
@ -38,7 +37,7 @@ final class NullableException extends ValidationException
/**
* {@inheritdoc}
*/
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->hasName() ? static::NAMED : static::STANDARD;
}

View file

@ -15,8 +15,7 @@ namespace Respect\Validation\Exceptions;
class OptionalException extends ValidationException
{
public const STANDARD = 0;
public const NAMED = 1;
public const NAMED = 'named';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -29,7 +28,7 @@ class OptionalException extends ValidationException
],
];
public function chooseTemplate()
public function chooseTemplate(): string
{
return $this->hasName() ? static::NAMED : static::STANDARD;
}

View file

@ -20,9 +20,9 @@ namespace Respect\Validation\Exceptions;
*/
class SizeException extends NestedValidationException
{
public const BOTH = 0;
public const LOWER = 1;
public const GREATER = 2;
public const BOTH = 'both';
public const LOWER = 'lower';
public const GREATER = 'greater';
/**
* {@inheritdoc}
@ -43,7 +43,7 @@ class SizeException extends NestedValidationException
/**
* {@inheritdoc}
*/
public function chooseTemplate(): int
public function chooseTemplate(): string
{
if (!$this->getParam('minValue')) {
return static::GREATER;

View file

@ -20,9 +20,15 @@ use function Respect\Stringifier\stringify;
class ValidationException extends InvalidArgumentException implements ExceptionInterface
{
public const MODE_DEFAULT = 1;
public const MODE_NEGATIVE = 2;
public const STANDARD = 0;
public const MODE_DEFAULT = 'default';
public const MODE_NEGATIVE = 'negative';
public const STANDARD = 'standard';
/**
* Contains the default templates for exception message.
*
* @var array
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be valid',
@ -64,7 +70,7 @@ class ValidationException extends InvalidArgumentException implements ExceptionI
return $this->getMainMessage();
}
public function chooseTemplate()
public function chooseTemplate(): string
{
return key(static::$defaultTemplates[$this->mode]);
}

View file

@ -15,7 +15,7 @@ namespace Respect\Validation\Exceptions;
class VideoUrlException extends ValidationException
{
public const SERVICE = 1;
public const SERVICE = 'service';
public static $defaultTemplates = [
self::MODE_DEFAULT => [
@ -31,7 +31,7 @@ class VideoUrlException extends ValidationException
/**
* {@inheritdoc}
*/
public function chooseTemplate()
public function chooseTemplate(): string
{
if (false !== $this->getParam('service')) {
return self::SERVICE;