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

InteractionMemberFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 27
ccs 14
cts 15
cp 0.9333
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createMember() 0 19 4
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