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

Passed
Push — dependabot/composer/phpstan/ph... ( 54306b...acb380 )
by
unknown
11:49 queued 06:39
created

DwarfPlanet   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 24
c 2
b 1
f 1
dl 0
loc 41
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 2 1
A maxLanded() 0 2 1
A maxAttackers() 0 2 1
A description() 0 2 1
A imageLink() 0 2 1
A getStructureData() 0 2 1
A menuOptions() 0 2 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * Defines intrinsic properties of planet types.
5
 */
6
abstract class SmrPlanetType {
7
	const MAX_LANDED_UNLIMITED = 0;
8
	const DEFAULT_MENU_OPTIONS = ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP', 'FINANCE'];
9
10
	/**
11
	 * Returns the properties of all the structures this planet type can build.
12
	 *
13
	 * We could access static::STRUCTURES directly (late static binding), but
14
	 * that confuses static analyzers, since there is no STRUCTURES const in
15
	 * the base class (nor should there be).
16
	 */
17
	abstract protected function getStructureData() : array;
18
19
	abstract public function name() : string;
20
	abstract public function imageLink() : string;
21
	abstract public function description() : string;
22
	abstract public function maxAttackers() : int;
23
	abstract public function maxLanded() : int;
24
	abstract public function menuOptions() : array;
25
26
	private array $structures;
27
28
	/**
29
	 * Associates the planet_type_id with the planet class.
30
	 * These indices must not be changed!
31
	 */
32
	const PLANET_TYPES = [
33
		1 => TerranPlanet::class,
34
		2 => AridPlanet::class,
35
		3 => DwarfPlanet::class,
36
		4 => DefenseWorld::class,
37
		5 => ProtoPlanet::class,
38
	];
39
40
	/**
41
	 * Returns an instance of the planet type from the given $typeID.
42
	 * This is the intended method to construct an SmrPlanetType.
43
	 */
44
	public static function getTypeInfo(int $typeID) : self {
45
		if (!isset(self::PLANET_TYPES[$typeID])) {
46
			throw new Exception("Planet type ID does not exist: $typeID");
47
		}
48
		$planetType = self::PLANET_TYPES[$typeID];
49
		return new $planetType;
50
	}
51
52
	/**
53
	 * Access properties of structures that this planet type can build.
54
	 */
55
	public function structureTypes(int $structureID = null) : SmrPlanetStructureType|array {
56
		if (!isset($this->structures)) {
57
			foreach ($this->getStructureData() as $ID => $Info) {
58
				$this->structures[$ID] = new SmrPlanetStructureType($ID, $Info);
59
			}
60
		}
61
		if ($structureID === null) {
62
			return $this->structures;
63
		} elseif (isset($this->structures[$structureID])) {
64
			return $this->structures[$structureID];
65
		} else {
66
			throw new Exception("Structure not supported on this planet type: $structureID");
67
		}
68
	}
69
}
70
71
class TerranPlanet extends SmrPlanetType {
72
	const STRUCTURES = [
73
		PLANET_GENERATOR => [
74
			'max_amount' => 25,
75
			'base_time' => 10800,
76
			'credit_cost' => 100000,
77
			'exp_gain' => 90,
78
		],
79
		PLANET_HANGAR => [
80
			'max_amount' => 100,
81
			'base_time' => 21600,
82
			'credit_cost' => 100000,
83
			'exp_gain' => 180,
84
		],
85
		PLANET_TURRET => [
86
			'max_amount' => 10,
87
			'base_time' => 64800,
88
			'credit_cost' => 1000000,
89
			'exp_gain' => 540,
90
		],
91
	];
92
	protected function getStructureData() : array {
93
		return self::STRUCTURES;
94
	}
95
	public function name() : string {
96
		return "Terran Planet";
97
	}
98
	public function imageLink() : string {
99
		return "images/planet1.png";
100
	}
101
	public function description() : string {
102
		return "A lush world, with forests, seas, sweeping meadows, and indigenous lifeforms.";
103
	}
104
	public function maxAttackers() : int {
105
		return 10;
106
	}
107
	public function maxLanded() : int {
108
		return self::MAX_LANDED_UNLIMITED;
109
	}
110
	public function menuOptions() : array {
111
		return self::DEFAULT_MENU_OPTIONS;
112
	}
113
}
114
115
class AridPlanet extends SmrPlanetType {
116
	const STRUCTURES = [
117
		PLANET_GENERATOR => [
118
			'max_amount' => 25,
119
			'base_time' => 10800,
120
			'credit_cost' => 100000,
121
			'exp_gain' => 90,
122
		],
123
		PLANET_BUNKER => [
124
			'max_amount' => 25,
125
			'base_time' => 10800,
126
			'credit_cost' => 50000,
127
			'exp_gain' => 90,
128
		],
129
		PLANET_TURRET => [
130
			'max_amount' => 15,
131
			'base_time' => 21600,
132
			'credit_cost' => 750000,
133
			'exp_gain' => 180,
134
		],
135
	];
136
	protected function getStructureData() : array {
137
		return self::STRUCTURES;
138
	}
139
	public function name() : string {
140
		return "Arid Planet";
141
	}
142
	public function imageLink() : string {
143
		return "images/planet2.png";
144
	}
145
	public function description() : string {
146
		return "A world mostly devoid of surface water, but capable of supporting life.";
147
	}
148
	public function maxAttackers() : int {
149
		return 5;
150
	}
151
	public function maxLanded() : int {
152
		return 5;
153
	}
154
	public function menuOptions() : array {
155
		return ['CONSTRUCTION', 'DEFENSE', 'STOCKPILE', 'OWNERSHIP'];
156
	}
157
}
158
159
class DwarfPlanet extends SmrPlanetType {
160
	const STRUCTURES = [
161
		PLANET_GENERATOR => [
162
			'max_amount' => 10,
163
			'base_time' => 10800,
164
			'credit_cost' => 100000,
165
			'exp_gain' => 90,
166
		],
167
		PLANET_HANGAR => [
168
			'max_amount' => 85,
169
			'base_time' => 21600,
170
			'credit_cost' => 100000,
171
			'exp_gain' => 180,
172
		],
173
		PLANET_TURRET => [
174
			'max_amount' => 5,
175
			'base_time' => 64800,
176
			'credit_cost' => 1000000,
177
			'exp_gain' => 540,
178
		],
179
	];
180
	protected function getStructureData() : array {
181
		return self::STRUCTURES;
182
	}
183
	public function name() : string {
184
		return "Dwarf Planet";
185
	}
186
	public function imageLink() : string {
187
		return "images/planet3.png";
188
	}
189
	public function description() : string {
190
		return "A smaller than usual planet, with no native life present.";
191
	}
192
	public function maxAttackers() : int {
193
		return 5;
194
	}
195
	public function maxLanded() : int {
196
		return self::MAX_LANDED_UNLIMITED;
197
	}
198
	public function menuOptions() : array {
199
		return self::DEFAULT_MENU_OPTIONS;
200
	}
201
}
202
203
class ProtoPlanet extends SmrPlanetType {
204
	const STRUCTURES = [
205
		PLANET_GENERATOR => [
206
			'max_amount' => 5,
207
			'base_time' => 10800,
208
			'credit_cost' => 100000,
209
			'exp_gain' => 90,
210
		],
211
		PLANET_HANGAR => [
212
			'max_amount' => 50,
213
			'base_time' => 21600,
214
			'credit_cost' => 100000,
215
			'exp_gain' => 180,
216
		],
217
		PLANET_BUNKER => [
218
			'max_amount' => 15,
219
			'base_time' => 10800,
220
			'credit_cost' => 50000,
221
			'exp_gain' => 90,
222
		],
223
		PLANET_WEAPON_MOUNT => [
224
			'max_amount' => 20,
225
			'base_time' => 32400,
226
			'credit_cost' => 300000,
227
			'exp_gain' => 270,
228
		],
229
		PLANET_RADAR => [
230
			'max_amount' => 10,
231
			'base_time' => 64800,
232
			'credit_cost' => 1000000,
233
			'exp_gain' => 540,
234
		],
235
	];
236
	protected function getStructureData() : array {
237
		return self::STRUCTURES;
238
	}
239
	public function name() : string {
240
		return "Protoplanet";
241
	}
242
	public function imageLink() : string {
243
		return "images/planet5.png";
244
	}
245
	public function description() : string {
246
		return "A developing planet, not yet able to support the infrastructure of advanced technologies.";
247
	}
248
	public function maxAttackers() : int {
249
		return 5;
250
	}
251
	public function maxLanded() : int {
252
		return 5;
253
	}
254
	public function menuOptions() : array {
255
		return self::DEFAULT_MENU_OPTIONS;
256
	}
257
}
258
259
class DefenseWorld extends SmrPlanetType {
260
	const STRUCTURES = [
261
		PLANET_GENERATOR => [
262
			'max_amount' => 800,
263
			'base_time' => 2700,
264
			'credit_cost' => 500,
265
			'exp_gain' => 9,
266
		],
267
		PLANET_HANGAR => [
268
			'max_amount' => 3500,
269
			'base_time' => 5400,
270
			'credit_cost' => 500,
271
			'exp_gain' => 18,
272
		],
273
		PLANET_TURRET => [
274
			'max_amount' => 550,
275
			'base_time' => 18200,
276
			'credit_cost' => 5000,
277
			'exp_gain' => 54,
278
		],
279
		PLANET_BUNKER => [
280
			'max_amount' => 500,
281
			'base_time' => 2500,
282
			'credit_cost' => 250,
283
			'exp_gain' => 9,
284
		],
285
	];
286
	protected function getStructureData() : array {
287
		return self::STRUCTURES;
288
	}
289
	public function name() : string {
290
		return "Defense World";
291
	}
292
	public function imageLink() : string {
293
		return "images/planet4.png";
294
	}
295
	public function description() : string {
296
		return "A fully armed and operational battle station loaded with excessive firepower.";
297
	}
298
	public function maxAttackers() : int {
299
		return 10;
300
	}
301
	public function maxLanded() : int {
302
		return self::MAX_LANDED_UNLIMITED;
303
	}
304
	public function menuOptions() : array {
305
		return self::DEFAULT_MENU_OPTIONS;
306
	}
307
}
308