Skip to content

Commit 1f45cac

Browse files
committed
Add proper phpstan types for arrays
1 parent 892d909 commit 1f45cac

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

Examples/View.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$Query = new SourceQuery( );
1818

19-
$Info = [];
19+
$Info = null;
2020
$Rules = [];
2121
$Players = [];
2222
$Exception = null;
@@ -105,7 +105,7 @@
105105
</tr>
106106
</thead>
107107
<tbody>
108-
<?php if( !empty( $Info ) ): ?>
108+
<?php if( $Info !== null ): ?>
109109
<?php foreach( $Info as $InfoKey => $InfoValue ): ?>
110110
<tr>
111111
<td><?php echo htmlspecialchars( $InfoKey ); ?></td>
@@ -128,7 +128,7 @@
128128
}
129129
else
130130
{
131-
echo htmlspecialchars( $InfoValue );
131+
echo htmlspecialchars( (string)$InfoValue );
132132
}
133133
}
134134
?></td>
@@ -152,7 +152,7 @@
152152
</tr>
153153
</thead>
154154
<tbody>
155-
<?php if( !empty( $Players ) ): ?>
155+
<?php if( count( $Players ) > 0 ): ?>
156156
<?php foreach( $Players as $Player ): ?>
157157
<tr>
158158
<td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
@@ -178,7 +178,7 @@
178178
</tr>
179179
</thead>
180180
<tbody>
181-
<?php if( !empty( $Rules ) ): ?>
181+
<?php if( count( $Rules ) > 0 ): ?>
182182
<?php foreach( $Rules as $Rule => $Value ): ?>
183183
<tr>
184184
<td><?php echo htmlspecialchars( $Rule ); ?></td>

SourceQuery/Buffer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function Set( string $Buffer ) : void
5050
* Get remaining bytes
5151
*
5252
* @return int Remaining bytes in buffer
53+
*
54+
* @phpstan-impure
5355
*/
5456
public function Remaining( ) : int
5557
{

SourceQuery/SourceQuery.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,42 @@ public function Ping( ) : bool
185185
* @throws InvalidPacketException
186186
* @throws SocketException
187187
*
188-
* @return array Returns an array with information on success
188+
* @return array{
189+
* Protocol: int,
190+
* HostName: string,
191+
* Map: string,
192+
* ModDir: string,
193+
* ModDesc: string,
194+
* AppID?: int,
195+
* Players: int,
196+
* MaxPlayers: int,
197+
* Bots: int,
198+
* Dedicated: string,
199+
* Os: string,
200+
* Password: bool,
201+
* Secure: bool,
202+
* Version?: string,
203+
* ExtraDataFlags?: int,
204+
* GamePort?: int,
205+
* SteamID?: string|int,
206+
* SpecPort?: int,
207+
* SpecName?: string,
208+
* GameTags?: string,
209+
* GameID?: int,
210+
* Address?: string,
211+
* IsMod?: bool,
212+
* Mod?: array{
213+
* Url: string,
214+
* Download: string,
215+
* Version: int,
216+
* Size: int,
217+
* ServerSide: bool,
218+
* CustomDLL: bool
219+
* },
220+
* GameMode?: int,
221+
* WitnessCount?: int,
222+
* WitnessTime?: int
223+
* } Returns an array with server information on success
189224
*/
190225
public function GetInfo( ) : array
191226
{
@@ -364,7 +399,7 @@ public function GetInfo( ) : array
364399
* @throws InvalidPacketException
365400
* @throws SocketException
366401
*
367-
* @return array Returns an array with players on success
402+
* @return array<int, array{Id: int, Name: string, Frags: int, Time: int, TimeF: string}> Returns an array with players on success
368403
*/
369404
public function GetPlayers( ) : array
370405
{
@@ -409,7 +444,7 @@ public function GetPlayers( ) : array
409444
* @throws InvalidPacketException
410445
* @throws SocketException
411446
*
412-
* @return array Returns an array with rules on success
447+
* @return array<string, string> Returns an array with rules on success
413448
*/
414449
public function GetRules( ) : array
415450
{
@@ -438,7 +473,7 @@ public function GetRules( ) : array
438473
$Rule = $Buffer->ReadNullTermString( );
439474
$Value = $Buffer->ReadNullTermString( );
440475

441-
if( !empty( $Rule ) )
476+
if( strlen( $Rule ) > 0 )
442477
{
443478
$Rules[ $Rule ] = $Value;
444479
}

phpstan.neon

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ parameters:
77
- .
88
excludePaths:
99
- vendor
10-
- Examples/View.php
1110
strictRules:
1211
booleansInConditions: false
1312
ignoreErrors:
1413
- identifier: missingType.iterableValue
15-
- identifier: empty.notAllowed
14+
path: Tests/Tests.php
1615
- identifier: cast.int
16+
path: SourceQuery/Buffer.php
1717
- identifier: cast.double
18-
19-
-
20-
message: "#^Comparison operation \"\\>\" between int\\<1, max\\> and 0 is always true\\.$#"
21-
count: 1
22-
path: SourceQuery/SourceQuery.php
18+
path: SourceQuery/Buffer.php

0 commit comments

Comments
 (0)