Skip to content

Commit

Permalink
Fixes unqualified root level function usage
Browse files Browse the repository at this point in the history
  • Loading branch information
hollodotme committed Nov 18, 2017
1 parent 0b9a710 commit 6c60054
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function waitForResponse( int $requestId, $timeoutMs = null )
*/
public function waitForResponses( $timeoutMs = null )
{
if ( count( $this->sockets ) === 0 )
if ( \count( $this->sockets ) === 0 )
{
throw new ReadFailedException( 'No pending requests found.' );
}
Expand Down Expand Up @@ -216,7 +216,7 @@ private function fetchResponseAndNotifyCallback( Socket $socket, $timeoutMs = nu
*/
public function hasUnhandledResponses() : bool
{
return (count( $this->sockets ) > 0);
return (\count( $this->sockets ) > 0);
}

/**
Expand Down Expand Up @@ -307,7 +307,7 @@ public function readReadyResponses( $timeoutMs = null ) : \Generator
{
$requestIds = $this->getRequestIdsHavingResponse();

if ( count( $requestIds ) > 0 )
if ( \count( $requestIds ) > 0 )
{
yield from $this->readResponses( $timeoutMs, ...$requestIds );
}
Expand Down Expand Up @@ -343,7 +343,7 @@ public function handleReadyResponses( $timeoutMs = null )
{
$requestIds = $this->getRequestIdsHavingResponse();

if ( count( $requestIds ) > 0 )
if ( \count( $requestIds ) > 0 )
{
$this->handleResponses( $timeoutMs, ...$requestIds );
}
Expand Down
42 changes: 21 additions & 21 deletions src/Encoders/NameValuePairEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,34 @@ public function encodePairs( array $pairs ) : string

public function encodePair( string $name, string $value ) : string
{
$nameLength = strlen( $name );
$valueLength = strlen( $value );
$nameLength = \strlen( $name );
$valueLength = \strlen( $value );

if ( $nameLength < 128 )
{
/* nameLengthB0 */
$nameValuePair = chr( $nameLength );
$nameValuePair = \chr( $nameLength );
}
else
{
/* nameLengthB3 & nameLengthB2 & nameLengthB1 & nameLengthB0 */
$nameValuePair = chr( ($nameLength >> 24) | 0x80 )
. chr( ($nameLength >> 16) & 0xFF )
. chr( ($nameLength >> 8) & 0xFF )
. chr( $nameLength & 0xFF );
$nameValuePair = \chr( ($nameLength >> 24) | 0x80 )
. \chr( ($nameLength >> 16) & 0xFF )
. \chr( ($nameLength >> 8) & 0xFF )
. \chr( $nameLength & 0xFF );
}
if ( $valueLength < 128 )
{
/* valueLengthB0 */
$nameValuePair .= chr( $valueLength );
$nameValuePair .= \chr( $valueLength );
}
else
{
/* valueLengthB3 & valueLengthB2 & valueLengthB1 & valueLengthB0 */
$nameValuePair .= chr( ($valueLength >> 24) | 0x80 )
. chr( ($valueLength >> 16) & 0xFF )
. chr( ($valueLength >> 8) & 0xFF )
. chr( $valueLength & 0xFF );
$nameValuePair .= \chr( ($valueLength >> 24) | 0x80 )
. \chr( ($valueLength >> 16) & 0xFF )
. \chr( ($valueLength >> 8) & 0xFF )
. \chr( $valueLength & 0xFF );
}

return $nameValuePair . $name . $value;
Expand All @@ -84,29 +84,29 @@ public function decodePairs( string $data, int $length = -1 ) : array

if ( $length === -1 )
{
$length = strlen( $data );
$length = \strlen( $data );
}

$p = 0;

while ( $p !== $length )
{
$nameLength = ord( $data{$p++} );
$nameLength = \ord( $data{$p++} );
if ( $nameLength >= 128 )
{
$nameLength &= (0x7F << 24);
$nameLength |= (ord( $data{$p++} ) << 16);
$nameLength |= (ord( $data{$p++} ) << 8);
$nameLength |= ord( $data{$p++} );
$nameLength |= (\ord( $data{$p++} ) << 16);
$nameLength |= (\ord( $data{$p++} ) << 8);
$nameLength |= \ord( $data{$p++} );
}

$valueLength = ord( $data{$p++} );
$valueLength = \ord( $data{$p++} );
if ( $valueLength >= 128 )
{
$valueLength = ($nameLength & 0x7F << 24);
$valueLength |= (ord( $data{$p++} ) << 16);
$valueLength |= (ord( $data{$p++} ) << 8);
$valueLength |= ord( $data{$p++} );
$valueLength |= (\ord( $data{$p++} ) << 16);
$valueLength |= (\ord( $data{$p++} ) << 8);
$valueLength |= \ord( $data{$p++} );
}
$array[ substr( $data, $p, $nameLength ) ] = substr( $data, $p + $nameLength, $valueLength );
$p += ($nameLength + $valueLength);
Expand Down
32 changes: 16 additions & 16 deletions src/Encoders/PacketEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ final class PacketEncoder implements EncodesPacket

public function encodePacket( int $type, string $content, int $requestId ) : string
{
$contentLength = strlen( $content );
$contentLength = \strlen( $content );

return chr( self::VERSION ) /* version */
. chr( $type ) /* type */
. chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
. chr( $requestId & 0xFF ) /* requestIdB0 */
. chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
. chr( $contentLength & 0xFF ) /* contentLengthB0 */
. chr( 0 ) /* paddingLength */
. chr( 0 ) /* reserved */
. $content; /* content */
return \chr( self::VERSION ) /* version */
. \chr( $type ) /* type */
. \chr( ($requestId >> 8) & 0xFF ) /* requestIdB1 */
. \chr( $requestId & 0xFF ) /* requestIdB0 */
. \chr( ($contentLength >> 8) & 0xFF ) /* contentLengthB1 */
. \chr( $contentLength & 0xFF ) /* contentLengthB0 */
. \chr( 0 ) /* paddingLength */
. \chr( 0 ) /* reserved */
. $content; /* content */
}

public function decodeHeader( string $data ) : array
{
$header = [];
$header['version'] = ord( $data{0} );
$header['type'] = ord( $data{1} );
$header['requestId'] = (ord( $data{2} ) << 8) + ord( $data{3} );
$header['contentLength'] = (ord( $data{4} ) << 8) + ord( $data{5} );
$header['paddingLength'] = ord( $data{6} );
$header['reserved'] = ord( $data{7} );
$header['version'] = \ord( $data{0} );
$header['type'] = \ord( $data{1} );
$header['requestId'] = (\ord( $data{2} ) << 8) + \ord( $data{3} );
$header['contentLength'] = (\ord( $data{4} ) << 8) + \ord( $data{5} );
$header['paddingLength'] = \ord( $data{6} );
$header['reserved'] = \ord( $data{7} );

return $header;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getContent() : string
public function setContent( string $content )
{
$this->content = $content;
$this->contentLength = strlen( $content );
$this->contentLength = \strlen( $content );
}

public function setCustomVar( string $key, $value )
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function parseHeadersAndBody()
break;
}

$this->body = implode( PHP_EOL, array_slice( $lines, $offset + 2 ) );
$this->body = implode( PHP_EOL, \array_slice( $lines, $offset + 2 ) );
}

public function getRequestId() : int
Expand Down
8 changes: 4 additions & 4 deletions src/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function getRequestPackets( ProvidesRequestData $request ) : string
# Keep alive bit always set to 1
$requestPackets = $this->packetEncoder->encodePacket(
self::BEGIN_REQUEST,
chr( 0 ) . chr( self::RESPONDER ) . chr( 1 ) . str_repeat( chr( 0 ), 5 ),
\chr( 0 ) . \chr( self::RESPONDER ) . \chr( 1 ) . str_repeat( \chr( 0 ), 5 ),
$this->id
);

Expand Down Expand Up @@ -303,7 +303,7 @@ public function fetchResponse( $timeoutMs = null ) : ProvidesResponseData
try
{
$this->handleNullPacket( $packet );
$this->guardRequestCompleted( ord( $packet['content']{4} ) );
$this->guardRequestCompleted( \ord( $packet['content']{4} ) );

$this->response = new Response(
$this->id,
Expand Down Expand Up @@ -336,7 +336,7 @@ private function readPacket()

while ( $length && ($buffer = fread( $this->resource, $length )) !== false )
{
$length -= strlen( $buffer );
$length -= \strlen( $buffer );
$packet['content'] .= $buffer;
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ private function guardRequestCompleted( int $flag )

private function disconnect()
{
if ( is_resource( $this->resource ) )
if ( \is_resource( $this->resource ) )
{
fclose( $this->resource );
}
Expand Down

0 comments on commit 6c60054

Please sign in to comment.