Skip to content

Commit

Permalink
Rename ValidationKeywordFailed to KeywordMismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
scaytrase committed May 19, 2019
1 parent a46066a commit 251597d
Show file tree
Hide file tree
Showing 39 changed files with 100 additions and 100 deletions.
4 changes: 2 additions & 2 deletions src/PSR7/Exception/Request/RequestQueryArgumentMismatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OpenAPIValidation\PSR7\Exception\NoOperation;
use OpenAPIValidation\PSR7\OperationAddress;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Throwable;
use function implode;
use function sprintf;
Expand All @@ -18,7 +18,7 @@ public static function fromAddrAndCauseException(OperationAddress $addr, Throwab
$i = new self(
sprintf(
"OpenAPI spec does not match the query argument '%s' of the request [%s,%s]: %s",
$cause instanceof ValidationKeywordFailed ? implode('->', $cause->dataBreadCrumb()->buildChain()) : '?',
$cause instanceof KeywordMismatch ? implode('->', $cause->dataBreadCrumb()->buildChain()) : '?',
$addr->path(),
$addr->method(),
$cause->getMessage()
Expand Down
6 changes: 3 additions & 3 deletions src/PSR7/Validators/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use cebe\openapi\spec\Parameter;
use OpenAPIValidation\PSR7\PathAddress;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use OpenAPIValidation\Schema\SchemaValidator;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -19,7 +19,7 @@ class Path
* @param Parameter[] $specs [paramName=>Parameter]
* @param string $pathPattern like "/users/{id}"
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate(MessageInterface $message, array $specs, string $pathPattern) : void
{
Expand All @@ -35,7 +35,7 @@ public function validate(MessageInterface $message, array $specs, string $pathPa
/**
* @param Parameter[] $specs
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
private function validateServerRequest(ServerRequestInterface $message, array $specs, string $pathPattern) : void
{
Expand Down
6 changes: 3 additions & 3 deletions src/PSR7/Validators/QueryArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use cebe\openapi\spec\Parameter;
use OpenAPIValidation\Schema\BreadCrumb;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use OpenAPIValidation\Schema\SchemaValidator;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -20,7 +20,7 @@ class QueryArguments
/**
* @param Parameter[] $specs [queryArgumentName=>schema]
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate(MessageInterface $message, array $specs) : void
{
Expand All @@ -35,7 +35,7 @@ public function validate(MessageInterface $message, array $specs) : void
/**
* @param Parameter[] $specs
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
private function validateServerRequest(ServerRequestInterface $message, array $specs) : void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Throwable;

// Indicates that data was not matched against a schema's keyword
class ValidationKeywordFailed extends SchemaMismatch
class KeywordMismatch extends SchemaMismatch
{
/** @var string */
protected $keyword;

/**
* @param mixed $data
*
* @return ValidationKeywordFailed
* @return KeywordMismatch
*/
public static function fromKeyword(string $keyword, $data, ?string $message = null, ?Throwable $prev = null) : self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Exception/TypeMismatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use function gettype;
use function sprintf;

class TypeMismatch extends ValidationKeywordFailed
class TypeMismatch extends KeywordMismatch
{
/**
* @param mixed $value
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use cebe\openapi\spec\Schema as CebeSchema;
use OpenAPIValidation\Schema\BreadCrumb;
use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use OpenAPIValidation\Schema\Exception\SchemaMismatch;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\SchemaValidator;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
Expand Down Expand Up @@ -40,7 +40,7 @@ public function __construct(CebeSchema $parentSchema, int $type, BreadCrumb $bre
* @param mixed $data
* @param CebeSchema[] $anyOf
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, array $anyOf) : void
{
Expand All @@ -59,7 +59,7 @@ public function validate($data, array $anyOf) : void
}
}

throw ValidationKeywordFailed::fromKeyword('anyOf', $data, 'Data must match at least one schema');
throw KeywordMismatch::fromKeyword('anyOf', $data, 'Data must match at least one schema');
} catch (ExceptionInterface $e) {
throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function count;
Expand All @@ -25,7 +25,7 @@ class Enum extends BaseKeyword
* @param mixed $data
* @param mixed[] $enum - can be strings or numbers
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, array $enum) : void
{
Expand All @@ -34,7 +34,7 @@ public function validate($data, array $enum) : void
Validator::trueVal()->assert(count($enum) >= 1);

if (! in_array($data, $enum, true)) {
throw ValidationKeywordFailed::fromKeyword('enum', $data, 'Value must be present in the enum');
throw KeywordMismatch::fromKeyword('enum', $data, 'Value must be present in the enum');
}
} catch (ExceptionInterface $e) {
throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e);
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MaxItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function count;
Expand All @@ -22,7 +22,7 @@ class MaxItems extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $maxItems) : void
{
Expand All @@ -32,7 +32,7 @@ public function validate($data, int $maxItems) : void
Validator::trueVal()->assert($maxItems >= 0);

if (count($data) > $maxItems) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'maxItems',
$data,
sprintf('Size of an array must be less or equal to %d', $maxItems)
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MaxLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function mb_strlen;
Expand All @@ -27,7 +27,7 @@ class MaxLength extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $maxLength) : void
{
Expand All @@ -37,7 +37,7 @@ public function validate($data, int $maxLength) : void
Validator::trueVal()->assert($maxLength >= 0);

if (mb_strlen($data) > $maxLength) {
throw ValidationKeywordFailed::fromKeyword('maxLength', $data, sprintf("Length of '%d' must be shorter or equal to %d", $data, $maxLength));
throw KeywordMismatch::fromKeyword('maxLength', $data, sprintf("Length of '%d' must be shorter or equal to %d", $data, $maxLength));
}
} catch (ExceptionInterface $e) {
throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e);
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MaxProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function count;
Expand All @@ -22,7 +22,7 @@ class MaxProperties extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $maxProperties) : void
{
Expand All @@ -31,7 +31,7 @@ public function validate($data, int $maxProperties) : void
Validator::trueVal()->assert($maxProperties >= 0);

if (count($data) > $maxProperties) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'maxProperties',
$data,
sprintf("The number of object's properties must be less or equal to %d", $maxProperties)
Expand Down
8 changes: 4 additions & 4 deletions src/Schema/Keywords/Maximum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function sprintf;
Expand Down Expand Up @@ -33,7 +33,7 @@ class Maximum extends BaseKeyword
* @param mixed $data
* @param int|float $maximum
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, $maximum, bool $exclusiveMaximum = false) : void
{
Expand All @@ -42,15 +42,15 @@ public function validate($data, $maximum, bool $exclusiveMaximum = false) : void
Validator::numeric()->assert($maximum);

if ($exclusiveMaximum && $data >= $maximum) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'maximum',
$data,
sprintf('Value %d must be less or equal to %d', $data, $maximum)
);
}

if (! $exclusiveMaximum && $data > $maximum) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'maximum',
$data,
sprintf('Value %d must be less than %d', $data, $maximum)
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MinItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function count;
Expand All @@ -25,7 +25,7 @@ class MinItems extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $minItems) : void
{
Expand All @@ -35,7 +35,7 @@ public function validate($data, int $minItems) : void
Validator::trueVal()->assert($minItems >= 0);

if (count($data) < $minItems) {
throw ValidationKeywordFailed::fromKeyword('minItems', $data, sprintf('Size of an array must be greater or equal to %d', $minItems));
throw KeywordMismatch::fromKeyword('minItems', $data, sprintf('Size of an array must be greater or equal to %d', $minItems));
}
} catch (ExceptionInterface $e) {
throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e);
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MinLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function mb_strlen;
Expand All @@ -28,7 +28,7 @@ class MinLength extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $minLength) : void
{
Expand All @@ -38,7 +38,7 @@ public function validate($data, int $minLength) : void
Validator::trueVal()->assert($minLength >= 0);

if (mb_strlen($data) < $minLength) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'minLength',
$data,
sprintf("Length of '%d' must be longer or equal to %d", $data, $minLength)
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Keywords/MinProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function count;
Expand All @@ -25,7 +25,7 @@ class MinProperties extends BaseKeyword
*
* @param mixed $data
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, int $minProperties) : void
{
Expand All @@ -34,7 +34,7 @@ public function validate($data, int $minProperties) : void
Validator::trueVal()->assert($minProperties >= 0);

if (count($data) < $minProperties) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'minProperties',
$data,
sprintf("The number of object's properties must be greater or equal to %d", $minProperties)
Expand Down
8 changes: 4 additions & 4 deletions src/Schema/Keywords/Minimum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAPIValidation\Schema\Keywords;

use OpenAPIValidation\Schema\Exception\InvalidSchema;
use OpenAPIValidation\Schema\Exception\ValidationKeywordFailed;
use OpenAPIValidation\Schema\Exception\KeywordMismatch;
use Respect\Validation\Exceptions\ExceptionInterface;
use Respect\Validation\Validator;
use function sprintf;
Expand Down Expand Up @@ -33,7 +33,7 @@ class Minimum extends BaseKeyword
* @param mixed $data
* @param int|float $minimum
*
* @throws ValidationKeywordFailed
* @throws KeywordMismatch
*/
public function validate($data, $minimum, bool $exclusiveMinimum = false) : void
{
Expand All @@ -42,15 +42,15 @@ public function validate($data, $minimum, bool $exclusiveMinimum = false) : void
Validator::numeric()->assert($minimum);

if ($exclusiveMinimum && $data <= $minimum) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'minimum',
$data,
sprintf('Value %d must be greater or equal to %d', $data, $minimum)
);
}

if (! $exclusiveMinimum && $data < $minimum) {
throw ValidationKeywordFailed::fromKeyword(
throw KeywordMismatch::fromKeyword(
'minimum',
$data,
sprintf('Value %d must be greater than %d', $data, $minimum)
Expand Down
Loading

0 comments on commit 251597d

Please sign in to comment.