Skip to content

Commit

Permalink
Make JSONSchemaFaker\Faker class optional
Browse files Browse the repository at this point in the history
Add a check to ensure JSONSchemaFaker\Faker class is present before usage. Updated the koriym/json-schema-faker dependency to version ^0.3.1 in composer.json and updated composer-require-checker.json accordingly.
  • Loading branch information
koriym committed Oct 23, 2024
1 parent 9d90024 commit b93f550
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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"
]
}
3 changes: 1 addition & 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,7 @@
"ray/rector-ray": "^1.0",
"rector/rector": "^1.2.4",
"ray/compiler": "^1.9.1",
"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('JSONSchemaFaker\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

0 comments on commit b93f550

Please sign in to comment.