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

AstroEntryLib::cancelAstroFinalizing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 16
ccs 0
cts 11
cp 0
crap 6
rs 9.9332
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