Skip to content

Commit 011a681

Browse files
committed
Max phpstan level, add checks for socket null
1 parent 90b87d3 commit 011a681

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

SourceQuery/GoldSourceRcon.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use xPaw\SourceQuery\Exception\AuthenticationException;
1818
use xPaw\SourceQuery\Exception\InvalidPacketException;
19+
use xPaw\SourceQuery\Exception\SocketException;
1920

2021
/**
2122
* Class GoldSourceRcon
@@ -53,18 +54,21 @@ public function Open( ) : void
5354

5455
public function Write( int $Header, string $String = '' ) : bool
5556
{
57+
if( $this->Socket->Socket === null )
58+
{
59+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
60+
}
61+
5662
$Command = pack( 'cccca*', 0xFF, 0xFF, 0xFF, 0xFF, $String );
5763
$Length = strlen( $Command );
5864

5965
return $Length === fwrite( $this->Socket->Socket, $Command, $Length );
6066
}
6167

6268
/**
63-
* @param int $Length
6469
* @throws AuthenticationException
65-
* @return Buffer
6670
*/
67-
public function Read( int $Length = 1400 ) : Buffer
71+
public function Read( ) : Buffer
6872
{
6973
// GoldSource RCON has same structure as Query
7074
$Buffer = $this->Socket->Read( );

SourceQuery/Socket.php

+15
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function Open( string $Address, int $Port, int $Timeout, int $Engine ) :
5858

5959
public function Write( int $Header, string $String = '' ) : bool
6060
{
61+
if( $this->Socket === null )
62+
{
63+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
64+
}
65+
6166
$Command = pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String );
6267
$Length = strlen( $Command );
6368

@@ -75,6 +80,11 @@ public function Write( int $Header, string $String = '' ) : bool
7580
*/
7681
public function Read( ) : Buffer
7782
{
83+
if( $this->Socket === null )
84+
{
85+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
86+
}
87+
7888
$Data = fread( $this->Socket, self::MaxPacketLength );
7989
$Buffer = new Buffer( );
8090
$Buffer->Set( $Data === false ? '' : $Data );
@@ -86,6 +96,11 @@ public function Read( ) : Buffer
8696

8797
public function Sherlock( Buffer $Buffer ) : bool
8898
{
99+
if( $this->Socket === null )
100+
{
101+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
102+
}
103+
89104
$Data = fread( $this->Socket, self::MaxPacketLength );
90105

91106
if( $Data === false || strlen( $Data ) < 4 )

SourceQuery/SourceRcon.php

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public function Open( ) : void
7474

7575
public function Write( int $Header, string $String = '' ) : bool
7676
{
77+
if( $this->RconSocket === null )
78+
{
79+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
80+
}
81+
7782
// Pack the packet together
7883
$Command = pack( 'VV', ++$this->RconRequestId, $Header ) . $String . "\x00\x00";
7984

@@ -86,6 +91,11 @@ public function Write( int $Header, string $String = '' ) : bool
8691

8792
public function Read( ) : Buffer
8893
{
94+
if( $this->RconSocket === null )
95+
{
96+
throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED );
97+
}
98+
8999
$Data = fread( $this->RconSocket, 4 );
90100
$Buffer = new Buffer( );
91101
$Buffer->Set( $Data === false ? '' : $Data );

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- vendor/phpstan/phpstan-strict-rules/rules.neon
33
parameters:
44
checkFunctionNameCase: true
5-
level: 7
5+
level: max
66
paths:
77
- .
88
excludePaths:

0 commit comments

Comments
 (0)