Passed
Pull Request — develop (#146)
by
unknown
02:08
created

RetrieveResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 22
c 5
b 0
f 0
dl 0
loc 55
ccs 21
cts 24
cp 0.875
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 26 2
A __construct() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\Tickets;
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 2
    private function __construct(
18
        public readonly bool | null $available,
19
        public readonly null | string $availableFrom,
20
        public readonly null | string $availableTo,
21
        public readonly null | string $builtBasketUrl,
22
        public readonly null | string $builtBasketIframeUrl,
23
        public readonly object $cost,
24
        public readonly bool | null $courseTicket,
25
        public readonly null | string $details,
26
        public readonly bool | null $groupTicket,
27
        public readonly int | null $groupMin,
28
        public readonly int | null $groupMax,
29
        public readonly string $id,
30
        public readonly int | null $numberIssued,
31
        public readonly int | null $numberTaken,
32
        public readonly null | string $title
33
    ) {
34 2
    }
35
36
    /**
37
     * Acts as static factory, and returns a new Response instance.
38
     *
39
     * @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...
40
     */
41 2
    public static function from(array $attributes): self
42
    {
43
44 2
        $cost = new \stdClass();
45 2
        if (!empty($attributes['attributes']['cost'])) {
46
            $cost->currencyCode = $attributes['attributes']['cost']['currency_code'];
47
            $cost->net = $attributes['attributes']['cost']['net'];
48
            $cost->tax = $attributes['attributes']['cost']['tax'];
49
        }
50
51 2
        return new self(
52 2
            $attributes['attributes']['available'] ?? null,
53 2
            $attributes['attributes']['available_from'] ?? null,
54 2
            $attributes['attributes']['available_to'] ?? null,
55 2
            $attributes['attributes']['built_basket_url'] ?? null,
56 2
            $attributes['attributes']['built_basket_iframe_url'] ?? null,
57 2
            $cost,
58 2
            $attributes['attributes']['course_ticket'] ?? null,
59 2
            $attributes['attributes']['details'] ?? null,
60 2
            $attributes['attributes']['group_ticket'] ?? null,
61 2
            $attributes['attributes']['group_min'] ?? null,
62 2
            $attributes['attributes']['group_max'] ?? null,
63 2
            $attributes['id'],
64 2
            $attributes['attributes']['number_issued'] ?? null,
65 2
            $attributes['attributes']['number_taken'] ?? null,
66 2
            $attributes['attributes']['title'] ?? null,
67 2
        );
68
    }
69
}
70