Passed
Push — master ( 499990...210c58 )
by Théo
01:59
created

SymbolsConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 18
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
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\Configuration;
16
17
use Humbug\PhpScoper\Symbol\NamespaceRegistry;
18
use Humbug\PhpScoper\Symbol\SymbolRegistry;
19
20
final class SymbolsConfiguration
21
{
22
    private bool $exposeGlobalConstants;
23
    private bool $exposeGlobalClasses;
24
    private bool $exposeGlobalFunctions;
25
26
    private NamespaceRegistry $excludedNamespaces;
27
    private NamespaceRegistry $exposedNamespaces;
28
29
    private SymbolRegistry $exposedClasses;
30
    private SymbolRegistry $exposedFunctions;
31
    private SymbolRegistry $exposedConstants;
32
33
    public static function create(
34
        bool $exposeGlobalConstants = false,
35
        bool $exposeGlobalClasses = false,
36
        bool $exposeGlobalFunctions = false,
37
        ?NamespaceRegistry $excludedNamespaces = null,
38
        // Does not contain the list of excluded symbols which go to the
39
        // Reflector (which has no notion of namespaces)
40
        ?NamespaceRegistry $exposedNamespaces = null,
41
        SymbolRegistry $exposedClasses = null,
42
        SymbolRegistry $exposedFunctions = null,
43
        SymbolRegistry $exposedConstants = null
44
    ): self {
45
        return new self(
46
            $exposeGlobalConstants,
47
            $exposeGlobalClasses,
48
            $exposeGlobalFunctions,
49
            $excludedNamespaces ?? NamespaceRegistry::create(),
50
            $exposedNamespaces ?? NamespaceRegistry::create(),
51
            $exposedClasses ?? SymbolRegistry::create(),
52
            $exposedFunctions ?? SymbolRegistry::create(),
53
            $exposedConstants ?? SymbolRegistry::createForConstants(),
54
        );
55
    }
56
57
    private function __construct(
58
        bool $exposeGlobalConstants,
59
        bool $exposeGlobalClasses,
60
        bool $exposeGlobalFunctions,
61
        NamespaceRegistry $excludedNamespaces,
62
        NamespaceRegistry $exposedNamespaces,
63
        SymbolRegistry $exposedClasses,
64
        SymbolRegistry $exposedFunctions,
65
        SymbolRegistry $exposedConstants
66
    ) {
67
        $this->exposeGlobalConstants = $exposeGlobalConstants;
68
        $this->exposeGlobalClasses = $exposeGlobalClasses;
69
        $this->exposeGlobalFunctions = $exposeGlobalFunctions;
70
        $this->excludedNamespaces = $excludedNamespaces;
71
        $this->exposedNamespaces = $exposedNamespaces;
72
        $this->exposedClasses = $exposedClasses;
73
        $this->exposedFunctions = $exposedFunctions;
74
        $this->exposedConstants = $exposedConstants;
75
    }
76
77
    public function shouldExposeGlobalConstants(): bool
78
    {
79
        return $this->exposeGlobalConstants;
80
    }
81
82
    public function shouldExposeGlobalClasses(): bool
83
    {
84
        return $this->exposeGlobalClasses;
85
    }
86
87
    public function shouldExposeGlobalFunctions(): bool
88
    {
89
        return $this->exposeGlobalFunctions;
90
    }
91
92
    public function getExcludedNamespaces(): NamespaceRegistry
93
    {
94
        return $this->excludedNamespaces;
95
    }
96
97
    public function getExposedNamespaces(): NamespaceRegistry
98
    {
99
        return $this->exposedNamespaces;
100
    }
101
102
    public function getExposedClasses(): SymbolRegistry
103
    {
104
        return $this->exposedClasses;
105
    }
106
107
    public function getExposedFunctions(): SymbolRegistry
108
    {
109
        return $this->exposedFunctions;
110
    }
111
112
    public function getExposedConstants(): SymbolRegistry
113
    {
114
        return $this->exposedConstants;
115
    }
116
}
117