Passed
Pull Request — master (#1830)
by Nico
30:56
created

AstroEntryLib   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 8.33%

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 45
ccs 2
cts 24
cp 0.0833
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A cancelAstroFinalizing() 0 16 2
A finish() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib;
6
7
use RuntimeException;
8
use Stu\Component\Ship\AstronomicalMappingEnum;
9
use Stu\Component\Ship\ShipStateEnum;
10
use Stu\Orm\Repository\AstroEntryRepositoryInterface;
11
12
final class AstroEntryLib implements AstroEntryLibInterface
13
{
14
    private AstroEntryRepositoryInterface $astroEntryRepository;
15
16 4
    public function __construct(
17
        AstroEntryRepositoryInterface $astroEntryRepository
18
    ) {
19 4
        $this->astroEntryRepository = $astroEntryRepository;
20
    }
21
22
    public function cancelAstroFinalizing(ShipWrapperInterface $wrapper): void
23
    {
24
        $ship = $wrapper->get();
25
26
        $ship->setState(ShipStateEnum::SHIP_STATE_NONE);
27
        $astroLab = $wrapper->getAstroLaboratorySystemData();
28
        if ($astroLab === null) {
29
            throw new RuntimeException('this should not happen');
30
        }
31
        $astroLab->setAstroStartTurn(null)->update();
32
33
        $entry = $this->astroEntryRepository->getByShipLocation($ship, false);
34
35
        $entry->setState(AstronomicalMappingEnum::MEASURED);
36
        $entry->setAstroStartTurn(null);
37
        $this->astroEntryRepository->save($entry);
0 ignored issues
show
Bug introduced by
It seems like $entry can also be of type null; however, parameter $entry of Stu\Orm\Repository\Astro...sitoryInterface::save() does only seem to accept Stu\Orm\Entity\AstronomicalEntryInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $this->astroEntryRepository->save(/** @scrutinizer ignore-type */ $entry);
Loading history...
38
    }
39
40
    public function finish(ShipWrapperInterface $wrapper): void
41
    {
42
        $ship = $wrapper->get();
43
44
        $ship->setState(ShipStateEnum::SHIP_STATE_NONE);
45
46
        $astroLab = $wrapper->getAstroLaboratorySystemData();
47
        if ($astroLab === null) {
48
            throw new RuntimeException('this should not happen');
49
        }
50
        $astroLab->setAstroStartTurn(null)->update();
51
52
        $entry = $this->astroEntryRepository->getByShipLocation($ship, false);
53
54
        $entry->setState(AstronomicalMappingEnum::DONE);
55
        $entry->setAstroStartTurn(null);
56
        $this->astroEntryRepository->save($entry);
0 ignored issues
show
Bug introduced by
It seems like $entry can also be of type null; however, parameter $entry of Stu\Orm\Repository\Astro...sitoryInterface::save() does only seem to accept Stu\Orm\Entity\AstronomicalEntryInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $this->astroEntryRepository->save(/** @scrutinizer ignore-type */ $entry);
Loading history...
57
    }
58
}
59