Passed
Pull Request — master (#1773)
by Nico
29:30
created

FleetWrapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A get() 0 3 1
A getLeadWrapper() 0 3 1
A getShipWrappers() 0 3 1
A isForeignFleet() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib;
6
7
use Stu\Module\Control\GameControllerInterface;
8
use Stu\Orm\Entity\FleetInterface;
9
10
final class FleetWrapper implements FleetWrapperInterface
11
{
12
    private FleetInterface $fleet;
13
14
    private ShipWrapperFactoryInterface $shipWrapperFactory;
15
16
    private GameControllerInterface $game;
17
18
    private bool $isSingleShips;
19
20 2
    public function __construct(
21
        FleetInterface $fleet,
22
        ShipWrapperFactoryInterface $shipWrapperFactory,
23
        GameControllerInterface $game,
24
        bool $isSingleShips
25
    ) {
26 2
        $this->fleet = $fleet;
27 2
        $this->shipWrapperFactory = $shipWrapperFactory;
28 2
        $this->game = $game;
29 2
        $this->isSingleShips = $isSingleShips;
30
    }
31
32 2
    public function get(): FleetInterface
33
    {
34 2
        return $this->fleet;
35
    }
36
37
    public function getLeadWrapper(): ShipWrapperInterface
38
    {
39
        return $this->shipWrapperFactory->wrapShip($this->get()->getLeadShip());
40
    }
41
42 2
    public function getShipWrappers(): array
43
    {
44 2
        return $this->shipWrapperFactory->wrapShips($this->get()->getShips()->toArray());
45
    }
46
47
    public function isForeignFleet(): bool
48
    {
49
        return !$this->isSingleShips && $this->get()->getUser() !== $this->game->getUser();
50
    }
51
}
52