Test Failed
Push — master ( 135f34...8b25c6 )
by Chris
33:49
created

Setting::__construct()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 9.2222
c 0
b 0
f 0
cc 6
nc 32
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 Leonidas\Library\System\Setting;
4
5
use Leonidas\Contracts\System\Setting\SettingHandlerInterface;
6
use Leonidas\Contracts\System\Setting\SettingInterface;
7
use Leonidas\Library\System\Setting\Traits\HasSettingDataTrait;
8
9
class Setting implements SettingInterface
10
{
11
    use HasSettingDataTrait;
12
13
    public function __construct(
14
        string $optionGroup,
15
        string $optionName,
16
        ?string $type = null,
17
        ?string $description = null,
18
        ?SettingHandlerInterface $handler = null,
19
        $restSchema = null,
20
        $defaultValue = null,
21
        ?array $extraArgs = null
22
    ) {
23
        $this->optionGroup = $optionGroup;
24
        $this->optionName = $optionName;
25
        $this->handler = $handler;
26
27
        $type && $this->type = $type;
28
        $description && $this->description = $description;
29
        $restSchema && $this->restSchema = $restSchema;
30
        $defaultValue && $this->defaultValue = $defaultValue;
31
        $extraArgs && $this->extraArgs = $extraArgs;
32
    }
33
}
34