Passed
Pull Request — master (#565)
by Théo
02:31
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 function array_unique;
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
    /**
30
     * @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...
31
     */
32
    private array $exposedClasses;
33
34
    /**
35
     * @var list<string>
36
     */
37
    private array $exposedFunctions;
38
39
    /**
40
     * @var list<string>
41
     */
42
    private array $exposedConstants;
43
44
    /**
45
     * @param string[] $excludedNamespaceRegexes
46
     * @param string[] $excludedNamespaceNames
47
     * @param string[] $exposedNamespaceRegexes
48
     * @param string[] $exposedNamespaceNames
49
     * @param string[] $exposedClasses
50
     * @param string[] $exposedFunctions
51
     * @param string[] $exposedConstants
52
     */
53
    public static function create(
54
        bool $exposeGlobalConstants = true,
55
        bool $exposeGlobalClasses = true,
56
        bool $exposeGlobalFunctions = true,
57
        ?NamespaceRegistry $excludedNamespaces = null,
58
        // Does not contain the list of excluded symbols which go to the
59
        // Reflector (which has no notion of namespaces)
60
        ?NamespaceRegistry $exposedNamespaces = null,
61
        array $exposedClasses = [],
62
        array $exposedFunctions = [],
63
        array $exposedConstants = []
64
    ): self {
65
        return new self(
66
            $exposeGlobalConstants,
67
            $exposeGlobalClasses,
68
            $exposeGlobalFunctions,
69
            $excludedNamespaces ?? NamespaceRegistry::create(),
70
            $exposedNamespaces ?? NamespaceRegistry::create(),
71
            array_unique($exposedClasses),
72
            array_unique($exposedFunctions),
73
            array_unique($exposedConstants),
74
        );
75
    }
76
77
    /**
78
     * @param list<string>       $exposedClasses
79
     * @param list<string>       $exposedFunctions
80
     * @param list<string>       $exposedConstants
81
     */
82
    public function __construct(
83
        bool $exposeGlobalConstants,
84
        bool $exposeGlobalClasses,
85
        bool $exposeGlobalFunctions,
86
        NamespaceRegistry $excludedNamespaces,
87
        NamespaceRegistry $exposedNamespaces,
88
        array $exposedClasses,
89
        array $exposedFunctions,
90
        array $exposedConstants
91
    ) {
92
        $this->exposeGlobalConstants = $exposeGlobalConstants;
93
        $this->exposeGlobalClasses = $exposeGlobalClasses;
94
        $this->exposeGlobalFunctions = $exposeGlobalFunctions;
95
        $this->excludedNamespaces = $excludedNamespaces;
96
        $this->exposedNamespaces = $exposedNamespaces;
97
        $this->exposedClasses = $exposedClasses;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedClasses of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedClasses.

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...
98
        $this->exposedFunctions = $exposedFunctions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedFunctions of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedFunctions.

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...
99
        $this->exposedConstants = $exposedConstants;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exposedConstants of type array is incompatible with the declared type Humbug\PhpScoper\Configuration\list of property $exposedConstants.

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...
100
    }
101
102
    public function shouldExposeGlobalConstants(): bool
103
    {
104
        return $this->exposeGlobalConstants;
105
    }
106
107
    public function shouldExposeGlobalClasses(): bool
108
    {
109
        return $this->exposeGlobalClasses;
110
    }
111
112
    public function shouldExposeGlobalFunctions(): bool
113
    {
114
        return $this->exposeGlobalFunctions;
115
    }
116
117
    public function getExcludedNamespaces(): NamespaceRegistry
118
    {
119
        return $this->excludedNamespaces;
120
    }
121
122
    public function getExposedNamespaces(): NamespaceRegistry
123
    {
124
        return $this->exposedNamespaces;
125
    }
126
127
    /**
128
     * @return list<string>
129
     */
130
    public function getExposedClasses(): array
131
    {
132
        return $this->exposedClasses;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedClasses returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
133
    }
134
135
    /**
136
     * @return list<string>
137
     */
138
    public function getExposedFunctions(): array
139
    {
140
        return $this->exposedFunctions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedFunctions returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
141
    }
142
143
    /**
144
     * @return list<string>
145
     */
146
    public function getExposedConstants(): array
147
    {
148
        return $this->exposedConstants;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exposedConstants returns the type array which is incompatible with the documented return type Humbug\PhpScoper\Configuration\list.
Loading history...
149
    }
150
}
151