diff --git a/lib/php/lib/Base/TBase.php b/lib/php/lib/Base/TBase.php index 2bcb3c860f..594e6a5861 100644 --- a/lib/php/lib/Base/TBase.php +++ b/lib/php/lib/Base/TBase.php @@ -35,7 +35,8 @@ #[\AllowDynamicProperties] abstract class TBase { - public static $tmethod = [ + /** @var array */ + public static array $tmethod = [ TType::BOOL => 'Bool', TType::BYTE => 'Byte', TType::I16 => 'I16', diff --git a/lib/php/lib/ClassLoader/ThriftClassLoader.php b/lib/php/lib/ClassLoader/ThriftClassLoader.php index e30e5bca73..8ccccfb830 100644 --- a/lib/php/lib/ClassLoader/ThriftClassLoader.php +++ b/lib/php/lib/ClassLoader/ThriftClassLoader.php @@ -30,27 +30,27 @@ class ThriftClassLoader { /** * Namespaces path - * @var array + * + * @var array> */ - protected $namespaces = []; + protected array $namespaces = []; /** * Thrift definition paths - * @var array + * + * @var array> */ - protected $definitions = []; + protected array $definitions = []; /** * Do we use APCu cache ? - * @var boolean */ - protected $apcu = false; + protected bool $apcu = false; /** * APCu Cache prefix - * @var string */ - protected $apcu_prefix; + protected ?string $apcu_prefix; /** * Set autoloader to use APCu cache diff --git a/lib/php/lib/Exception/TApplicationException.php b/lib/php/lib/Exception/TApplicationException.php index 181f7b5d7c..bc2d0943ec 100644 --- a/lib/php/lib/Exception/TApplicationException.php +++ b/lib/php/lib/Exception/TApplicationException.php @@ -27,7 +27,8 @@ class TApplicationException extends TException { - public static $tspec = [ + /** @var array */ + public static array $tspec = [ 1 => [ 'var' => 'message', 'type' => TType::STRING, diff --git a/lib/php/lib/Exception/TException.php b/lib/php/lib/Exception/TException.php index 575d93bd52..ac212daef8 100644 --- a/lib/php/lib/Exception/TException.php +++ b/lib/php/lib/Exception/TException.php @@ -58,7 +58,8 @@ public function __construct($p1 = null, $p2 = 0) } } - public static $tmethod = [ + /** @var array */ + public static array $tmethod = [ TType::BOOL => 'Bool', TType::BYTE => 'Byte', TType::I16 => 'I16', diff --git a/lib/php/lib/Factory/TBinaryProtocolFactory.php b/lib/php/lib/Factory/TBinaryProtocolFactory.php index 7d54dcfce8..3d3016a940 100644 --- a/lib/php/lib/Factory/TBinaryProtocolFactory.php +++ b/lib/php/lib/Factory/TBinaryProtocolFactory.php @@ -31,14 +31,8 @@ */ class TBinaryProtocolFactory implements TProtocolFactory { - /** - * @var bool - */ - private $strictRead = false; - /** - * @var bool - */ - private $strictWrite = false; + private bool $strictRead = false; + private bool $strictWrite = false; /** * @param bool $strictRead diff --git a/lib/php/lib/Protocol/JSON/ListContext.php b/lib/php/lib/Protocol/JSON/ListContext.php index 8d996be15f..207cb47ee3 100644 --- a/lib/php/lib/Protocol/JSON/ListContext.php +++ b/lib/php/lib/Protocol/JSON/ListContext.php @@ -27,12 +27,10 @@ class ListContext extends BaseContext { - private $first = true; - private $protocol; + private bool $first = true; - public function __construct($protocol) + public function __construct(private TJSONProtocol $protocol) { - $this->protocol = $protocol; } public function write() diff --git a/lib/php/lib/Protocol/JSON/LookaheadReader.php b/lib/php/lib/Protocol/JSON/LookaheadReader.php index 70ddf3f4cc..25e6d9bf4e 100644 --- a/lib/php/lib/Protocol/JSON/LookaheadReader.php +++ b/lib/php/lib/Protocol/JSON/LookaheadReader.php @@ -23,15 +23,15 @@ namespace Thrift\Protocol\JSON; +use Thrift\Protocol\TJSONProtocol; + class LookaheadReader { - private $hasData = false; - private $data = []; - private $protocol; + private bool $hasData = false; + private string $data = ''; - public function __construct($protocol) + public function __construct(private TJSONProtocol $protocol) { - $this->protocol = $protocol; } public function read() diff --git a/lib/php/lib/Protocol/JSON/PairContext.php b/lib/php/lib/Protocol/JSON/PairContext.php index d9fe2b27f8..8f37559d72 100644 --- a/lib/php/lib/Protocol/JSON/PairContext.php +++ b/lib/php/lib/Protocol/JSON/PairContext.php @@ -27,13 +27,11 @@ class PairContext extends BaseContext { - private $first = true; - private $colon = true; - private $protocol = null; + private bool $first = true; + private bool $colon = true; - public function __construct($protocol) + public function __construct(private TJSONProtocol $protocol) { - $this->protocol = $protocol; } public function write() diff --git a/lib/php/lib/Protocol/SimpleJSON/ListContext.php b/lib/php/lib/Protocol/SimpleJSON/ListContext.php index 837afe23bb..2346d6a818 100644 --- a/lib/php/lib/Protocol/SimpleJSON/ListContext.php +++ b/lib/php/lib/Protocol/SimpleJSON/ListContext.php @@ -27,12 +27,10 @@ class ListContext extends Context { - protected $first = true; - private $protocol; + protected bool $first = true; - public function __construct($protocol) + public function __construct(private TSimpleJSONProtocol $protocol) { - $this->protocol = $protocol; } public function write() diff --git a/lib/php/lib/Protocol/SimpleJSON/MapContext.php b/lib/php/lib/Protocol/SimpleJSON/MapContext.php index 6f97c306da..87a5a236ad 100644 --- a/lib/php/lib/Protocol/SimpleJSON/MapContext.php +++ b/lib/php/lib/Protocol/SimpleJSON/MapContext.php @@ -23,12 +23,13 @@ namespace Thrift\Protocol\SimpleJSON; +use Thrift\Protocol\TSimpleJSONProtocol; + class MapContext extends StructContext { - protected $isKey = true; - private $protocol; + protected bool $isKey = true; - public function __construct($protocol) + public function __construct(TSimpleJSONProtocol $protocol) { parent::__construct($protocol); } diff --git a/lib/php/lib/Protocol/SimpleJSON/StructContext.php b/lib/php/lib/Protocol/SimpleJSON/StructContext.php index 9099a497f5..f0cd3bb4c0 100644 --- a/lib/php/lib/Protocol/SimpleJSON/StructContext.php +++ b/lib/php/lib/Protocol/SimpleJSON/StructContext.php @@ -27,13 +27,11 @@ class StructContext extends Context { - protected $first = true; - protected $colon = true; - private $protocol; + protected bool $first = true; + protected bool $colon = true; - public function __construct($protocol) + public function __construct(private TSimpleJSONProtocol $protocol) { - $this->protocol = $protocol; } public function write() diff --git a/lib/php/lib/Protocol/TBinaryProtocol.php b/lib/php/lib/Protocol/TBinaryProtocol.php index c0aca47e4d..4dfaaa3e03 100644 --- a/lib/php/lib/Protocol/TBinaryProtocol.php +++ b/lib/php/lib/Protocol/TBinaryProtocol.php @@ -35,8 +35,8 @@ class TBinaryProtocol extends TProtocol public const VERSION_MASK = 0xffff0000; public const VERSION_1 = 0x80010000; - protected $strictRead = false; - protected $strictWrite = true; + protected bool $strictRead = false; + protected bool $strictWrite = true; public function __construct($trans, $strictRead = false, $strictWrite = true) { diff --git a/lib/php/lib/Protocol/TCompactProtocol.php b/lib/php/lib/Protocol/TCompactProtocol.php index 54b091bf3e..49a4a7ede4 100644 --- a/lib/php/lib/Protocol/TCompactProtocol.php +++ b/lib/php/lib/Protocol/TCompactProtocol.php @@ -66,7 +66,8 @@ class TCompactProtocol extends TProtocol public const MAX_VARINT_BYTES = 10; // ceil(64/7); matches protobuf wire format - protected static $ctypes = [ + /** @var array */ + protected static array $ctypes = [ TType::STOP => TCompactProtocol::COMPACT_STOP, TType::BOOL => TCompactProtocol::COMPACT_TRUE, // used for collection TType::BYTE => TCompactProtocol::COMPACT_BYTE, @@ -82,7 +83,8 @@ class TCompactProtocol extends TProtocol TType::UUID => TCompactProtocol::COMPACT_UUID, ]; - protected static $ttypes = [ + /** @var array */ + protected static array $ttypes = [ TCompactProtocol::COMPACT_STOP => TType::STOP, TCompactProtocol::COMPACT_TRUE => TType::BOOL, // used for collection TCompactProtocol::COMPACT_FALSE => TType::BOOL, @@ -99,12 +101,14 @@ class TCompactProtocol extends TProtocol TCompactProtocol::COMPACT_UUID => TType::UUID, ]; - protected $state = TCompactProtocol::STATE_CLEAR; - protected $lastFid = 0; - protected $boolFid = null; - protected $boolValue = null; - protected $structs = []; - protected $containers = []; + protected int $state = TCompactProtocol::STATE_CLEAR; + protected ?int $lastFid = 0; + protected ?int $boolFid = null; + protected ?bool $boolValue = null; + /** @var list */ + protected array $structs = []; + /** @var list */ + protected array $containers = []; // Some varint / zigzag helper methods public function toZigZag($n, $bits) diff --git a/lib/php/lib/Protocol/TJSONProtocol.php b/lib/php/lib/Protocol/TJSONProtocol.php index 2148ed36a0..ac7450368e 100644 --- a/lib/php/lib/Protocol/TJSONProtocol.php +++ b/lib/php/lib/Protocol/TJSONProtocol.php @@ -164,9 +164,10 @@ private function getTypeIDForTypeName($name) return $result; } + /** @var list */ private array $contextStack = []; - private $context; - private $reader; + private BaseContext $context; + private LookaheadReader $reader; private function pushContext($c) { diff --git a/lib/php/lib/Protocol/TMultiplexedProtocol.php b/lib/php/lib/Protocol/TMultiplexedProtocol.php index 9e7d659056..779a4e3122 100644 --- a/lib/php/lib/Protocol/TMultiplexedProtocol.php +++ b/lib/php/lib/Protocol/TMultiplexedProtocol.php @@ -44,10 +44,8 @@ class TMultiplexedProtocol extends TProtocolDecorator /** * The name of service. - * - * @var string */ - private $serviceName; + private string $serviceName; /** * Constructor of TMultiplexedProtocol class. diff --git a/lib/php/lib/Protocol/TProtocolDecorator.php b/lib/php/lib/Protocol/TProtocolDecorator.php index 7c16de5af6..263c93e565 100644 --- a/lib/php/lib/Protocol/TProtocolDecorator.php +++ b/lib/php/lib/Protocol/TProtocolDecorator.php @@ -38,10 +38,8 @@ abstract class TProtocolDecorator extends TProtocol { /** * Instance of protocol, to which all operations will be forwarded. - * - * @var TProtocol */ - private $concreteProtocol; + private TProtocol $concreteProtocol; /** * Constructor of TProtocolDecorator class. diff --git a/lib/php/lib/Protocol/TSimpleJSONProtocol.php b/lib/php/lib/Protocol/TSimpleJSONProtocol.php index 805a8bc70f..640bf2e613 100644 --- a/lib/php/lib/Protocol/TSimpleJSONProtocol.php +++ b/lib/php/lib/Protocol/TSimpleJSONProtocol.php @@ -48,8 +48,9 @@ class TSimpleJSONProtocol extends TProtocol public const NAME_LIST = "lst"; public const NAME_SET = "set"; - protected $writeContext = null; - protected $writeContextStack = []; + protected ?Context $writeContext = null; + /** @var list */ + protected array $writeContextStack = []; /** * Push a new write context onto the stack. diff --git a/lib/php/lib/Server/TForkingServer.php b/lib/php/lib/Server/TForkingServer.php index 900a13013e..41819b751c 100644 --- a/lib/php/lib/Server/TForkingServer.php +++ b/lib/php/lib/Server/TForkingServer.php @@ -15,17 +15,15 @@ class TForkingServer extends TServer { /** * Flag for the main serving loop - * - * @var bool */ - private $stop = false; + private bool $stop = false; /** * List of children. * - * @var array + * @var array */ - protected $children = []; + protected array $children = []; /** * Listens for new client using the supplied diff --git a/lib/php/lib/Server/TServer.php b/lib/php/lib/Server/TServer.php index bbc9c44934..9c6ac7dcc7 100644 --- a/lib/php/lib/Server/TServer.php +++ b/lib/php/lib/Server/TServer.php @@ -20,40 +20,29 @@ abstract class TServer protected $processor; /** - * Server transport to be used for listening - * and accepting new clients - * - * @var TServerTransport + * Server transport to be used for listening and accepting new clients */ - protected $transport; + protected TServerTransport $transport; /** * Input transport factory - * - * @var TTransportFactoryInterface */ - protected $inputTransportFactory; + protected TTransportFactoryInterface $inputTransportFactory; /** * Output transport factory - * - * @var TTransportFactoryInterface */ - protected $outputTransportFactory; + protected TTransportFactoryInterface $outputTransportFactory; /** * Input protocol factory - * - * @var TProtocolFactory */ - protected $inputProtocolFactory; + protected TProtocolFactory $inputProtocolFactory; /** * Output protocol factory - * - * @var TProtocolFactory */ - protected $outputProtocolFactory; + protected TProtocolFactory $outputProtocolFactory; /** * Sets up all the factories, etc diff --git a/lib/php/lib/Server/TServerSocket.php b/lib/php/lib/Server/TServerSocket.php index 6c91a8409d..066135b422 100644 --- a/lib/php/lib/Server/TServerSocket.php +++ b/lib/php/lib/Server/TServerSocket.php @@ -35,30 +35,24 @@ class TServerSocket extends TServerTransport /** * Handle for the listener socket * - * @var resource + * @var resource|null */ protected $listener; /** * Port for the listener to listen on - * - * @var int */ - protected $port; + protected int $port; /** * Timeout when listening for a new client - * - * @var int */ - protected $acceptTimeout = 30000; + protected int $acceptTimeout = 30000; /** * Host to listen on - * - * @var string */ - protected $host; + protected string $host; /** * ServerSocket constructor diff --git a/lib/php/lib/Server/TSimpleServer.php b/lib/php/lib/Server/TSimpleServer.php index 4b07011add..1cc5916608 100644 --- a/lib/php/lib/Server/TSimpleServer.php +++ b/lib/php/lib/Server/TSimpleServer.php @@ -13,10 +13,8 @@ class TSimpleServer extends TServer { /** * Flag for the main serving loop - * - * @var bool */ - private $stop = false; + private bool $stop = false; /** * Listens for new client using the supplied diff --git a/lib/php/lib/StoredMessageProtocol.php b/lib/php/lib/StoredMessageProtocol.php index 5363ec797c..9895421942 100644 --- a/lib/php/lib/StoredMessageProtocol.php +++ b/lib/php/lib/StoredMessageProtocol.php @@ -33,9 +33,9 @@ */ class StoredMessageProtocol extends TProtocolDecorator { - private $fname; - private $mtype; - private $rseqid; + private string $fname; + private int $mtype; + private int $rseqid; public function __construct(TProtocol $protocol, $fname, $mtype, $rseqid) { diff --git a/lib/php/lib/TMultiplexedProcessor.php b/lib/php/lib/TMultiplexedProcessor.php index f0e87508f1..869e6983ac 100644 --- a/lib/php/lib/TMultiplexedProcessor.php +++ b/lib/php/lib/TMultiplexedProcessor.php @@ -52,7 +52,10 @@ class TMultiplexedProcessor { - private $serviceProcessorMap; + /** + * @var array + */ + private array $serviceProcessorMap = []; /** * 'Register' a service with this TMultiplexedProcessor. This diff --git a/lib/php/lib/Transport/TBufferedTransport.php b/lib/php/lib/Transport/TBufferedTransport.php index 2f4c01abeb..3fd36000ca 100644 --- a/lib/php/lib/Transport/TBufferedTransport.php +++ b/lib/php/lib/Transport/TBufferedTransport.php @@ -36,38 +36,28 @@ class TBufferedTransport extends TTransport { /** * The underlying transport - * - * @var TTransport */ - protected $transport; + protected TTransport $transport; /** * The receive buffer size - * - * @var int */ - protected $rBufSize = 512; + protected int $rBufSize = 512; /** * The write buffer size - * - * @var int */ - protected $wBufSize = 512; + protected int $wBufSize = 512; /** * The write buffer. - * - * @var string */ - protected $wBuf = ''; + protected string $wBuf = ''; /** * The read buffer. - * - * @var string */ - protected $rBuf = ''; + protected string $rBuf = ''; /** * Constructor. Creates a buffered transport around an underlying transport diff --git a/lib/php/lib/Transport/TCurlClient.php b/lib/php/lib/Transport/TCurlClient.php index fa94b139ee..46979f0a37 100644 --- a/lib/php/lib/Transport/TCurlClient.php +++ b/lib/php/lib/Transport/TCurlClient.php @@ -32,70 +32,59 @@ */ class TCurlClient extends TTransport { + /** @var \CurlHandle|null */ private static $curlHandle; /** * The host to connect to - * - * @var string */ - protected $host; + protected string $host; /** * The port to connect on - * - * @var int */ - protected $port; + protected int $port; /** * The URI to request - * - * @var string */ - protected $uri; + protected string $uri; /** * The scheme to use for the request, i.e. http, https - * - * @var string */ - protected $scheme; + protected string $scheme; /** * Buffer for the HTTP request data - * - * @var string */ - protected $request; + protected string $request; /** - * Buffer for the HTTP response data. - * - * @var binary string + * Buffer for the HTTP response data. `false` reflects a failed curl_exec. */ - protected $response; + protected string|false|null $response; /** * Read timeout * - * @var float + * @var float|int|null */ protected $timeout; /** * Connection timeout * - * @var float + * @var float|int|null */ protected $connectionTimeout; /** * http headers * - * @var array + * @var array */ - protected $headers; + protected array $headers; /** * Make a new HTTP client. diff --git a/lib/php/lib/Transport/TFramedTransport.php b/lib/php/lib/Transport/TFramedTransport.php index 732bc813c6..6738577e6f 100644 --- a/lib/php/lib/Transport/TFramedTransport.php +++ b/lib/php/lib/Transport/TFramedTransport.php @@ -33,38 +33,28 @@ class TFramedTransport extends TTransport { /** * Underlying transport object. - * - * @var TTransport */ - private $transport; + private ?TTransport $transport; /** * Buffer for read data. - * - * @var string */ - private $rBuf = ''; + private string $rBuf = ''; /** * Buffer for queued output data - * - * @var string */ - private $wBuf = ''; + private string $wBuf = ''; /** * Whether to frame reads - * - * @var bool */ - private $read; + private bool $read; /** * Whether to frame writes - * - * @var bool */ - private $write; + private bool $write; /** * Constructor. diff --git a/lib/php/lib/Transport/THttpClient.php b/lib/php/lib/Transport/THttpClient.php index a65420afd5..807855ba91 100644 --- a/lib/php/lib/Transport/THttpClient.php +++ b/lib/php/lib/Transport/THttpClient.php @@ -34,66 +34,56 @@ class THttpClient extends TTransport { /** * The host to connect to - * - * @var string */ - protected $host; + protected string $host; /** * The port to connect on - * - * @var int */ - protected $port; + protected int $port; /** * The URI to request - * - * @var string */ - protected $uri; + protected string $uri; /** * The scheme to use for the request, i.e. http, https - * - * @var string */ - protected $scheme; + protected string $scheme; /** * Buffer for the HTTP request data - * - * @var string */ - protected $buf; + protected string $buf; /** * Input socket stream. * - * @var resource + * @var resource|null */ protected $handle; /** * Read timeout * - * @var float + * @var float|int|null */ protected $timeout; /** * http headers * - * @var array + * @var array */ - protected $headers; + protected array $headers; /** * Context additional options * - * @var array + * @var array */ - protected $context; + protected array $context; /** * Make a new HTTP client. diff --git a/lib/php/lib/Transport/TMemoryBuffer.php b/lib/php/lib/Transport/TMemoryBuffer.php index 62227a992b..275bbe58db 100644 --- a/lib/php/lib/Transport/TMemoryBuffer.php +++ b/lib/php/lib/Transport/TMemoryBuffer.php @@ -35,7 +35,7 @@ */ class TMemoryBuffer extends TTransport { - protected $buf = ''; + protected string $buf = ''; /** * Constructor. Optionally pass an initial value diff --git a/lib/php/lib/Transport/TPhpStream.php b/lib/php/lib/Transport/TPhpStream.php index 21782de5cb..d540d4eb77 100644 --- a/lib/php/lib/Transport/TPhpStream.php +++ b/lib/php/lib/Transport/TPhpStream.php @@ -36,13 +36,15 @@ class TPhpStream extends TTransport public const MODE_R = 1; public const MODE_W = 2; + /** @var resource|null */ private $inStream = null; + /** @var resource|null */ private $outStream = null; - private $read = false; + private bool $read = false; - private $write = false; + private bool $write = false; public function __construct($mode) { diff --git a/lib/php/lib/Transport/TSocket.php b/lib/php/lib/Transport/TSocket.php index a8af569e62..f72eeb963b 100644 --- a/lib/php/lib/Transport/TSocket.php +++ b/lib/php/lib/Transport/TSocket.php @@ -36,80 +36,62 @@ class TSocket extends TTransport /** * Handle to PHP socket * - * @var resource + * @var resource|null */ protected $handle = null; /** * Remote hostname - * - * @var string */ - protected $host = 'localhost'; + protected string $host = 'localhost'; /** * Remote port - * - * @var int */ - protected $port = '9090'; + protected int $port = 9090; /** * Send timeout in seconds. * * Combined with sendTimeoutUsec this is used for send timeouts. - * - * @var int */ - protected $sendTimeoutSec = 0; + protected int $sendTimeoutSec = 0; /** * Send timeout in microseconds. * * Combined with sendTimeoutSec this is used for send timeouts. - * - * @var int */ - protected $sendTimeoutUsec = 100000; + protected int $sendTimeoutUsec = 100000; /** * Recv timeout in seconds * * Combined with recvTimeoutUsec this is used for recv timeouts. - * - * @var int */ - protected $recvTimeoutSec = 0; + protected int $recvTimeoutSec = 0; /** * Recv timeout in microseconds * * Combined with recvTimeoutSec this is used for recv timeouts. - * - * @var int */ - protected $recvTimeoutUsec = 750000; + protected int $recvTimeoutUsec = 750000; /** * Persistent socket or plain? - * - * @var bool */ - protected $persist = false; + protected bool $persist = false; /** * Debugging on? - * - * @var bool */ - protected $debug = false; + protected bool $debug = false; /** * Debug handler - * - * @var mixed */ - protected $debugHandler = null; + protected mixed $debugHandler = null; /** * Socket constructor diff --git a/lib/php/lib/Transport/TSocketPool.php b/lib/php/lib/Transport/TSocketPool.php index 9049873bfe..bce50b43ee 100644 --- a/lib/php/lib/Transport/TSocketPool.php +++ b/lib/php/lib/Transport/TSocketPool.php @@ -35,50 +35,41 @@ class TSocketPool extends TSocket { /** * Remote servers. Array of associative arrays with 'host' and 'port' keys + * + * @var list */ - private $servers = []; + private array $servers = []; /** * How many times to retry each host in connect - * - * @var int */ - private $numRetries = 1; + private int $numRetries = 1; /** * Retry interval in seconds, how long to not try a host if it has been * marked as down. - * - * @var int */ - private $retryInterval = 60; + private int $retryInterval = 60; /** * Max consecutive failures before marking a host down. - * - * @var int */ - private $maxConsecutiveFailures = 1; + private int $maxConsecutiveFailures = 1; /** * Try hosts in order? or Randomized? - * - * @var bool */ - private $randomize = true; + private bool $randomize = true; /** * Always try last host, even if marked down? - * - * @var bool */ - private $alwaysTryLast = true; + private bool $alwaysTryLast = true; /** * Use apcu cache - * @var bool */ - private $useApcuCache; + private bool $useApcuCache; /** * Socket pool constructor @@ -94,7 +85,7 @@ public function __construct( $persist = false, $debugHandler = null ) { - parent::__construct(null, 0, $persist, $debugHandler); + parent::__construct('', 0, $persist, $debugHandler); if (!is_array($ports)) { $port = $ports; diff --git a/lib/php/test/Unit/Lib/Protocol/Fixture/JsonProtocolStub.php b/lib/php/test/Unit/Lib/Protocol/Fixture/JsonProtocolStub.php index 07f9602a8b..ef6aadc672 100644 --- a/lib/php/test/Unit/Lib/Protocol/Fixture/JsonProtocolStub.php +++ b/lib/php/test/Unit/Lib/Protocol/Fixture/JsonProtocolStub.php @@ -21,25 +21,21 @@ namespace Test\Thrift\Unit\Lib\Protocol\Fixture; -use Thrift\Transport\TTransport; +use Thrift\Protocol\TJSONProtocol; -class JsonProtocolStub +/** + * Test double for TJSONProtocol that captures readJSONSyntaxChar calls + * for inspection. Inherits getTransport() and the rest of the protocol + * machinery from TJSONProtocol so context-level tests can pass it where + * a real TJSONProtocol is expected. + */ +class JsonProtocolStub extends TJSONProtocol { - private $transport; - public $readChars = []; - - public function __construct(TTransport $transport) - { - $this->transport = $transport; - } - - public function getTransport(): TTransport - { - return $this->transport; - } + /** @var list */ + public array $readChars = []; - public function readJSONSyntaxChar(string $char): void + public function readJSONSyntaxChar($b): void { - $this->readChars[] = $char; + $this->readChars[] = $b; } } diff --git a/lib/php/test/Unit/Lib/Protocol/Fixture/SimpleJsonProtocolStub.php b/lib/php/test/Unit/Lib/Protocol/Fixture/SimpleJsonProtocolStub.php deleted file mode 100644 index e61795ea02..0000000000 --- a/lib/php/test/Unit/Lib/Protocol/Fixture/SimpleJsonProtocolStub.php +++ /dev/null @@ -1,39 +0,0 @@ -transport = $transport; - } - - public function getTransport(): TMemoryBuffer - { - return $this->transport; - } -} diff --git a/lib/php/test/Unit/Lib/Protocol/SimpleJsonContextTest.php b/lib/php/test/Unit/Lib/Protocol/SimpleJsonContextTest.php index b80c66e61e..9adcc92cb4 100644 --- a/lib/php/test/Unit/Lib/Protocol/SimpleJsonContextTest.php +++ b/lib/php/test/Unit/Lib/Protocol/SimpleJsonContextTest.php @@ -22,13 +22,13 @@ namespace Test\Thrift\Unit\Lib\Protocol; use PHPUnit\Framework\TestCase; -use Test\Thrift\Unit\Lib\Protocol\Fixture\SimpleJsonProtocolStub; use Thrift\Exception\TException; use Thrift\Protocol\SimpleJSON\CollectionMapKeyException; use Thrift\Protocol\SimpleJSON\Context; use Thrift\Protocol\SimpleJSON\ListContext; use Thrift\Protocol\SimpleJSON\MapContext; use Thrift\Protocol\SimpleJSON\StructContext; +use Thrift\Protocol\TSimpleJSONProtocol; use Thrift\Transport\TMemoryBuffer; class SimpleJsonContextTest extends TestCase @@ -44,7 +44,7 @@ public function testContextDefaults(): void public function testListContextWritesCommasAfterFirstElement(): void { $transport = new TMemoryBuffer(); - $context = new ListContext(new SimpleJsonProtocolStub($transport)); + $context = new ListContext(new TSimpleJSONProtocol($transport)); $context->write(); $context->write(); @@ -56,7 +56,7 @@ public function testListContextWritesCommasAfterFirstElement(): void public function testStructContextWritesColonsAndCommas(): void { $transport = new TMemoryBuffer(); - $context = new StructContext(new SimpleJsonProtocolStub($transport)); + $context = new StructContext(new TSimpleJSONProtocol($transport)); $context->write(); $context->write(); @@ -68,7 +68,7 @@ public function testStructContextWritesColonsAndCommas(): void public function testMapContextTogglesMapKeyState(): void { $transport = new TMemoryBuffer(); - $context = new MapContext(new SimpleJsonProtocolStub($transport)); + $context = new MapContext(new TSimpleJSONProtocol($transport)); $this->assertTrue($context->isMapKey());