Passed
Pull Request — develop (#91)
by
unknown
18:44 queued 03:45
created

RetrieveResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 14
dl 0
loc 17
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\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 bool | null $available,
39
        public readonly null | string $availableFrom,
40
        public readonly null | string $availableTo,
41
        public readonly null | string $builtBasketUrl,
42
        public readonly null | string $builtBasketIframeUrl,
43
        public readonly bool | null $courseTicket,
44
        // cost
45
        public readonly null | string $details,
46
        public readonly bool | null $groupTicket,
47
        public readonly int | null $groupMin,
48
        public readonly int | null $groupMax,
49
        public readonly string $id,
50
        public readonly int | null $numberIssued,
51
        public readonly int | null $numberTaken,
52
        public readonly null | string $title
53
    ) {
54
    }
55
56
    /**
57
     * Acts as static factory, and returns a new Response instance.
58
     *
59
     * @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...
60
     */
61
    public static function from(array $attributes): self
62
    {
63
        return new self(
64
            $attributes['attributes']['available'],
65
            $attributes['attributes']['available_from'],
66
            $attributes['attributes']['available_to'],
67
            $attributes['attributes']['built_basket_url'],
68
            $attributes['attributes']['built_basket_iframe_url'],
69
            $attributes['attributes']['course_ticket'],
70
            $attributes['attributes']['details'],
71
            $attributes['attributes']['group_ticket'],
72
            $attributes['attributes']['group_min'],
73
            $attributes['attributes']['group_max'],
74
            $attributes['id'],
75
            $attributes['attributes']['number_issued'],
76
            $attributes['attributes']['number_taken'],
77
            $attributes['attributes']['title']
78
        );
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function toArray(): array
85
    {
86
        return [
87
            'id' => $this->id,
88
            'type' => $this->type,
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on InShore\Bookwhen\Respons...Passes\RetrieveResponse. Did you maybe forget to declare it?
Loading history...
89
            //'attributes' => $this->attributes,
90
        ];
91
    }
92
}
93