Passed
Push — develop ( a6f0fe...5308a3 )
by Daniel
24:47 queued 09:44
created

ListResponse::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\Locations;
6
7
use InShore\Bookwhen\Contracts\ResponseContract;
8
use InShore\Bookwhen\Responses\Concerns\ArrayAccessible;
9
use InShore\Bookwhen\Responses\Events\RetrieveResponse;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, InShore\Bookwhen\Respons...ations\RetrieveResponse. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
//use InShore\Bookwhen\Testing\Responses\Concerns\Fakeable;
12
13
/**
14
 * @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
15
 */
16
final class ListResponse implements ResponseContract
17
{
18
    /**
19
     * @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
20
     */
21
    use ArrayAccessible;
22
23
    //     use Fakeable;
24
25
    /**
26
     * @param  array<int, RetrieveResponse>  $data
27
     */
28
    private function __construct(
29
        public readonly array $data,
30
    ) {
31
    }
32
33
    /**
34
     * Acts as static factory, and returns a new Response instance.
35
     *
36
     * @param  array{data: array<int, array{event_id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}  $attributes
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{data: array<int, a..., mixed>|string|null}>} at position 42 could not be parsed: Unknown type name 'array-key' at position 42 in array{data: array<int, array{event_id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}.
Loading history...
37
     */
38
    public static function from(array $attributes): self
39
    {
40
        $data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from(
41
            $result
42
        ), $attributes['data']);
43
44
        return new self(
45
            $data,
46
        );
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function toArray(): array
53
    {
54
        return [
55
            'object' => $this->object,
0 ignored issues
show
Bug Best Practice introduced by
The property object does not exist on InShore\Bookwhen\Responses\Locations\ListResponse. Did you maybe forget to declare it?
Loading history...
56
            'data' => array_map(
57
                static fn (RetrieveResponse $response): array => $response->toArray(),
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on InShore\Bookwhen\Responses\Events\RetrieveResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                static fn (RetrieveResponse $response): array => $response->/** @scrutinizer ignore-call */ toArray(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
                $this->data,
59
            ),
60
        ];
61
    }
62
}
63