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

RetrieveResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 4
b 0
f 0
nc 1
nop 15
dl 0
loc 17
ccs 1
cts 1
cp 1
crap 1
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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