Passed
Push — master ( 288b46...98b0e3 )
by Nico
31:30 queued 08:00
created

ColonyLibFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 19
c 2
b 1
f 0
nc 1
nop 19
dl 0
loc 40
ccs 20
cts 20
cp 1
crap 1
rs 9.6333

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
namespace Stu\Module\Colony\Lib;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Stu\Component\Colony\ColonyFunctionManagerInterface;
9
use Stu\Component\Colony\ColonyPopulationCalculator;
10
use Stu\Component\Colony\ColonyPopulationCalculatorInterface;
11
use Stu\Component\Colony\Commodity\ColonyCommodityProduction;
12
use Stu\Component\Colony\Commodity\ColonyCommodityProductionInterface;
13
use Stu\Component\Colony\Commodity\ColonyProductionSumReducer;
14
use Stu\Component\Colony\Commodity\ColonyProductionSumReducerInterface;
15
use Stu\Component\Colony\Shields\ColonyShieldingManager;
16
use Stu\Component\Colony\Shields\ColonyShieldingManagerInterface;
17
use Stu\Lib\ColonyProduction\ColonyProduction;
18
use Stu\Lib\ModuleScreen\Addon\ModuleSelectorAddonFactoryInterface;
19
use Stu\Lib\ModuleScreen\ModuleSelector;
20
use Stu\Lib\ModuleScreen\ModuleSelectorSpecial;
21
use Stu\Module\Commodity\Lib\CommodityCacheInterface;
22
use Stu\Module\Logging\LoggerUtilFactoryInterface;
23
use Stu\Module\Tal\TalPageInterface;
24
use Stu\Orm\Entity\ColonyInterface;
25
use Stu\Orm\Entity\CommodityInterface;
26
use Stu\Orm\Entity\ShipBuildplanInterface;
27
use Stu\Orm\Entity\ShipInterface;
28
use Stu\Orm\Entity\ShipRumpInterface;
29
use Stu\Orm\Entity\UserInterface;
30
use Stu\Orm\Repository\BuildingCommodityRepositoryInterface;
31
use Stu\Orm\Repository\BuildingRepositoryInterface;
32
use Stu\Orm\Repository\ColonyRepositoryInterface;
33
use Stu\Orm\Repository\FlightSignatureRepositoryInterface;
34
use Stu\Orm\Repository\ModuleRepositoryInterface;
35
use Stu\Orm\Repository\PlanetFieldRepositoryInterface;
36
use Stu\Orm\Repository\ResearchedRepositoryInterface;
37
use Stu\Orm\Repository\ShipBuildplanRepositoryInterface;
38
use Stu\Orm\Repository\ShipRepositoryInterface;
39
use Stu\Orm\Repository\ShipRumpModuleLevelRepositoryInterface;
40
use Stu\PlanetGenerator\PlanetGeneratorInterface;
41
42
final class ColonyLibFactory implements ColonyLibFactoryInterface
43
{
44
    private PlanetFieldRepositoryInterface $planetFieldRepository;
45
46
    private BuildingRepositoryInterface $buildingRepository;
47
48
    private ColonyRepositoryInterface $colonyRepository;
49
50
    private CommodityConsumptionInterface $commodityConsumption;
51
52
    private ShipRepositoryInterface $shipRepository;
53
54
    private ShipBuildplanRepositoryInterface $shipBuildplanRepository;
55
56
    private ResearchedRepositoryInterface $researchedRepository;
57
58
    private FlightSignatureRepositoryInterface $flightSignatureRepository;
59
60
    private PlanetGeneratorInterface $planetGenerator;
61
62
    private EntityManagerInterface $entityManager;
63
64
    private BuildingCommodityRepositoryInterface $buildingCommodityRepository;
65
66
    private ModuleRepositoryInterface $moduleRepository;
67
68
    private ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository;
69
70
    private TalPageInterface $talPage;
71
72
    private PlanetFieldTypeRetrieverInterface $planetFieldTypeRetriever;
73
74
    private ColonyFunctionManagerInterface $colonyFunctionManager;
75
76
    private ModuleSelectorAddonFactoryInterface $moduleSelectorAddonFactory;
77
78
    private CommodityCacheInterface $commodityCache;
79
80
    private LoggerUtilFactoryInterface $loggerUtilFactory;
81
82 2
    public function __construct(
83
        PlanetFieldRepositoryInterface $planetFieldRepository,
84
        BuildingRepositoryInterface $buildingRepository,
85
        ColonyRepositoryInterface $colonyRepository,
86
        CommodityConsumptionInterface $commodityConsumption,
87
        ShipRepositoryInterface $shipRepository,
88
        ShipBuildplanRepositoryInterface $shipBuildplanRepository,
89
        ResearchedRepositoryInterface $researchedRepository,
90
        FlightSignatureRepositoryInterface $flightSignatureRepository,
91
        PlanetGeneratorInterface $planetGenerator,
92
        EntityManagerInterface $entityManager,
93
        BuildingCommodityRepositoryInterface $buildingCommodityRepository,
94
        ModuleRepositoryInterface $moduleRepository,
95
        ShipRumpModuleLevelRepositoryInterface $shipRumpModuleLevelRepository,
96
        TalPageInterface $talPage,
97
        PlanetFieldTypeRetrieverInterface $planetFieldTypeRetriever,
98
        ColonyFunctionManagerInterface $colonyFunctionManager,
99
        ModuleSelectorAddonFactoryInterface $moduleSelectorAddonFactory,
100
        CommodityCacheInterface $commodityCache,
101
        LoggerUtilFactoryInterface $loggerUtilFactory
102
    ) {
103 2
        $this->planetFieldRepository = $planetFieldRepository;
104 2
        $this->buildingRepository = $buildingRepository;
105 2
        $this->colonyRepository = $colonyRepository;
106 2
        $this->commodityConsumption = $commodityConsumption;
107 2
        $this->shipRepository = $shipRepository;
108 2
        $this->shipBuildplanRepository = $shipBuildplanRepository;
109 2
        $this->researchedRepository = $researchedRepository;
110 2
        $this->flightSignatureRepository = $flightSignatureRepository;
111 2
        $this->planetGenerator = $planetGenerator;
112 2
        $this->entityManager = $entityManager;
113 2
        $this->buildingCommodityRepository = $buildingCommodityRepository;
114 2
        $this->moduleRepository = $moduleRepository;
115 2
        $this->shipRumpModuleLevelRepository = $shipRumpModuleLevelRepository;
116 2
        $this->talPage = $talPage;
117 2
        $this->planetFieldTypeRetriever = $planetFieldTypeRetriever;
118 2
        $this->colonyFunctionManager = $colonyFunctionManager;
119 2
        $this->moduleSelectorAddonFactory = $moduleSelectorAddonFactory;
120 2
        $this->commodityCache = $commodityCache;
121 2
        $this->loggerUtilFactory = $loggerUtilFactory;
122
    }
123
124
    public function createBuildingFunctionTal(
125
        array $buildingFunctionIds
126
    ): BuildingFunctionTalInterface {
127
        return new BuildingFunctionTal($buildingFunctionIds);
128
    }
129
130
    public function createColonySurface(
131
        ColonyInterface $colony,
132
        ?int $buildingId = null,
133
        bool $showUnderground = true
134
    ): ColonySurfaceInterface {
135
        return new ColonySurface(
136
            $this,
137
            $this->planetFieldRepository,
138
            $this->buildingRepository,
139
            $this->colonyRepository,
140
            $this->researchedRepository,
141
            $this->planetGenerator,
142
            $this->entityManager,
143
            $this->loggerUtilFactory->getLoggerUtil(),
144
            $this->planetFieldTypeRetriever,
145
            $colony,
146
            $buildingId,
147
            $showUnderground
148
        );
149
    }
150
151
    public function createColonyListItem(
152
        ColonyInterface $colony
153
    ): ColonyListItemInterface {
154
        return new ColonyListItem(
155
            $this,
156
            $this->planetFieldRepository,
157
            $this->commodityConsumption,
158
            $colony,
159
            $this->flightSignatureRepository->getVisibleSignatureCount($colony)
160
        );
161
    }
162
163
    public function createBuildableRumpItem(
164
        ShipRumpInterface $shipRump,
165
        UserInterface $currentUser
166
    ): BuildableRumpListItemInterface {
167
        return new BuildableRumpListItem(
168
            $this->shipRepository,
169
            $this->shipBuildplanRepository,
170
            $shipRump,
171
            $currentUser
172
        );
173
    }
174
175
    public function createColonyProductionPreviewWrapper(
176
        array $production
177
    ): ColonyProductionPreviewWrapper {
178
        return new ColonyProductionPreviewWrapper(
179
            $this,
180
            $this->buildingCommodityRepository,
181
            $production
182
        );
183
    }
184
185
    public function createEpsProductionPreviewWrapper(
186
        ColonyInterface $colony
187
    ): ColonyEpsProductionPreviewWrapper {
188
        return new ColonyEpsProductionPreviewWrapper(
189
            $this->planetFieldRepository,
190
            $this->buildingRepository,
191
            $colony
192
        );
193
    }
194
195
    public function createModuleSelector(
196
        int $moduleType,
197
        ?ColonyInterface $colony,
198
        ?ShipInterface $station,
199
        ShipRumpInterface $rump,
200
        int $userId,
201
        ?ShipBuildplanInterface $buildplan = null
202
    ): ModuleSelector {
203
204
        $addon = $this->moduleSelectorAddonFactory->createModuleSelectorAddon($moduleType);
205
206
        return new ModuleSelector(
207
            $this->moduleRepository,
208
            $this->shipRumpModuleLevelRepository,
209
            $this->talPage,
210
            $moduleType,
211
            $colony,
212
            $station,
213
            $rump,
214
            $userId,
215
            $addon,
216
            $buildplan
217
        );
218
    }
219
220
    public function createModuleSelectorSpecial(
221
        int $moduleType,
222
        ?ColonyInterface $colony,
223
        ?ShipInterface $station,
224
        ShipRumpInterface $rump,
225
        int $userId,
226
        ?ShipBuildplanInterface $buildplan = null
227
    ): ModuleSelectorSpecial {
228
        return new ModuleSelectorSpecial(
229
            $this->moduleRepository,
230
            $this->shipRumpModuleLevelRepository,
231
            $this->talPage,
232
            $moduleType,
233
            $colony,
234
            $station,
235
            $rump,
236
            $userId,
237
            null,
238
            $buildplan
239
        );
240
    }
241
242
    public function createColonyProduction(
243
        CommodityInterface $commodity,
244
        int $production,
245
        ?int $pc = null
246
    ): ColonyProduction {
247
        return new ColonyProduction(
248
            $commodity,
249
            $production,
250
            $pc
251
        );
252
    }
253
254
    public function createColonyShieldingManager(
255
        ColonyInterface $colony
256
    ): ColonyShieldingManagerInterface {
257
        return new ColonyShieldingManager(
258
            $this->planetFieldRepository,
259
            $this->colonyFunctionManager,
260
            $colony
261
        );
262
    }
263
264
    public function createColonyCommodityProduction(
265
        ColonyInterface $colony
266
    ): ColonyCommodityProductionInterface {
267
        return new ColonyCommodityProduction(
268
            $this->buildingCommodityRepository,
269
            $colony,
270
            $this,
271
            $this->commodityCache
272
        );
273
    }
274
275
    public function createColonyProductionSumReducer(): ColonyProductionSumReducerInterface
276
    {
277
        return new ColonyProductionSumReducer();
278
    }
279
280
    public function createColonyPopulationCalculator(
281
        ColonyInterface $colony,
282
        array $production = null
283
    ): ColonyPopulationCalculatorInterface {
284
285
        return new ColonyPopulationCalculator(
286
            $colony,
287
            $production ?? $this->createColonyCommodityProduction($colony)->getProduction()
288
        );
289
    }
290
}
291