Passed
Push — master ( 2c9072...01edf2 )
by Daniel
39:31 queued 24:28
created

RetrieveResponse::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\ClassPasses;
6
7
use InShore\Bookwhen\Contracts\ResponseContract;
8
use InShore\Bookwhen\Responses\Concerns\ArrayAccessible;
9
10
//use OpenAI\Testing\Responses\Concerns\Fakeable;
11
12
/**
13
 * @implements ResponseContract<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
14
 */
15
final class RetrieveResponse implements ResponseContract
16
{
17
    /**
18
     * @use ArrayAccessible<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
19
     */
20
    use ArrayAccessible;
21
22
    //use Fakeable;
23
24
    /**
25
     * @param  array<array-key, mixed>|null  $statusDetails
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, mixed>|null at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, mixed>|null.
Loading history...
26
,
27
28
29
30
    'cost' =>
31
    array (
32
      'currency_code' => 'GBP',
33
      'net' => 3500,
34
      'tax' => 0,
35
    ),
36
     */
37
    private function __construct(
38
        public readonly null | string $details,
39
        public readonly string $id,
40
        public readonly int | null $numberAvailable,
41
        public readonly string $title,
42
        public readonly int | null $usageAllowance,
43
        public readonly string $usageType,
44
        public readonly int | null $useRestrictedForDays,
45
    ) {
46
    }
47
48
    /**
49
     * Acts as static factory, and returns a new Response instance.
50
     *
51
     * @param  array{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{id: string, object...ey, mixed>|string|null} at position 34 could not be parsed: Unknown type name 'array-key' at position 34 in array{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...
52
     */
53
    public static function from(array $attributes): self
54
    {
55
56
        return new self(
57
            $attributes['attributes']['details'],
58
            $attributes['id'],
59
            $attributes['attributes']['number_available'],
60
            $attributes['attributes']['title'],
61
            $attributes['attributes']['usage_allowance'],
62
            $attributes['attributes']['usage_type'],
63
            $attributes['attributes']['use_restricted_for_days'],
64
        );
65
    }
66
}
67