Passed
Push — dev ( 91186a...20d5e2 )
by Janko
05:17
created

ShipSystemDataFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 0
c 1
b 1
f 0
nc 1
nop 9
dl 0
loc 11
ccs 2
cts 2
cp 1
crap 1
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
namespace Stu\Component\Spacecraft\System\Data;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
8
use Stu\Component\Spacecraft\System\Exception\InvalidSystemException;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
10
use Stu\Module\Control\StuTime;
11
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
12
use Stu\Module\Template\StatusBarFactoryInterface;
13
use Stu\Orm\Repository\ShipRepositoryInterface;
14
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
15
use Stu\Orm\Repository\TholianWebRepositoryInterface;
16
use Stu\Orm\Repository\DatabaseUserRepositoryInterface;
17
use Stu\Orm\Repository\SpacecraftRumpRepositoryInterface;
18
use Stu\Orm\Repository\FlightSignatureRepositoryInterface;
19
use Stu\Module\Control\GameController;
20
21
final class ShipSystemDataFactory implements ShipSystemDataFactoryInterface
22
{
23 1
    public function __construct(
24
        private readonly ShipRepositoryInterface $shipRepository,
25
        private readonly SpacecraftSystemRepositoryInterface $shipSystemRepository,
26
        private readonly TholianWebRepositoryInterface $tholianWebRepository,
27
        private readonly StatusBarFactoryInterface $statusBarFactory,
28
        private readonly StuTime $stuTime,
29
        private readonly DatabaseUserRepositoryInterface $databaseUserRepository,
30
        private readonly SpacecraftRumpRepositoryInterface $spacecraftRumpRepository,
31
        private readonly FlightSignatureRepositoryInterface $flightSignatureRepository,
32
        private readonly GameController $gameController
33 1
    ) {}
34
35 69
    #[Override]
36
    public function createSystemData(
37
        SpacecraftSystemTypeEnum $systemType,
38
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
39
    ): AbstractSystemData {
40
41
        return match ($systemType) {
42 69
            SpacecraftSystemTypeEnum::HULL =>  new HullSystemData($this->shipSystemRepository, $this->statusBarFactory),
43 69
            SpacecraftSystemTypeEnum::SHIELDS =>  new ShieldSystemData($this->shipSystemRepository, $this->statusBarFactory),
44 69
            SpacecraftSystemTypeEnum::EPS =>  new EpsSystemData($this->shipSystemRepository, $this->statusBarFactory),
45 57
            SpacecraftSystemTypeEnum::COMPUTER =>  new ComputerSystemData($this->shipSystemRepository, $this->statusBarFactory),
46 42
            SpacecraftSystemTypeEnum::TRACKER =>  new TrackerSystemData($this->shipRepository, $spacecraftWrapperFactory, $this->shipSystemRepository, $this->statusBarFactory),
47 42
            SpacecraftSystemTypeEnum::THOLIAN_WEB =>  new WebEmitterSystemData($this->shipSystemRepository, $this->tholianWebRepository, $this->statusBarFactory),
48 34
            SpacecraftSystemTypeEnum::WARPDRIVE =>  new WarpDriveSystemData($this->shipSystemRepository, $this->statusBarFactory, $this->stuTime, $this->spacecraftRumpRepository, $this->databaseUserRepository, $this->gameController),
49 25
            SpacecraftSystemTypeEnum::WARPCORE =>  new WarpCoreSystemData($this->shipSystemRepository, $this->statusBarFactory),
50 13
            SpacecraftSystemTypeEnum::SINGULARITY_REACTOR =>  new SingularityCoreSystemData($this->shipSystemRepository, $this->statusBarFactory),
51 13
            SpacecraftSystemTypeEnum::FUSION_REACTOR =>  new FusionCoreSystemData($this->shipSystemRepository, $this->statusBarFactory),
52 13
            SpacecraftSystemTypeEnum::ASTRO_LABORATORY =>  new AstroLaboratorySystemData($this->shipSystemRepository, $this->statusBarFactory),
53 13
            SpacecraftSystemTypeEnum::PHASER =>  new EnergyWeaponSystemData($this->shipSystemRepository, $this->statusBarFactory),
54 12
            SpacecraftSystemTypeEnum::TORPEDO =>  new ProjectileLauncherSystemData($this->shipSystemRepository, $this->statusBarFactory),
55 12
            SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR =>  new BussardCollectorSystemData($this->shipSystemRepository, $this->statusBarFactory),
56 10
            SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM =>  new AggregationSystemSystemData($this->shipSystemRepository, $this->statusBarFactory),
57 8
            SpacecraftSystemTypeEnum::LSS =>  new LssSystemData($this->shipSystemRepository, $this->statusBarFactory),
58 1
            SpacecraftSystemTypeEnum::SUBSPACE_SCANNER => new SubspaceSystemData($this->shipSystemRepository, $this->statusBarFactory, $this->flightSignatureRepository),
59
60 69
            default => throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value))
61
        };
62
    }
63
}
64