RetrieveResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A from() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\Attachments;
6
7
use InShore\Bookwhen\Contracts\ResponseContract;
8
9
/**
10
 * @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}>
11
 */
12
final class RetrieveResponse implements ResponseContract
13
{
14
    /**
15
     * @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...
16
     */
17 6
    private function __construct(
18
        public readonly null | string $contentType,
19
        public readonly null | string $fileName,
20
        public readonly null | string $fileSizeBytes,
21
        public readonly null | string $fileSizeText,
22
        public readonly null | string $fileType,
23
        public readonly null | string $fileUrl,
24
        public readonly string $id,
25
        public readonly null | string $title
26
    ) {
27 6
    }
28
29
    /**
30
     * Acts as static factory, and returns a new Response instance.
31
     *
32
     * @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...
33
     */
34 6
    public static function from(array $attributes): self
35
    {
36 6
        return new self(
37 6
            $attributes['attributes']['content_type'] ?? null,
38 6
            $attributes['attributes']['file_name'] ?? null,
39 6
            $attributes['attributes']['file_size_bytes'] ?? null,
40 6
            $attributes['attributes']['file_size_text'] ?? null,
41 6
            $attributes['attributes']['file_type'] ?? null,
42 6
            $attributes['attributes']['file_url'] ?? null,
43 6
            $attributes['id'],
44 6
            $attributes['attributes']['title'] ?? null,
45 6
        );
46
    }
47
}
48