Passed
Push — master ( 4c85b9...e180ca )
by Arthur
36:55
created

ClientState::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 21.02.19
6
 * Time: 18:34
7
 */
8
9
namespace Modules\Client\Entities;
10
11
12
class ClientState
13
{
14
    public $type;
15
    public $paused;
16
    public $stoppable;
17
    public $scriptId;
18
    public $machineId;
19
    public $scriptConfig;
20
    public $proxy;
21
    public $credentials;
22
23
    /**
24
     * ClientState constructor.
25
     * @param $type
26
     * @param $paused
27
     * @param $stoppable
28
     * @param $scriptId
29
     * @param $machineId
30
     * @param $scriptConfig
31
     * @param $proxy
32
     * @param $credentials
33
     */
34
    private function __construct(string $type, bool $paused, bool $stoppable, string $scriptId, string $machineId, ?array $scriptConfig, ?array $proxy, ?array $credentials)
35
    {
36
        $this->type = $type;
37
        $this->paused = $paused;
38
        $this->stoppable = $stoppable;
39
        $this->scriptId = $scriptId;
40
        $this->machineId = $machineId;
41
        $this->scriptConfig = $scriptConfig;
42
        $this->proxy = $proxy;
43
        $this->credentials = $credentials;
44
    }
45
46
    public static function create(array $state){
47
        return new ClientState(
48
            $state['type'],
49
            $state['paused'],
50
            $state['stoppable'],
51
            $state['scriptId'],
52
            $state['machineId'],
53
            $state['script_config'] ??null,
54
            $state['proxy'] ?? null,
55
            $state['credentials'] ?? null
56
        );
57
    }
58
59
60
}