Passed
Pull Request — develop (#95)
by
unknown
29:42 queued 14:41
created

ListResponse::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\Events;
6
7
use InShore\Bookwhen\Contracts\ResponseContract;
8
use InShore\Bookwhen\Responses\Concerns\ArrayAccessible;
9
use InShore\Bookwhen\Responses\Events\RetrieveResponse;
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
        $included = [];
41
        if(array_key_exists('included', $attributes)) {
42
            $included = $attributes['included'];
43
        }
44
45
        $data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from(
46
            $result,
47
            $included
48
        ), $attributes['data']);
49
50
        return new self(
51
            $data,
52
        );
53
    }
54
}
55