RetrieveResponse::__construct()   A
last analyzed

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 8
    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 8
    }
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 8
    public static function from(array $attributes, $included = []): self
0 ignored issues
show
Unused Code introduced by
The parameter $included is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
    public static function from(array $attributes, /** @scrutinizer ignore-unused */ $included = []): self

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
44 8
        $cost = new \stdClass();
45 8
        if (!empty($attributes['attributes']['cost'])) {
46 2
            $cost->currencyCode = $attributes['attributes']['cost']['currency_code'];
47 2
            $cost->net = $attributes['attributes']['cost']['net'];
48 2
            $cost->tax = $attributes['attributes']['cost']['tax'];
49
        }
50
51 8
        return new self(
52 8
            $attributes['attributes']['available'] ?? null,
53 8
            $attributes['attributes']['available_from'] ?? null,
54 8
            $attributes['attributes']['available_to'] ?? null,
55 8
            $attributes['attributes']['built_basket_url'] ?? null,
56 8
            $attributes['attributes']['built_basket_iframe_url'] ?? null,
57 8
            $cost,
58 8
            $attributes['attributes']['course_ticket'] ?? null,
59 8
            $attributes['attributes']['details'] ?? null,
60 8
            $attributes['attributes']['group_ticket'] ?? null,
61 8
            $attributes['attributes']['group_min'] ?? null,
62 8
            $attributes['attributes']['group_max'] ?? null,
63 8
            $attributes['id'],
64 8
            $attributes['attributes']['number_issued'] ?? null,
65 8
            $attributes['attributes']['number_taken'] ?? null,
66 8
            $attributes['attributes']['title'] ?? null,
67 8
        );
68
    }
69
}
70