FileUser::setUserData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 8
crap 2

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 kalanis\kw_accounts\Data;
4
5
6
use kalanis\kw_accounts\Interfaces\IUser;
7
use kalanis\kw_accounts\Interfaces\IProcessClasses;
8
9
10
/**
11
 * Class FileUser
12
 * @package kalanis\kw_accounts\Data
13
 */
14
class FileUser implements IUser
15
{
16
    protected string $authId = '0';
17
    protected string $authName = '';
18
    protected string $authGroup = '0';
19
    protected int $authClass = IProcessClasses::CLASS_UNKNOWN;
20
    protected int $authStatus = IUser::USER_STATUS_UNKNOWN;
21
    protected string $displayName = '';
22
    protected string $dir = '';
23
    /** @var array<string|int, string|int|float|bool> */
24
    protected array $extra = [];
25
26 1
    public function setUserData(?string $authId, ?string $authName, ?string $authGroup, ?int $authClass, ?int $authStatus, ?string $displayName, ?string $dir, ?array $extra = []): void
27
    {
28 1
        $this->authId = $authId ?? $this->authId;
29 1
        $this->authName = $authName ?? $this->authName;
30 1
        $this->authGroup = $authGroup ?? $this->authGroup;
31 1
        $this->authClass = $authClass ?? $this->authClass;
32 1
        $this->authStatus = $authStatus ?? $this->authStatus;
33 1
        $this->displayName = $displayName ?? $this->displayName;
34 1
        $this->dir = $dir ?? $this->dir;
35 1
        $this->extra = !is_null($extra) ? array_merge($this->extra, $extra) : $this->extra;
0 ignored issues
show
introduced by
The condition is_null($extra) is always false.
Loading history...
36 1
    }
37
38 1
    public function getAuthId(): string
39
    {
40 1
        return $this->authId;
41
    }
42
43 1
    public function getAuthName(): string
44
    {
45 1
        return $this->authName;
46
    }
47
48 1
    public function getGroup(): string
49
    {
50 1
        return $this->authGroup;
51
    }
52
53 1
    public function getClass(): int
54
    {
55 1
        return $this->authClass;
56
    }
57
58 1
    public function getStatus(): int
59
    {
60 1
        return $this->authStatus;
61
    }
62
63 1
    public function getDisplayName(): string
64
    {
65 1
        return $this->displayName;
66
    }
67
68 1
    public function getDir(): string
69
    {
70 1
        return $this->dir;
71
    }
72
73 1
    public function getExtra(): array
74
    {
75 1
        return $this->extra;
76
    }
77
}
78