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 — master ( 9eaac4...d9a8b1 )
by Dan
04:15
created

SmrWeaponType::getRaceID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * Defines the base weapon types for ships/planets.
5
 */
6
class SmrWeaponType {
7
	use Traits\RaceID;
8
9
	protected static array $CACHE_WEAPON_TYPES = [];
10
11
	protected int $weaponTypeID;
12
	protected string $name;
13
	protected int $cost;
14
	protected int $shieldDamage;
15
	protected int $armourDamage;
16
	protected int $accuracy;
17
	protected int $powerLevel;
18
	protected int $buyerRestriction;
19
20
	public static function getWeaponType(int $weaponTypeID, SmrMySqlDatabase $db = null) : SmrWeaponType {
21
		if (!isset(self::$CACHE_WEAPON_TYPES[$weaponTypeID])) {
22
			if (is_null($db)) {
23
				$db = new SmrMySqlDatabase();
24
				$db->query('SELECT * FROM weapon_type WHERE weapon_type_id = ' . $db->escapeNumber($weaponTypeID));
25
				$db->requireRecord();
26
			}
27
			$weapon = new SmrWeaponType($weaponTypeID, $db);
28
			self::$CACHE_WEAPON_TYPES[$weaponTypeID] = $weapon;
29
		}
30
		return self::$CACHE_WEAPON_TYPES[$weaponTypeID];
31
	}
32
33
	public static function getAllWeaponTypes() : array {
34
		$db = new SmrMySqlDatabase();
35
		$db->query('SELECT * FROM weapon_type');
36
		$weapons = array();
37
		while ($db->nextRecord()) {
38
			$weaponTypeID = $db->getInt('weapon_type_id');
39
			$weapons[$weaponTypeID] = self::getWeaponType($weaponTypeID, $db);
40
		}
41
		return $weapons;
42
	}
43
44
	/**
45
	 * Returns all weapon types that are purchasable in the given game.
46
	 */
47
	public static function getAllSoldWeaponTypes(int $gameID) : array {
48
		$db = new SmrMySqlDatabase();
49
		$db->query('SELECT DISTINCT weapon_type.* FROM weapon_type JOIN location_sells_weapons USING (weapon_type_id) JOIN location USING (location_type_id) WHERE game_id = ' . $db->escapeNumber($gameID));
50
		$weapons = [];
51
		while ($db->nextRecord()) {
52
			$weaponTypeID = $db->getInt('weapon_type_id');
53
			$weapons[$weaponTypeID] = self::getWeaponType($weaponTypeID, $db);
54
		}
55
		return $weapons;
56
	}
57
58
	protected function __construct(int $weaponTypeID, SmrMySqlDatabase $db) {
59
		$this->weaponTypeID = $weaponTypeID;
60
		$this->name = $db->getField('weapon_name');
61
		$this->raceID = $db->getInt('race_id');
62
		$this->cost = $db->getInt('cost');
63
		$this->shieldDamage = $db->getInt('shield_damage');
64
		$this->armourDamage = $db->getInt('armour_damage');
65
		$this->accuracy = $db->getInt('accuracy');
66
		$this->powerLevel = $db->getInt('power_level');
67
		$this->buyerRestriction = $db->getInt('buyer_restriction');
68
	}
69
70
	public function getWeaponTypeID() {
71
		return $this->weaponTypeID;
72
	}
73
74
	public function getName() {
75
		return $this->name;
76
	}
77
78
	public function getCost() {
79
		return $this->cost;
80
	}
81
82
	public function getShieldDamage() {
83
		return $this->shieldDamage;
84
	}
85
86
	public function getArmourDamage() {
87
		return $this->armourDamage;
88
	}
89
90
	public function getAccuracy() {
91
		return $this->accuracy;
92
	}
93
94
	public function getPowerLevel() {
95
		return $this->powerLevel;
96
	}
97
98
	public function getBuyerRestriction() {
99
		return $this->buyerRestriction;
100
	}
101
102
}
103