Passed
Push — master ( e661f4...30021e )
by Nico
25:16 queued 10:59
created

ApplyBuildingDamage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 7.69%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 46
ccs 2
cts 26
cp 0.0769
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B damageBuilding() 0 40 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Colony\Lib\Damage;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use RuntimeException;
9
use Stu\Lib\Damage\DamageModeEnum;
10
use Stu\Lib\Damage\DamageWrapper;
11
use Stu\Lib\Information\InformationWrapper;
12
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface;
13
use Stu\Orm\Entity\ColonyInterface;
14
use Stu\Orm\Entity\PlanetFieldInterface;
15
16
final class ApplyBuildingDamage implements ApplyBuildingDamageInterface
17
{
18 1
    public function __construct(
19
        private ColonyLibFactoryInterface $colonyLibFactory
20 1
    ) {}
21
22
    #[Override]
23
    public function damageBuilding(
24
        DamageWrapper $damageWrapper,
25
        PlanetFieldInterface $target,
26
        bool $isOrbitField
27
    ): InformationWrapper {
28
        $informations = new InformationWrapper();
29
30
        $colony = $target->getHost();
31
        if (!$colony instanceof ColonyInterface) {
32
            throw new RuntimeException('this should not happen');
33
        }
34
35
        if (!$isOrbitField && $this->colonyLibFactory->createColonyShieldingManager($colony)->isShieldingEnabled()) {
36
            $damage = (int) $damageWrapper->getDamageRelative($colony, DamageModeEnum::SHIELDS);
37
            if ($damage > $colony->getShields()) {
38
                $informations->addInformation("- Schildschaden: " . $colony->getShields());
39
                $informations->addInformation("-- Schilde brechen zusammen!");
40
41
                $colony->setShields(0);
42
            } else {
43
                $colony->setShields($colony->getShields() - $damage);
44
                $informations->addInformation("- Schildschaden: " . $damage . " - Status: " . $colony->getShields());
45
            }
46
        }
47
        if ($damageWrapper->getNetDamage() <= 0) {
48
            return $informations;
49
        }
50
        $damage = (int) $damageWrapper->getDamageRelative($colony, DamageModeEnum::HULL);
51
        if ($target->getIntegrity() > $damage) {
52
            $target->setIntegrity($target->getIntegrity() - $damage);
53
            $informations->addInformation("- Gebäudeschaden: " . $damage . " - Status: " . $target->getIntegrity());
54
55
            return $informations;
56
        }
57
        $informations->addInformation("- Gebäudeschaden: " . $damage);
58
        $informations->addInformation("-- Das Gebäude wurde zerstört!");
59
        $target->setIntegrity(0);
60
61
        return $informations;
62
    }
63
}
64