From 6c600548075db64b7857b4ff8daa935472d2ed1e Mon Sep 17 00:00:00 2001 From: Holger Woltersdorf Date: Sat, 18 Nov 2017 23:40:19 +0100 Subject: [PATCH] Fixes unqualified root level function usage --- src/Client.php | 8 ++--- src/Encoders/NameValuePairEncoder.php | 42 +++++++++++++-------------- src/Encoders/PacketEncoder.php | 32 ++++++++++---------- src/Requests/AbstractRequest.php | 2 +- src/Responses/Response.php | 2 +- src/Socket.php | 8 ++--- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Client.php b/src/Client.php index 3fef672..1cdd0df 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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.' ); } @@ -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); } /** @@ -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 ); } @@ -343,7 +343,7 @@ public function handleReadyResponses( $timeoutMs = null ) { $requestIds = $this->getRequestIdsHavingResponse(); - if ( count( $requestIds ) > 0 ) + if ( \count( $requestIds ) > 0 ) { $this->handleResponses( $timeoutMs, ...$requestIds ); } diff --git a/src/Encoders/NameValuePairEncoder.php b/src/Encoders/NameValuePairEncoder.php index 3eb3289..1e0997c 100644 --- a/src/Encoders/NameValuePairEncoder.php +++ b/src/Encoders/NameValuePairEncoder.php @@ -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; @@ -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); diff --git a/src/Encoders/PacketEncoder.php b/src/Encoders/PacketEncoder.php index 866d526..2372b5f 100644 --- a/src/Encoders/PacketEncoder.php +++ b/src/Encoders/PacketEncoder.php @@ -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; } diff --git a/src/Requests/AbstractRequest.php b/src/Requests/AbstractRequest.php index effef40..b320aa5 100644 --- a/src/Requests/AbstractRequest.php +++ b/src/Requests/AbstractRequest.php @@ -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 ) diff --git a/src/Responses/Response.php b/src/Responses/Response.php index 6819ea4..2e41ccc 100644 --- a/src/Responses/Response.php +++ b/src/Responses/Response.php @@ -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 diff --git a/src/Socket.php b/src/Socket.php index b5a668a..5459798 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -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 ); @@ -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, @@ -336,7 +336,7 @@ private function readPacket() while ( $length && ($buffer = fread( $this->resource, $length )) !== false ) { - $length -= strlen( $buffer ); + $length -= \strlen( $buffer ); $packet['content'] .= $buffer; } } @@ -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 ); }