Passed
Push — master ( 199cf7...129662 )
by Rogier
12:20
created

AccountData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 8

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
namespace Rogierw\RwAcme\DTO;
4
5
use Rogierw\RwAcme\Http\Response;
6
use Rogierw\RwAcme\Support\Arr;
7
use Rogierw\RwAcme\Support\Url;
8
use Spatie\LaravelData\Data;
9
10
class AccountData extends Data
11
{
12
    public function __construct(
13
        public string $id,
14
        public string $url,
15
        public array $key,
16
        public string $status,
17
        public array $contact,
18
        public string $agreement,
19
        public string $initialIp,
20
        public string $createdAt,
21
    ) {}
22
23
    public static function fromResponse(Response $response): AccountData
24
    {
25
        $url = trim(Arr::get($response->getRawHeaders(), 'Location', ''));
26
27
        return new self(
28
            id: Url::extractId($url),
29
            url: $url,
30
            key: $response->getBody()['key'],
31
            status: $response->getBody()['status'],
32
            contact: $response->getBody()['contact'],
33
            agreement: $response->getBody()['agreement'] ?? '',
34
            initialIp: $response->getBody()['initialIp'],
35
            createdAt: $response->getBody()['createdAt']
36
        );
37
    }
38
}
39