Skip to content

Commit 6d19794

Browse files
committed
Update to PHP 8
1 parent b19c276 commit 6d19794

File tree

10 files changed

+80
-178
lines changed

10 files changed

+80
-178
lines changed

.github/workflows/php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup PHP
2525
uses: shivammathur/setup-php@v2
2626
with:
27-
php-version: 7.4
27+
php-version: 8.2
2828
extensions: gd, imagick, mbstring
2929

3030
- name: Validate composer.json and composer.lock

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
],
1717
"config": {
1818
"platform": {
19-
"php": "7.3.31"
19+
"php": "8.2.7"
2020
}
2121
},
2222
"require": {
23-
"php": "~7.3",
24-
"randomhost/image": "~2.0",
23+
"php": "~8.0",
24+
"randomhost/image": "~3.0-beta",
2525
"ext-mbstring": "*"
2626
},
2727
"require-dev": {

src/php/API.php

+5-13
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,18 @@ class API
5959

6060
/**
6161
* Steam Web API key.
62-
*
63-
* @var string
6462
*/
65-
protected $key = '';
63+
protected string $key = '';
6664

6765
/**
6866
* \Memcached instance.
69-
*
70-
* @var null|\Memcached
7167
*/
72-
protected $memcached;
68+
protected ?\Memcached $memcached = null;
7369

7470
/**
7571
* Toggles Memcached usage.
76-
*
77-
* @var bool
7872
*/
79-
protected $memcachedUsage = true;
73+
protected bool $memcachedUsage = true;
8074

8175
/**
8276
* Constructor for this class.
@@ -262,10 +256,8 @@ protected function getMemcachedKey(string $key): string
262256
* If no data is stored, null is returned.
263257
*
264258
* @param string $key Key of the item to retrieve.
265-
*
266-
* @return null|mixed
267259
*/
268-
protected function getMemcachedValue(string $key)
260+
protected function getMemcachedValue(string $key): mixed
269261
{
270262
if (is_null($this->memcached) || !$this->getMemcachedUsage()) {
271263
return null;
@@ -287,7 +279,7 @@ protected function getMemcachedValue(string $key)
287279
* @param mixed $data Value to store.
288280
* @param int $ttl Expiration time (default: 0).
289281
*/
290-
protected function setMemcachedValue(string $key, $data, int $ttl): bool
282+
protected function setMemcachedValue(string $key, mixed $data, int $ttl): bool
291283
{
292284
if (is_null($this->memcached) || !$this->getMemcachedUsage()) {
293285
return true;

src/php/Dto/User/Game.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,20 @@ class Game
1717
{
1818
/**
1919
* Game ID of the game the user is currently playing.
20-
*
21-
* @var string
2220
*/
23-
protected $id = '0';
21+
protected string $id = '0';
2422

2523
/**
2624
* IP and port of the game server the user is currently playing on.
27-
*
28-
* @var string
2925
*/
30-
protected $serverIp = '0.0.0.0:0';
26+
protected string $serverIp = '0.0.0.0:0';
3127

3228
/**
3329
* Name of the game the user is playing.
3430
*
3531
* This may be the name of a non-Steam game shortcut.
36-
*
37-
* @var string
3832
*/
39-
protected $extraInfo = '';
33+
protected string $extraInfo = '';
4034

4135
/**
4236
* Sets the game ID of the game the user is currently playing.

src/php/Dto/User/General.php

+28-52
Original file line numberDiff line numberDiff line change
@@ -41,77 +41,63 @@ class General
4141
*
4242
* @var array
4343
*/
44-
protected static $personaStateMapping
45-
= [
46-
self::PERSONA_STATE_OFFLINE => 'offline',
47-
self::PERSONA_STATE_ONLINE => 'online',
48-
self::PERSONA_STATE_BUSY => 'busy',
49-
self::PERSONA_STATE_AWAY => 'away',
50-
self::PERSONA_STATE_SNOOZE => 'snooze',
51-
self::PERSONA_STATE_LOOKING_TO_TRADE => 'looking to trade',
52-
self::PERSONA_STATE_LOOKING_TO_PLAY => 'looking to play',
53-
];
44+
protected const PERSONA_STATE_MAPPING = [
45+
self::PERSONA_STATE_OFFLINE => 'offline',
46+
self::PERSONA_STATE_ONLINE => 'online',
47+
self::PERSONA_STATE_BUSY => 'busy',
48+
self::PERSONA_STATE_AWAY => 'away',
49+
self::PERSONA_STATE_SNOOZE => 'snooze',
50+
self::PERSONA_STATE_LOOKING_TO_TRADE => 'looking to trade',
51+
self::PERSONA_STATE_LOOKING_TO_PLAY => 'looking to play',
52+
];
5453

5554
/**
5655
* Mapping of community visibility state integer values to strings.
5756
*
5857
* @var array
5958
*/
60-
protected static $communityVisibilityStateMapping
61-
= [
62-
self::COMMUNITY_VISIBILITY_STATE_PRIVATE => 'private',
63-
self::COMMUNITY_VISIBILITY_STATE_PUBLIC => 'public',
64-
];
59+
protected const COMMUNITY_VISIBILITY_STATE_MAPPING = [
60+
self::COMMUNITY_VISIBILITY_STATE_PRIVATE => 'private',
61+
self::COMMUNITY_VISIBILITY_STATE_PUBLIC => 'public',
62+
];
6563

6664
/**
6765
* 64bit SteamID of the user.
6866
*
6967
* This is of type string to be compatible with 32-bit systems
70-
*
71-
* @var string
7268
*/
73-
protected $steamId = '';
69+
protected string $steamId = '';
7470

7571
/**
7672
* User's display name.
77-
*
78-
* @var string
7973
*/
80-
protected $displayName = '';
74+
protected string $displayName = '';
8175

8276
/**
8377
* Full URL of the user's Steam community profile.
84-
*
85-
* @var string
8678
*/
87-
protected $profileUrl = '';
79+
protected string $profileUrl = '';
8880

8981
/**
9082
* Full URL of the user's 32x32px avatar.
9183
*
9284
* If the user hasn't configured an avatar, this will be the default ? avatar.
93-
*
94-
* @var string
9585
*/
96-
protected $avatar = '';
86+
protected string $avatar = '';
9787

9888
/**
9989
* Full URL of the user's 64x64px avatar.
10090
*
10191
* If the user hasn't configured an avatar, this will be the default ? avatar.
102-
*
103-
* @var string
10492
*/
105-
protected $avatarMedium = '';
93+
protected string $avatarMedium = '';
10694

10795
/**
10896
* Full URL of the user's 184x184px avatar.
10997
*
11098
* If the user hasn't configured an avatar, this will be the default ? avatar.
111-
*
112-
* @var string
11399
*/
114-
protected $avatarFull = '';
100+
protected string $avatarFull = '';
115101

116102
/**
117103
* User's current status.
@@ -125,10 +111,8 @@ class General
125111
* 6 - looking to play
126112
*
127113
* If the user's profile is private, this will always be "0".
128-
*
129-
* @var int
130114
*/
131-
protected $personaState = 0;
115+
protected int $personaState = 0;
132116

133117
/**
134118
* This represents whether the profile is visible or not.
@@ -138,31 +122,23 @@ class General
138122
*
139123
* 1 - profile is not visible (Private, Friends Only, etc.)
140124
* 3 - profile is "Public"
141-
*
142-
* @var int
143125
*/
144-
protected $communityVisibilityState = 0;
126+
protected int $communityVisibilityState = 0;
145127

146128
/**
147129
* Indicates if the user has a community profile configured.
148-
*
149-
* @var bool
150130
*/
151-
protected $profileState = false;
131+
protected bool $profileState = false;
152132

153133
/**
154134
* Last time the user was online as \DateTime object.
155-
*
156-
* @var null|\DateTime
157135
*/
158-
protected $lastLogoff;
136+
protected ?\DateTime $lastLogoff;
159137

160138
/**
161139
* Indicates if the profile allows public comments.
162-
*
163-
* @var bool
164140
*/
165-
protected $commentPermission = false;
141+
protected bool $commentPermission = false;
166142

167143
/**
168144
* Sets the 64bit SteamID of the user.
@@ -314,11 +290,11 @@ public function getPersonaState(): int
314290
public function getPersonaStateString(): string
315291
{
316292
$key = $this->getPersonaState();
317-
if (!array_key_exists($key, self::$personaStateMapping)) {
293+
if (!array_key_exists($key, self::PERSONA_STATE_MAPPING)) {
318294
return 'Unknown status: '.$key;
319295
}
320296

321-
return self::$personaStateMapping[$key];
297+
return self::PERSONA_STATE_MAPPING[$key];
322298
}
323299

324300
/**
@@ -347,11 +323,11 @@ public function getCommunityVisibilityState(): int
347323
public function getCommunityVisibilityStateString(): string
348324
{
349325
$key = $this->getCommunityVisibilityState();
350-
if (!array_key_exists($key, self::$communityVisibilityStateMapping)) {
326+
if (!array_key_exists($key, self::COMMUNITY_VISIBILITY_STATE_MAPPING)) {
351327
return 'Unknown profile visibility: '.$key;
352328
}
353329

354-
return self::$communityVisibilityStateMapping[$key];
330+
return self::COMMUNITY_VISIBILITY_STATE_MAPPING[$key];
355331
}
356332

357333
/**

src/php/Dto/User/Location.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,18 @@ class Location
1717
{
1818
/**
1919
* User's country of residence (ISO country code).
20-
*
21-
* @var string
2220
*/
23-
protected $countryCode = '';
21+
protected string $countryCode = '';
2422

2523
/**
2624
* User's state of residence.
27-
*
28-
* @var string
2925
*/
30-
protected $stateCode = '';
26+
protected string $stateCode = '';
3127

3228
/**
3329
* User's city of residence.
34-
*
35-
* @var int
3630
*/
37-
protected $cityId = 0;
31+
protected int $cityId = 0;
3832

3933
/**
4034
* Sets the user's country of residence (ISO country code).

src/php/Dto/User/Profile.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ class Profile
1717
{
1818
/**
1919
* General instance.
20-
*
21-
* @var null|General
2220
*/
23-
protected $dataUserGeneral;
21+
protected ?General $dataUserGeneral = null;
2422

2523
/**
2624
* Restricted instance.
27-
*
28-
* @var null|Restricted
2925
*/
30-
protected $dataUserRestricted;
26+
protected ?Restricted $dataUserRestricted = null;
3127

3228
/**
3329
* Constructor for this class.

src/php/Dto/User/Restricted.php

+8-18
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,28 @@ class Restricted
1717
{
1818
/**
1919
* Player's "Real Name".
20-
*
21-
* @var string
2220
*/
23-
protected $realName = '';
21+
protected string $realName = '';
2422

2523
/**
2624
* Player's primary group ID.
27-
*
28-
* @var string
2925
*/
30-
protected $primaryGroupId = '';
26+
protected string $primaryGroupId = '';
3127

3228
/**
3329
* Time the player's account was created.
34-
*
35-
* @var null|\DateTime
3630
*/
37-
protected $timeCreated;
31+
protected ?\DateTime $timeCreated = null;
3832

3933
/**
4034
* Game data of the game the user is currently playing.
41-
*
42-
* @var null|Game
4335
*/
44-
protected $gameData;
36+
protected ?Game $gameData = null;
4537

4638
/**
4739
* Player's location data.
48-
*
49-
* @var null|Location
5040
*/
51-
protected $locationData;
41+
protected ?Location $locationData = null;
5242

5343
/**
5444
* Sets the player's "Real Name".
@@ -93,7 +83,7 @@ public function getPrimaryGroupId(): string
9383
/**
9484
* Sets the time the player's account was created.
9585
*
96-
* @param null|\DateTime $timeCreated Time the player's account was created.
86+
* @param \DateTime $timeCreated Time the player's account was created.
9787
*/
9888
public function setTimeCreated(\DateTime $timeCreated): self
9989
{
@@ -113,7 +103,7 @@ public function getTimeCreated(): ?\DateTime
113103
/**
114104
* Sets the game data of the game the user is currently playing.
115105
*
116-
* @param null|Game $gameData Game data of the game the user is currently playing.
106+
* @param Game $gameData Game data of the game the user is currently playing.
117107
*/
118108
public function setGameData(Game $gameData): self
119109
{
@@ -133,7 +123,7 @@ public function getGameData(): ?Game
133123
/**
134124
* Sets the player's location data.
135125
*
136-
* @param null|Location $locationData Player's location data.
126+
* @param Location $locationData Player's location data.
137127
*/
138128
public function setLocationData(Location $locationData): self
139129
{

0 commit comments

Comments
 (0)