Passed
Push — master ( bb5d68...d9c4a7 )
by Nico
56:35 queued 26:36
created

ColonyLibFactory::createColonyListItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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