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

Make koriym/json-schema-faker package optional #309

Merged
merged 2 commits into from
Oct 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"Attribute", "ReflectionAttribute", "Stringable",
"BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule"
"BEAR\\Resource\\HalLink", "BEAR\\Resource\\NullReverseLink", "BEAR\\Resource\\ReverseLinkInterface", "BEAR\\Resource\\Module\\AnnotationModule",
"JSONSchemaFaker\\Faker"
]
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"justinrainbow/json-schema": "^5.3 || ^6.0",
"koriym/attributes": "^1.0",
"koriym/http-constants": "^1.1",
"koriym/json-schema-faker": "^0.3",
"nocarrier/hal": "^0.9.12",
"phpdocumentor/reflection-docblock": "^5.2",
"psr/log": "^1.1 || ^2.0 || ^3.0",
Expand All @@ -37,7 +36,8 @@
"ray/rector-ray": "^1.0",
"rector/rector": "^1.2.4",
"ray/compiler": "^1.9.1",
"bear/devtools": "^1.0"
"bear/devtools": "^1.0",
"koriym/json-schema-faker": "^0.3.1"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions src/JsonSchema/JsonSchemaExceptionFakeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use BEAR\Resource\Exception\JsonSchemaException;
use JSONSchemaFaker\Faker;
use LogicException;
use SplFileInfo;
use stdClass;

use function class_exists;
use function is_object;

class JsonSchemaExceptionFakeHandler implements JsonSchemaExceptionHandlerInterface
Expand All @@ -30,6 +32,10 @@ public function handle(ResourceObject $ro, JsonSchemaException $e, string $schem
/** @return array<int|string, mixed> */
private function fakeResponse(string $schemaFile): array
{
if (! class_exists(Faker::class)) {
throw new LogicException('"koriym/json-schema-faker" not installed. Please run "composer require koriym/json-schema-faker --dev". See more at https://github.com/bearsunday/BEAR.Resource/wiki/json_schema_faker_required'); // @codeCoverageIgnore
}

/** @var array<int|string, mixed> $fakeObject */
$fakeObject = (new Faker())->generate(new SplFileInfo($schemaFile));

Expand Down
Loading