From 463ff701e7b5169abec9a552b56bd60260f9a16e Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 23 Oct 2024 11:29:13 +0900 Subject: [PATCH 1/2] Make koriym/json-schema-faker package optional 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. --- composer-require-checker.json | 3 ++- composer.json | 4 ++-- src/JsonSchema/JsonSchemaExceptionFakeHandler.php | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index a484094c..a38d52a1 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -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" ] } diff --git a/composer.json b/composer.json index 598c1c5e..56f3734b 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/src/JsonSchema/JsonSchemaExceptionFakeHandler.php b/src/JsonSchema/JsonSchemaExceptionFakeHandler.php index 74853332..ebd9e38c 100644 --- a/src/JsonSchema/JsonSchemaExceptionFakeHandler.php +++ b/src/JsonSchema/JsonSchemaExceptionFakeHandler.php @@ -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 @@ -30,6 +32,10 @@ public function handle(ResourceObject $ro, JsonSchemaException $e, string $schem /** @return array */ 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 $fakeObject */ $fakeObject = (new Faker())->generate(new SplFileInfo($schemaFile)); From 0ac6bc966b51cdb85fbbf7b4eee660f0b7d052e9 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 23 Oct 2024 11:41:24 +0900 Subject: [PATCH 2/2] fixup! Make koriym/json-schema-faker package optional --- src/JsonSchema/JsonSchemaExceptionFakeHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/JsonSchemaExceptionFakeHandler.php b/src/JsonSchema/JsonSchemaExceptionFakeHandler.php index ebd9e38c..0a0ab962 100644 --- a/src/JsonSchema/JsonSchemaExceptionFakeHandler.php +++ b/src/JsonSchema/JsonSchemaExceptionFakeHandler.php @@ -33,7 +33,7 @@ public function handle(ResourceObject $ro, JsonSchemaException $e, string $schem 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 + 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 $fakeObject */