Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rename exceptions #668

Merged
merged 1 commit into from Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ For a full diff see [`2.2.0...3.0.0`][2.2.0...3.0.0].

- Required `ergebnis/json-schema-validator:^3.0.0` ([#666]), by [@dependabot]
- Renamed `Exception\ExceptionInterface` to `Exception\Exception` ([#667]), by [@dependabot]
- Removed `Exception` suffix from all exceptions ([#668]), by [@dependabot]

## [`2.2.0`][2.2.0]

Expand Down Expand Up @@ -489,6 +490,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0].
[#641]: https://github.com/ergebnis/json-normalizer/pull/641
[#666]: https://github.com/ergebnis/json-normalizer/pull/666
[#667]: https://github.com/ergebnis/json-normalizer/pull/667
[#668]: https://github.com/ergebnis/json-normalizer/pull/668

[@BackEndTea]: https://github.com/BackEndTea
[@dependabot]: https://github.com/dependabot
Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidIndentSizeException extends \InvalidArgumentException implements Exception
final class InvalidIndentSize extends \InvalidArgumentException implements Exception
{
private int $size = 0;
private int $minimumSize = 0;
Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidIndentStringException extends \InvalidArgumentException implements Exception
final class InvalidIndentString extends \InvalidArgumentException implements Exception
{
private string $string = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidIndentStyleException extends \InvalidArgumentException implements Exception
final class InvalidIndentStyle extends \InvalidArgumentException implements Exception
{
private string $style = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidJsonEncodeOptionsException extends \InvalidArgumentException implements Exception
final class InvalidJsonEncodeOptions extends \InvalidArgumentException implements Exception
{
private int $jsonEncodeOptions = 0;

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidJsonEncodedException extends \InvalidArgumentException implements Exception
final class InvalidJsonEncoded extends \InvalidArgumentException implements Exception
{
private string $encoded = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class InvalidNewLineStringException extends \InvalidArgumentException implements Exception
final class InvalidNewLineString extends \InvalidArgumentException implements Exception
{
private string $string = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class NormalizedInvalidAccordingToSchemaException extends \RuntimeException implements Exception
final class NormalizedInvalidAccordingToSchema extends \RuntimeException implements Exception
{
private string $schemaUri = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class OriginalInvalidAccordingToSchemaException extends \RuntimeException implements Exception
final class OriginalInvalidAccordingToSchema extends \RuntimeException implements Exception
{
private string $schemaUri = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class SchemaUriCouldNotBeReadException extends \RuntimeException implements Exception
final class SchemaUriCouldNotBeRead extends \RuntimeException implements Exception
{
private string $schemaUri = '';

Expand Down
Expand Up @@ -13,7 +13,7 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class SchemaUriCouldNotBeResolvedException extends \RuntimeException implements Exception
final class SchemaUriCouldNotBeResolved extends \RuntimeException implements Exception
{
private string $schemaUri = '';

Expand Down
Expand Up @@ -13,14 +13,14 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class SchemaUriReferencesInvalidJsonDocumentException extends \RuntimeException implements Exception
final class SchemaUriReferencesDocumentWithInvalidMediaType extends \RuntimeException implements Exception
{
private string $schemaUri = '';

public static function fromSchemaUri(string $schemaUri): self
{
$exception = new self(\sprintf(
'Schema URI "%s" does not reference a document with valid JSON syntax.',
'Schema URI "%s" does not reference a document with media type "application/schema+json".',
$schemaUri,
));

Expand Down
Expand Up @@ -13,14 +13,14 @@

namespace Ergebnis\Json\Normalizer\Exception;

final class SchemaUriReferencesDocumentWithInvalidMediaTypeException extends \RuntimeException implements Exception
final class SchemaUriReferencesInvalidJsonDocument extends \RuntimeException implements Exception
{
private string $schemaUri = '';

public static function fromSchemaUri(string $schemaUri): self
{
$exception = new self(\sprintf(
'Schema URI "%s" does not reference a document with media type "application/schema+json".',
'Schema URI "%s" does not reference a document with valid JSON syntax.',
$schemaUri,
));

Expand Down
12 changes: 6 additions & 6 deletions src/Format/Indent.php
Expand Up @@ -33,20 +33,20 @@ private function __construct(string $value)
}

/**
* @throws Exception\InvalidIndentStringException
* @throws Exception\InvalidIndentString
*/
public static function fromString(string $value): self
{
if (1 !== \preg_match('/^( *|\t+)$/', $value)) {
throw Exception\InvalidIndentStringException::fromString($value);
throw Exception\InvalidIndentString::fromString($value);
}

return new self($value);
}

/**
* @throws Exception\InvalidIndentSizeException
* @throws Exception\InvalidIndentStyleException
* @throws Exception\InvalidIndentSize
* @throws Exception\InvalidIndentStyle
*/
public static function fromSizeAndStyle(
int $size,
Expand All @@ -55,14 +55,14 @@ public static function fromSizeAndStyle(
$minimumSize = 1;

if ($minimumSize > $size) {
throw Exception\InvalidIndentSizeException::fromSizeAndMinimumSize(
throw Exception\InvalidIndentSize::fromSizeAndMinimumSize(
$size,
$minimumSize,
);
}

if (!\array_key_exists($style, self::CHARACTERS)) {
throw Exception\InvalidIndentStyleException::fromStyleAndAllowedStyles(
throw Exception\InvalidIndentStyle::fromStyleAndAllowedStyles(
$style,
...\array_keys(self::CHARACTERS),
);
Expand Down
4 changes: 2 additions & 2 deletions src/Format/JsonEncodeOptions.php
Expand Up @@ -29,12 +29,12 @@ private function __construct(int $value)
}

/**
* @throws Exception\InvalidJsonEncodeOptionsException
* @throws Exception\InvalidJsonEncodeOptions
*/
public static function fromInt(int $value): self
{
if (0 > $value) {
throw Exception\InvalidJsonEncodeOptionsException::fromJsonEncodeOptions($value);
throw Exception\InvalidJsonEncodeOptions::fromJsonEncodeOptions($value);
}

return new self($value);
Expand Down
4 changes: 2 additions & 2 deletions src/Format/NewLine.php
Expand Up @@ -29,12 +29,12 @@ private function __construct(string $value)
}

/**
* @throws Exception\InvalidNewLineStringException
* @throws Exception\InvalidNewLineString
*/
public static function fromString(string $value): self
{
if (1 !== \preg_match('/^(?>\r\n|\n|\r)$/', $value)) {
throw Exception\InvalidNewLineStringException::fromString($value);
throw Exception\InvalidNewLineString::fromString($value);
}

return new self($value);
Expand Down
4 changes: 2 additions & 2 deletions src/Json.php
Expand Up @@ -34,7 +34,7 @@ private function __construct(
}

/**
* @throws Exception\InvalidJsonEncodedException
* @throws Exception\InvalidJsonEncoded
*/
public static function fromEncoded(string $encoded): self
{
Expand All @@ -46,7 +46,7 @@ public static function fromEncoded(string $encoded): self
\JSON_THROW_ON_ERROR,
);
} catch (\JsonException $exception) {
throw Exception\InvalidJsonEncodedException::fromEncoded($encoded);
throw Exception\InvalidJsonEncoded::fromEncoded($encoded);
}

return new self(
Expand Down
12 changes: 6 additions & 6 deletions src/NormalizerInterface.php
Expand Up @@ -16,12 +16,12 @@
interface NormalizerInterface
{
/**
* @throws Exception\SchemaUriCouldNotBeResolvedException
* @throws Exception\SchemaUriCouldNotBeReadException
* @throws Exception\SchemaUriReferencesDocumentWithInvalidMediaTypeException
* @throws Exception\SchemaUriReferencesInvalidJsonDocumentException
* @throws Exception\OriginalInvalidAccordingToSchemaException
* @throws Exception\NormalizedInvalidAccordingToSchemaException
* @throws Exception\SchemaUriCouldNotBeResolved
* @throws Exception\SchemaUriCouldNotBeRead
* @throws Exception\SchemaUriReferencesDocumentWithInvalidMediaType
* @throws Exception\SchemaUriReferencesInvalidJsonDocument
* @throws Exception\OriginalInvalidAccordingToSchema
* @throws Exception\NormalizedInvalidAccordingToSchema
*/
public function normalize(Json $json): Json;
}
12 changes: 6 additions & 6 deletions src/SchemaNormalizer.php
Expand Up @@ -42,13 +42,13 @@ public function normalize(Json $json): Json
try {
$schema = $this->schemaStorage->getSchema($this->schemaUri);
} catch (UriResolverException $exception) {
throw Exception\SchemaUriCouldNotBeResolvedException::fromSchemaUri($this->schemaUri);
throw Exception\SchemaUriCouldNotBeResolved::fromSchemaUri($this->schemaUri);
} catch (ResourceNotFoundException $exception) {
throw Exception\SchemaUriCouldNotBeReadException::fromSchemaUri($this->schemaUri);
throw Exception\SchemaUriCouldNotBeRead::fromSchemaUri($this->schemaUri);
} catch (InvalidSchemaMediaTypeException $exception) {
throw Exception\SchemaUriReferencesDocumentWithInvalidMediaTypeException::fromSchemaUri($this->schemaUri);
throw Exception\SchemaUriReferencesDocumentWithInvalidMediaType::fromSchemaUri($this->schemaUri);
} catch (JsonDecodingException $exception) {
throw Exception\SchemaUriReferencesInvalidJsonDocumentException::fromSchemaUri($this->schemaUri);
throw Exception\SchemaUriReferencesInvalidJsonDocument::fromSchemaUri($this->schemaUri);
}

$resultBeforeNormalization = $this->schemaValidator->validate(
Expand All @@ -58,7 +58,7 @@ public function normalize(Json $json): Json
);

if (!$resultBeforeNormalization->isValid()) {
throw Exception\OriginalInvalidAccordingToSchemaException::fromSchemaUriAndErrors(
throw Exception\OriginalInvalidAccordingToSchema::fromSchemaUriAndErrors(
$this->schemaUri,
...\array_map(static function (SchemaValidator\ValidationError $error): string {
return $error->message()->toString();
Expand All @@ -78,7 +78,7 @@ public function normalize(Json $json): Json
);

if (!$resultAfterNormalization->isValid()) {
throw Exception\NormalizedInvalidAccordingToSchemaException::fromSchemaUriAndErrors(
throw Exception\NormalizedInvalidAccordingToSchema::fromSchemaUriAndErrors(
$this->schemaUri,
...\array_map(static function (SchemaValidator\ValidationError $error): string {
return $error->message()->toString();
Expand Down
Expand Up @@ -18,13 +18,13 @@
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentSizeException
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentSize
*/
final class InvalidIndentSizeExceptionTest extends AbstractExceptionTestCase
final class InvalidIndentSizeTest extends AbstractExceptionTestCase
{
public function testDefaults(): void
{
$exception = new Exception\InvalidIndentSizeException();
$exception = new Exception\InvalidIndentSize();

self::assertSame(0, $exception->minimumSize());
self::assertSame(0, $exception->size());
Expand All @@ -37,7 +37,7 @@ public function testFromSizeAndMinimumSizeReturnsInvalidIndentSizeException(): v
$size = $faker->numberBetween(1);
$minimumSize = $faker->numberBetween(1);

$exception = Exception\InvalidIndentSizeException::fromSizeAndMinimumSize(
$exception = Exception\InvalidIndentSize::fromSizeAndMinimumSize(
$size,
$minimumSize,
);
Expand Down
Expand Up @@ -18,13 +18,13 @@
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentStringException
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentString
*/
final class InvalidIndentStringExceptionTest extends AbstractExceptionTestCase
final class InvalidIndentStringTest extends AbstractExceptionTestCase
{
public function testDefaults(): void
{
$exception = new Exception\InvalidIndentStringException();
$exception = new Exception\InvalidIndentString();

self::assertSame('', $exception->string());
}
Expand All @@ -33,7 +33,7 @@ public function testFromSizeAndMinimumSizeReturnsInvalidIndentStringException():
{
$string = self::faker()->word();

$exception = Exception\InvalidIndentStringException::fromString($string);
$exception = Exception\InvalidIndentString::fromString($string);

$message = \sprintf(
'"%s" is not a valid indent string',
Expand Down
Expand Up @@ -18,13 +18,13 @@
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentStyleException
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidIndentStyle
*/
final class InvalidIndentStyleExceptionTest extends AbstractExceptionTestCase
final class InvalidIndentStyleTest extends AbstractExceptionTestCase
{
public function testDefaults(): void
{
$exception = new Exception\InvalidIndentStyleException();
$exception = new Exception\InvalidIndentStyle();

self::assertSame([], $exception->allowedStyles());
self::assertSame('', $exception->style());
Expand All @@ -39,7 +39,7 @@ public function testFromStyleAndAllowedStylesReturnsInvalidIndentStyleException(
/** @var string[] $allowedStyles */
$allowedStyles = $faker->words();

$exception = Exception\InvalidIndentStyleException::fromStyleAndAllowedStyles(
$exception = Exception\InvalidIndentStyle::fromStyleAndAllowedStyles(
$style,
...$allowedStyles,
);
Expand Down
Expand Up @@ -18,13 +18,13 @@
/**
* @internal
*
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidJsonEncodeOptionsException
* @covers \Ergebnis\Json\Normalizer\Exception\InvalidJsonEncodeOptions
*/
final class InvalidJsonEncodeOptionsExceptionTest extends AbstractExceptionTestCase
final class InvalidJsonEncodeOptionsTest extends AbstractExceptionTestCase
{
public function testDefaults(): void
{
$exception = new Exception\InvalidJsonEncodeOptionsException();
$exception = new Exception\InvalidJsonEncodeOptions();

self::assertSame(0, $exception->jsonEncodeOptions());
}
Expand All @@ -33,7 +33,7 @@ public function testFromJsonEncodeOptionsReturnsInvalidJsonEncodeOptionsExceptio
{
$jsonEncodeOptions = self::faker()->randomNumber();

$exception = Exception\InvalidJsonEncodeOptionsException::fromJsonEncodeOptions($jsonEncodeOptions);
$exception = Exception\InvalidJsonEncodeOptions::fromJsonEncodeOptions($jsonEncodeOptions);

$message = \sprintf(
'"%s" is not valid options for json_encode().',
Expand Down