bearsunday /
BEAR.Resource
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace BEAR\Resource; |
||
| 6 | |||
| 7 | use BEAR\Resource\Exception\JsonSchemaException; |
||
| 8 | use JSONSchemaFaker\Faker; |
||
| 9 | use LogicException; |
||
| 10 | use Override; |
||
| 11 | use SplFileInfo; |
||
| 12 | use stdClass; |
||
| 13 | |||
| 14 | use function class_exists; |
||
| 15 | use function is_object; |
||
| 16 | |||
| 17 | /** @psalm-import-type Body from Types */ |
||
| 18 | final class JsonSchemaExceptionFakeHandler implements JsonSchemaExceptionHandlerInterface |
||
| 19 | { |
||
| 20 | final public const X_FAKE_JSON = 'X-Fake-JSON'; |
||
| 21 | final public const X_JSON_SCHEMA_EXCEPTION = 'X-JSON-Schema-Exception'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * {@inheritDoc} |
||
| 25 | */ |
||
| 26 | #[Override] |
||
| 27 | public function handle(ResourceObject $ro, JsonSchemaException $e, string $schemaFile) |
||
| 28 | { |
||
| 29 | $ro->headers[self::X_FAKE_JSON] = $schemaFile; |
||
| 30 | $ro->headers[self::X_JSON_SCHEMA_EXCEPTION] = $e->getMessage(); |
||
| 31 | $ro->body = $this->fakeResponse($schemaFile); |
||
| 32 | $ro->view = null; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** @return Body */ |
||
|
0 ignored issues
–
show
|
|||
| 36 | private function fakeResponse(string $schemaFile): array |
||
| 37 | { |
||
| 38 | if (! class_exists(Faker::class)) { |
||
| 39 | 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 |
||
| 40 | } |
||
| 41 | |||
| 42 | /** @var Body $fakeObject */ |
||
| 43 | $fakeObject = (new Faker())->generate(new SplFileInfo($schemaFile)); |
||
| 44 | |||
| 45 | return $this->deepArray($fakeObject); |
||
|
0 ignored issues
–
show
|
|||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param Body $values |
||
| 50 | * |
||
| 51 | * @return Body |
||
| 52 | */ |
||
| 53 | private function deepArray(array|stdClass $values): array |
||
| 54 | { |
||
| 55 | $result = []; |
||
| 56 | /** @psalm-suppress MixedAssignment */ |
||
| 57 | foreach ($values as $key => $value) { //@phpstan-ignore-line |
||
| 58 | $result[$key] = is_object($value) ? $this->deepArray((array) $value) : $result[$key] = $value; |
||
| 59 | } |
||
| 60 | |||
| 61 | return $result; |
||
|
0 ignored issues
–
show
|
|||
| 62 | } |
||
| 63 | } |
||
| 64 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths