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
Pull Request — main (#1508)
by Dan
04:48
created

TradeGood   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 53
rs 10
c 1
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getImageHTML() 0 2 1
A clearCache() 0 2 1
A get() 0 2 1
A __construct() 0 8 1
A getAll() 0 17 3
A getAllIDs() 0 2 1
1
<?php declare(strict_types=1);
2
3
namespace Smr;
4
5
class TradeGood {
6
7
	/** @var array<int, self> */
8
	private static array $CACHE_GOODS = [];
9
10
	public static function clearCache(): void {
11
		self::$CACHE_GOODS = [];
12
	}
13
14
	/**
15
	 * @return array<int, self>
16
	 */
17
	public static function getAll(): array {
18
		if (empty(self::$CACHE_GOODS)) {
19
			$db = Database::getInstance();
20
			$dbResult = $db->read('SELECT * FROM good');
21
			foreach ($dbResult->records() as $dbRecord) {
22
				$goodID = $dbRecord->getInt('good_id');
23
				self::$CACHE_GOODS[$goodID] = new self(
24
					id: $goodID,
25
					name: $dbRecord->getString('good_name'),
26
					maxPortAmount: $dbRecord->getInt('max_amount'),
27
					basePrice: $dbRecord->getInt('base_price'),
28
					class: $dbRecord->getInt('good_class'),
29
					alignRestriction: $dbRecord->getInt('align_restriction'),
30
				);
31
			}
32
		}
33
		return self::$CACHE_GOODS;
34
	}
35
36
	/**
37
	 * @return array<int>
38
	 */
39
	public static function getAllIDs(): array {
40
		return array_keys(self::getAll());
41
	}
42
43
	public static function get(int $goodID): self {
44
		return self::getAll()[$goodID];
45
	}
46
47
	public function __construct(
48
		public readonly int $id,
49
		public readonly string $name,
50
		public readonly int $maxPortAmount,
51
		public readonly int $basePrice,
52
		public readonly int $class,
53
		public readonly int $alignRestriction,
54
	) {}
55
56
	public function getImageHTML(): string {
57
		return '<img class="bottom" src="images/port/' . $this->id . '.png" width="13" height="16" title="' . $this->name . '" alt="' . $this->name . '" />';
58
	}
59
60
}
61