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

InteractionMemberFactory::createMember()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 0
Metric Value
cc 4
eloc 12
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 19
ccs 12
cts 13
cp 0.9231
crap 4.0072
rs 9.8666
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