Passed
Pull Request — master (#584)
by Théo
02:04
created

SymbolsConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 11
dl 0
loc 24
rs 9.9
c 1
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
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\Whitelist;
19
use function array_unique;
20
21
final class SymbolsConfiguration
22
{
23
    private bool $exposeGlobalConstants;
24
    private bool $exposeGlobalClasses;
25
    private bool $exposeGlobalFunctions;
26
27
    private NamespaceRegistry $excludedNamespaces;
28
    private NamespaceRegistry $exposedNamespaces;
29
30
    /**
31
     * @var list<string>
0 ignored issues
show
Bug introduced by
The type Humbug\PhpScoper\Configuration\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
     */
33
    private array $exposedClassNames;
34
35
    /**
36
     * @var list<string>
37
     */
38
    private array $exposedClassRegexes;
39
40
    /**
41
     * @var list<string>
42
     */
43
    private array $exposedFunctionNames;
44
45
    /**
46
     * @var list<string>
47
     */
48
    private array $exposedFunctionRegexes;
49
50
    /**
51
     * @var list<string>
52
     */
53
    private array $exposedConstantNames;
54
55
    /**
56
     * @var list<string>
57
     */
58
    private array $exposedConstantRegexes;
59
60
    public static function fromWhitelist(Whitelist $whitelist): self
61
    {
62
        $exposedSymbols = $whitelist->getExposedSymbols();
63
        $exposedSymbolsPatterns = $whitelist->getExposedSymbolsPatterns();
64
65
        return self::create(
66
            $whitelist->exposeGlobalConstants(),
67
            $whitelist->exposeGlobalClasses(),
68
            $whitelist->exposeGlobalFunctions(),
69
            $whitelist->getExcludedNamespaces(),
70
            null,
71
            $exposedSymbols,
72
            $exposedSymbolsPatterns,
73
            $exposedSymbols,
74
            $exposedSymbolsPatterns,
75
            $whitelist->getExposedConstants(),
76
            $exposedSymbolsPatterns,
77
        );
78
    }
79
80
    /**
81
     * @param string[] $exposedClassNames
82
     * @param string[] $exposedClassRegexes
83
     * @param string[] $exposedFunctionNames
84
     * @param string[] $exposedFunctionRegexes
85
     * @param string[] $exposedConstantNames
86
     * @param string[] $exposedConstantRegexes
87
     */
88
    public static function create(
89
        bool $exposeGlobalConstants = true,
90
        bool $exposeGlobalClasses = true,
91
        bool $exposeGlobalFunctions = true,
92
        ?NamespaceRegistry $excludedNamespaces = null,
93
        // Does not contain the list of excluded symbols which go to the
94
        // Reflector (which has no notion of namespaces)
95
        ?NamespaceRegistry $exposedNamespaces = null,
96
        array $exposedClassNames = [],
97
        array $exposedClassRegexes = [],
98
        array $exposedFunctionNames = [],
99
        array $exposedFunctionRegexes = [],
100
        array $exposedConstantNames = [],
101
        array $exposedConstantRegexes = []
102
    ): self {
103
        return new self(
104
            $exposeGlobalConstants,
105
            $exposeGlobalClasses,
106
            $exposeGlobalFunctions,
107
            $excludedNamespaces ?? NamespaceRegistry::create(),
108
            $exposedNamespaces ?? NamespaceRegistry::create(),
109
            array_unique($exposedClassNames),
110
            array_unique($exposedClassRegexes),
111
            array_unique($exposedFunctionNames),
112
            array_unique($exposedFunctionRegexes),
113
            array_unique($exposedConstantNames),
114
            array_unique($exposedConstantRegexes),
115
        );
116
    }
117
118
    /**
119
     * @param list<string> $exposedClassNames
120
     * @param list<string> $exposedClassRegexes
121
     * @param list<string> $exposedFunctionNames
122
     * @param list<string> $exposedFunctionRegexes
123
     * @param list<string> $exposedConstantNames
124
     * @param list<string> $exposedConstantRegexes
125
     */
126
    private function __construct(
127
        bool $exposeGlobalConstants,
128
        bool $exposeGlobalClasses,
129
        bool $exposeGlobalFunctions,
130
        NamespaceRegistry $excludedNamespaces,
131
        NamespaceRegistry $exposedNamespaces,
132
        array $exposedClassNames,
133
        array $exposedClassRegexes,
134
        array $exposedFunctionNames,
135
        array $exposedFunctionRegexes,
136
        array $exposedConstantNames,
137
        array $exposedConstantRegexes
138
    ) {
139
        $this->exposeGlobalConstants = $exposeGlobalConstants;
140
        $this->exposeGlobalClasses = $exposeGlobalClasses;
141
        $this->exposeGlobalFunctions = $exposeGlobalFunctions;
142
        $this->excludedNamespaces = $excludedNamespaces;
143
        $this->exposedNamespaces = $exposedNamespaces;
144
        $this->exposedClassNames = $exposedClassNames;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedClassNames of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedClassNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
145
        $this->exposedClassRegexes = $exposedClassRegexes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedClassRegexes of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedClassRegexes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
146
        $this->exposedFunctionNames = $exposedFunctionNames;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedFunctionNames of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedFunctionNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
147
        $this->exposedFunctionRegexes = $exposedFunctionRegexes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedFunctionRegexes of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedFunctionRegexes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
148
        $this->exposedConstantNames = $exposedConstantNames;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedConstantNames of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedConstantNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
149
        $this->exposedConstantRegexes = $exposedConstantRegexes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedConstantRegexes of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedConstantRegexes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
150
    }
151
152
    public function shouldExposeGlobalConstants(): bool
153
    {
154
        return $this->exposeGlobalConstants;
155
    }
156
157
    public function shouldExposeGlobalClasses(): bool
158
    {
159
        return $this->exposeGlobalClasses;
160
    }
161
162
    public function shouldExposeGlobalFunctions(): bool
163
    {
164
        return $this->exposeGlobalFunctions;
165
    }
166
167
    public function getExcludedNamespaces(): NamespaceRegistry
168
    {
169
        return $this->excludedNamespaces;
170
    }
171
172
    public function getExposedNamespaces(): NamespaceRegistry
173
    {
174
        return $this->exposedNamespaces;
175
    }
176
177
    /**
178
     * @return list<string>
179
     */
180
    public function getExposedClassNames(): array
181
    {
182
        return $this->exposedClassNames;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedClassNames returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
183
    }
184
185
    /**
186
     * @return list<string>
187
     */
188
    public function getExposedClassRegexes(): array
189
    {
190
        return $this->exposedClassRegexes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedClassRegexes returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
191
    }
192
193
    /**
194
     * @return list<string>
195
     */
196
    public function getExposedFunctionNames(): array
197
    {
198
        return $this->exposedFunctionNames;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedFunctionNames returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
199
    }
200
201
    /**
202
     * @return list<string>
203
     */
204
    public function getExposedFunctionRegexes(): array
205
    {
206
        return $this->exposedFunctionRegexes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedFunctionRegexes returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
207
    }
208
209
    /**
210
     * @return list<string>
211
     */
212
    public function getExposedConstantNames(): array
213
    {
214
        return $this->exposedConstantNames;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedConstantNames returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
215
    }
216
217
    /**
218
     * @return list<string>
219
     */
220
    public function getExposedConstantRegexes(): array
221
    {
222
        return $this->exposedConstantRegexes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedConstantRegexes returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
223
    }
224
}
225