Completed
Push — fake-json-handler ( 48eff3 )
by Akihito
09:34 queued 06:20
created

JsonSchemaExceptionFakeHandler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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
10
class JsonSchemaExceptionFakeHandler implements JsonSchemaExceptionHandlerInterface
11
{
12
    const X_FAKE_JSON = 'X-Fake-JSON';
13
14
    public function handle(ResourceObject $ro, JsonSchemaException $e, string $schemaFile)
0 ignored issues
show
Unused Code introduced by
The method parameter $e is never used
Loading history...
15
    {
16
        $ro->headers[self::X_FAKE_JSON] = $schemaFile;
17
        $ro->body = $this->fakeResponse($schemaFile);
18
    }
19
20
    private function fakeResponse(string $schemaFile) : array
21
    {
22
        $fakeObject = (new Faker())->generate(new \SplFileInfo($schemaFile));
0 ignored issues
show
Documentation introduced by
new \SplFileInfo($schemaFile) is of type object<SplFileInfo>, but the function expects a object<stdClass>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
24
        return $this->deepArray($fakeObject);
25
    }
26
27
    private function deepArray($values) : array
28
    {
29
        $result = [];
30
        foreach ($values as $key => $value) {
31
            $result[$key] = is_object($value) ? $this->deepArray((array) $value) : $result[$key] = $value;
32
        }
33
34
        return $result;
35
    }
36
}
37