Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Failed Conditions
Push — main ( 5797ad...3faf69 )
by Dan
29s queued 24s
created

DefenseProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Smr\Pages\Player\Planet;
4
5
use AbstractSmrPlayer;
6
use Smr\Page\PlayerPageProcessor;
7
use Smr\Request;
8
9
class DefenseProcessor extends PlayerPageProcessor {
10
11
	public function __construct(
12
		private readonly int $hardwareTypeID
13
	) {}
14
15
	public function build(AbstractSmrPlayer $player): never {
16
		$ship = $player->getShip();
17
18
		if (!$player->isLandedOnPlanet()) {
19
			create_error('You are not on a planet!');
20
		}
21
22
		$amount = Request::getInt('amount');
23
		if ($amount <= 0) {
24
			create_error('You must actually enter an amount > 0!');
25
		}
26
		// get a planet from the sector where the player is in
27
		$planet = $player->getSectorPlanet();
28
29
		$type_id = $this->hardwareTypeID;
30
		$action = Request::get('action');
31
		// transfer to ship
32
		if ($action == 'Ship') {
33
			if ($type_id == HARDWARE_SHIELDS) {
34
				// do we want transfer more than we have?
35
				if ($amount > $planet->getShields()) {
36
					create_error('You can\'t take more shields from planet than are on it!');
37
				}
38
39
				// do we want to transfer more than we can carry?
40
				if ($amount > $ship->getMaxShields() - $ship->getShields()) {
41
					create_error('You can\'t take more shields than you can carry!');
42
				}
43
44
				// now transfer
45
				$planet->decreaseShields($amount);
46
				$ship->increaseShields($amount);
47
				$player->log(LOG_TYPE_PLANETS, 'Player takes ' . $amount . ' shields from planet.');
48
			} elseif ($type_id == HARDWARE_COMBAT) {
49
				// do we want transfer more than we have?
50
				if ($amount > $planet->getCDs()) {
51
					create_error('You can\'t take more drones from planet than are on it!');
52
				}
53
54
				// do we want to transfer more than we can carry?
55
				if ($amount > $ship->getMaxCDs() - $ship->getCDs()) {
56
					create_error('You can\'t take more drones than you can carry!');
57
				}
58
59
				// now transfer
60
				$planet->decreaseCDs($amount);
61
				$ship->increaseCDs($amount);
62
				$player->log(LOG_TYPE_PLANETS, 'Player takes ' . $amount . ' drones from planet.');
63
			} elseif ($type_id == HARDWARE_ARMOUR) {
64
				// do we want transfer more than we have?
65
				if ($amount > $planet->getArmour()) {
66
					create_error('You can\'t take more armour from planet than are on it!');
67
				}
68
69
				// do we want to transfer more than we can carry?
70
				if ($amount > $ship->getMaxArmour() - $ship->getArmour()) {
71
					create_error('You can\'t take more armour than you can carry!');
72
				}
73
74
				// now transfer
75
				$planet->decreaseArmour($amount);
76
				$ship->increaseArmour($amount);
77
				$player->log(LOG_TYPE_PLANETS, 'Player takes ' . $amount . ' armour from planet.');
78
			}
79
80
		} elseif ($action == 'Planet') {
81
			if ($type_id == HARDWARE_SHIELDS) {
82
				// does the user wants to transfer shields?
83
84
				// do we want transfer more than we have?
85
				if ($amount > $ship->getShields()) {
86
					create_error('You can\'t transfer more shields than you carry!');
87
				}
88
89
				// do we want to transfer more than the planet can hold?
90
				if ($amount + $planet->getShields() > $planet->getMaxShields()) {
91
					create_error('The planet can\'t hold more than ' . $planet->getMaxShields() . ' shields!');
92
				}
93
94
				// now transfer
95
				$planet->increaseShields($amount);
96
				$ship->decreaseShields($amount);
97
				$player->log(LOG_TYPE_PLANETS, 'Player puts ' . $amount . ' shields on planet.');
98
			} elseif ($type_id == HARDWARE_COMBAT) {
99
				// does the user wants to transfer drones?
100
101
				// do we want transfer more than we have?
102
				if ($amount > $ship->getCDs()) {
103
					create_error('You can\'t transfer more combat drones than you carry!');
104
				}
105
106
				// do we want to transfer more than we can carry?
107
				if ($amount + $planet->getCDs() > $planet->getMaxCDs()) {
108
					create_error('The planet can\'t hold more than ' . $planet->getMaxCDs() . ' drones!');
109
				}
110
111
				// now transfer
112
				$planet->increaseCDs($amount);
113
				$ship->decreaseCDs($amount);
114
				$player->log(LOG_TYPE_PLANETS, 'Player puts ' . $amount . ' drones on planet.');
115
			} elseif ($type_id == HARDWARE_ARMOUR) {
116
				// does the user wish to transfare armour?
117
118
				// do we want transfer more than we have?
119
				if ($amount >= $ship->getArmour()) {
120
					create_error('You can\'t transfer more armour than what you carry minus one!');
121
				}
122
123
				// do we want to transfer more than we can carry?
124
				if ($amount + $planet->getArmour() > $planet->getMaxArmour()) {
125
					create_error('The planet can\'t hold more than ' . $planet->getMaxArmour() . ' armour!');
126
				}
127
128
				// now transfer
129
				$planet->increaseArmour($amount);
130
				$ship->decreaseArmour($amount);
131
				$player->log(LOG_TYPE_PLANETS, 'Player puts ' . $amount . ' armour on planet.');
132
			}
133
134
		} else {
135
			create_error('You must choose if you want to transfer to planet or to the ship!');
136
		}
137
138
		(new Defense())->go();
139
	}
140
141
}
142