RetrieveResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 2
b 0
f 0
nc 1
nop 8
dl 0
loc 10
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\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