Passed
Pull Request — dev (#2303)
by Janko
05:56
created

InteractionMemberFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Lib\Interaction\Member;
4
5
use RuntimeException;
6
use Stu\Component\Spacecraft\Nbs\NbsUtilityInterface;
7
use Stu\Lib\Interaction\EntityWithInteractionCheckInterface;
8
use Stu\Lib\Transfer\CommodityTransferInterface;
9
use Stu\Module\Ship\Lib\TholianWebUtilInterface;
10
use Stu\Orm\Entity\Colony;
11
use Stu\Orm\Entity\Spacecraft;
12
use Stu\Orm\Entity\Trumfield;
13
14
class InteractionMemberFactory implements InteractionMemberFactoryInterface
15
{
16 1
    public function __construct(
17
        private NbsUtilityInterface $nbsUtility,
18
        private TholianWebUtilInterface $tholianWebUtil,
19
        private CommodityTransferInterface $commodityTransfer
20 1
    ) {}
21
22 23
    #[\Override]
23
    public function createMember(EntityWithInteractionCheckInterface $entity): InteractionMemberInterface
24
    {
25 23
        if ($entity instanceof Colony) {
26 4
            return new ColonyMember($this->tholianWebUtil, $entity);
27
        }
28 23
        if ($entity instanceof Spacecraft) {
29 23
            return new SpacecraftMember(
30 23
                $this->nbsUtility,
31 23
                $this->tholianWebUtil,
32 23
                $this->commodityTransfer,
33 23
                $entity
34 23
            );
35
        }
36 1
        if ($entity instanceof Trumfield) {
37 1
            return new TrumfieldMember($entity);
38
        }
39
40
        throw new RuntimeException('unknown entity class');
41
    }
42
}
43