Passed
Push — dev ( 766009...bcc49c )
by Janko
09:42
created

ResearchStateFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 10
dl 0
loc 22
ccs 0
cts 11
cp 0
crap 2
rs 9.9332
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
namespace Stu\Module\Research;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Stu\Component\Ship\System\ShipSystemManagerInterface;
9
use Stu\Module\Award\Lib\CreateUserAwardInterface;
10
use Stu\Module\Crew\Lib\CrewCreatorInterface;
11
use Stu\Module\Database\Lib\CreateDatabaseEntryInterface;
12
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
13
use Stu\Module\Ship\Lib\ShipCreatorInterface;
14
use Stu\Orm\Repository\ResearchedRepositoryInterface;
15
use Stu\Orm\Repository\ShipRepositoryInterface;
16
use Stu\Orm\Repository\ShipRumpUserRepositoryInterface;
17
18
final class ResearchStateFactory implements ResearchStateFactoryInterface
19
{
20
    private ResearchedRepositoryInterface $researchedRepository;
21
22
    private ShipRumpUserRepositoryInterface $shipRumpUserRepository;
23
24
    private PrivateMessageSenderInterface $privateMessageSender;
25
26
    private CreateDatabaseEntryInterface $createDatabaseEntry;
27
28
    private CrewCreatorInterface $crewCreator;
29
30
    private ShipCreatorInterface $shipCreator;
31
32
    private ShipRepositoryInterface $shipRepository;
33
34
    private ShipSystemManagerInterface $shipSystemManager;
35
36
    private EntityManagerInterface $entityManager;
37
38
    private CreateUserAwardInterface $createUserAward;
39
40
    public function __construct(
41
        ResearchedRepositoryInterface $researchedRepository,
42
        ShipRumpUserRepositoryInterface $shipRumpUserRepository,
43
        PrivateMessageSenderInterface $privateMessageSender,
44
        CreateDatabaseEntryInterface $createDatabaseEntry,
45
        CrewCreatorInterface $crewCreator,
46
        ShipCreatorInterface $shipCreator,
47
        ShipRepositoryInterface $shipRepository,
48
        ShipSystemManagerInterface $shipSystemManager,
49
        CreateUserAwardInterface $createUserAward,
50
        EntityManagerInterface $entityManager
51
    ) {
52
        $this->researchedRepository = $researchedRepository;
53
        $this->shipRumpUserRepository = $shipRumpUserRepository;
54
        $this->privateMessageSender = $privateMessageSender;
55
        $this->createDatabaseEntry = $createDatabaseEntry;
56
        $this->crewCreator = $crewCreator;
57
        $this->shipCreator = $shipCreator;
58
        $this->shipRepository = $shipRepository;
59
        $this->shipSystemManager = $shipSystemManager;
60
        $this->entityManager = $entityManager;
61
        $this->createUserAward = $createUserAward;
62
    }
63
64
    public function createResearchState(): ResearchStateInterface
65
    {
66
        return new ResearchState(
67
            $this->researchedRepository,
68
            $this->shipRumpUserRepository,
69
            $this->privateMessageSender,
70
            $this->createDatabaseEntry,
71
            $this->crewCreator,
72
            $this->shipCreator,
73
            $this->shipRepository,
74
            $this->shipSystemManager,
75
            $this->createUserAward,
76
            $this->entityManager,
77
        );
78
    }
79
}
80