Skip to content

Commit

Permalink
Max phpstan level
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Aug 29, 2024
1 parent 72aa7b3 commit 6b9cccb
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .test.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function testSetFromUrlCode404( string $URL ) : void
SteamID::SetFromURL( $URL, [ $this, 'fakeResolveVanityURL' ] );
}

public function testCsgoFriendCodes() : void
public function testRenderCsgoFriendCodes() : void
{
$a = new SteamID( '[U:1:12229257]' );
$this->assertEquals( 'ALQF4-BYCA', $a->RenderCsgoFriendCode() );
Expand All @@ -388,7 +388,10 @@ public function testCsgoFriendCodes() : void

$a = new SteamID( '[I:4:12229257:1048575]' );
$this->assertEquals( 'ALQF4-BYCA', $a->RenderCsgoFriendCode() );
}

public function testSetFromCsgoFriendCodes() : void
{
$a = ( new SteamID() )->SetFromCsgoFriendCode( 'ALQF4-BYCA' );
$this->assertEquals( '[U:1:12229257]', $a->RenderSteam3() );

Expand Down
7 changes: 2 additions & 5 deletions Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
// SetFromURL does all the heavy lifing of parsing the input
// This callback is only called to resolve vanity urls when required
$SteamID = SteamID::SetFromURL( $UserInput, function( string $URL, int $Type ) use ( $WebAPIKey )
$SteamID = SteamID::SetFromURL( $UserInput, function( string $URL, int $Type ) use ( $WebAPIKey ) : ?string
{
$Parameters =
[
Expand All @@ -35,12 +35,9 @@
] );

$Response = curl_exec( $c );

curl_close( $c );

$Response = json_decode( (string)$Response, true );

if( isset( $Response[ 'response' ][ 'success' ] ) )
if( is_array( $Response ) && isset( $Response[ 'response' ][ 'success' ] ) )
{
switch( (int)$Response[ 'response' ][ 'success' ] )
{
Expand Down
7 changes: 2 additions & 5 deletions VanityURLs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Lookup vanity urls via Steam web api
$WebAPIKey = 'YOUR WEBAPI KEY HERE';

$SteamID = SteamID::SetFromURL( 'https://steamcommunity.com/id/xpaw', function( string $URL, int $Type ) use ( $WebAPIKey )
$SteamID = SteamID::SetFromURL( 'https://steamcommunity.com/id/xpaw', function( string $URL, int $Type ) use ( $WebAPIKey ) : ?string
{
// This callback is only used to resolve vanity urls when required
$Parameters =
Expand All @@ -40,12 +40,9 @@
] );

$Response = curl_exec( $c );

curl_close( $c );

$Response = json_decode( (string)$Response, true );

if( isset( $Response[ 'response' ][ 'success' ] ) )
if( is_array( $Response ) && isset( $Response[ 'response' ][ 'success' ] ) )
{
switch( (int)$Response[ 'response' ][ 'success' ] )
{
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"require-dev":
{
"phpunit/phpunit": "^10.3",
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-strict-rules": "^1.6"
},
"scripts":
{
Expand Down
11 changes: 3 additions & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
checkMissingIterableValueType: true
checkFunctionNameCase: true
level: 8
level: max
paths:
- .
excludePaths:
- vendor
ignoreErrors:
-
message: "#^Comparison operation \"==\" between GMP and 65536 results in an error\\.$#"
count: 2
path: src/SteamID.php
8 changes: 4 additions & 4 deletions src/SteamID.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ public function RenderSteam3() : string
{
case self::TypeChat:
{
if( $AccountInstance & self::InstanceFlagClan )
if( ( $AccountInstance & self::InstanceFlagClan ) !== 0 )
{
$AccountTypeChar = 'c';
}
else if( $AccountInstance & self::InstanceFlagLobby )
else if( ( $AccountInstance & self::InstanceFlagLobby ) !== 0 )
{
$AccountTypeChar = 'L';
}
Expand Down Expand Up @@ -609,8 +609,8 @@ public function SetFromCsgoFriendCode( string $Value ) : self
) );

$IsGroup =
gmp_and( $Left, '0xFFFF0000' ) == 0x10000 &&
gmp_and( $Right, '0xFFFF0000' ) == 0x10000;
gmp_cmp( gmp_and( $Left, '0xFFFF0000' ), 0x10000 ) === 0 &&
gmp_cmp( gmp_and( $Right, '0xFFFF0000' ), 0x10000 ) === 0;

$this->SetAccountID( $AccountId );
$this->SetAccountType( $IsGroup ? self::TypeClan : self::TypeIndividual );
Expand Down

0 comments on commit 6b9cccb

Please sign in to comment.