Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/php/lib/Base/TBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ abstract public function read(TProtocol $input): int;

abstract public function write(TProtocol $output): int;

/**
* @param array<int, array<string, mixed>>|null $spec
* @param array<string, mixed>|null $vals
*/
public function __construct(?array $spec = null, ?array $vals = null)
{
if (is_array($spec) && is_array($vals)) {
Expand All @@ -68,9 +72,15 @@ public function __construct(?array $spec = null, ?array $vals = null)

public function __wakeup(): void
{
$this->__construct(get_object_vars($this));
// PHP restores instance state automatically on unserialize();
// re-invoking __construct() with get_object_vars() was a no-op
// (it would short-circuit because the second parameter is null)
// and tripped strict-mode type checks on the first parameter.
}

/**
* @param array<string, mixed> $spec
*/
private function readMap(mixed &$var, array $spec, TProtocol $input): int
{
$xfer = 0;
Expand Down Expand Up @@ -139,6 +149,9 @@ private function readMap(mixed &$var, array $spec, TProtocol $input): int
return $xfer;
}

/**
* @param array<string, mixed> $spec
*/
private function readList(mixed &$var, array $spec, TProtocol $input, bool $set = false): int
{
$xfer = 0;
Expand Down Expand Up @@ -194,6 +207,9 @@ private function readList(mixed &$var, array $spec, TProtocol $input, bool $set
return $xfer;
}

/**
* @param array<int, array<string, mixed>> $spec
*/
protected function readStruct(string $class, array $spec, TProtocol $input): int
{
$xfer = 0;
Expand Down Expand Up @@ -245,6 +261,10 @@ protected function readStruct(string $class, array $spec, TProtocol $input): int
return $xfer;
}

/**
* @param array<int|string, mixed> $var
* @param array<string, mixed> $spec
*/
private function writeMap(array $var, array $spec, TProtocol $output): int
{
$xfer = 0;
Expand Down Expand Up @@ -305,6 +325,10 @@ private function writeMap(array $var, array $spec, TProtocol $output): int
return $xfer;
}

/**
* @param array<int|string, mixed> $var
* @param array<string, mixed> $spec
*/
private function writeList(array $var, array $spec, TProtocol $output, bool $set = false): int
{
$xfer = 0;
Expand Down Expand Up @@ -350,6 +374,9 @@ private function writeList(array $var, array $spec, TProtocol $output, bool $set
return $xfer;
}

/**
* @param array<int, array<string, mixed>> $spec
*/
protected function writeStruct(string $class, array $spec, TProtocol $output): int
{
$xfer = 0;
Expand Down
8 changes: 5 additions & 3 deletions lib/php/lib/ClassLoader/ThriftClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ public function loadClass(string $class): void
*/
protected function findFileInApcu(string $class): ?string
{
if (false === $file = apcu_fetch($this->apcu_prefix . $class)) {
apcu_store($this->apcu_prefix . $class, $file = $this->findFile($class));
$file = apcu_fetch($this->apcu_prefix . $class);
if ($file === false) {
$file = $this->findFile($class);
apcu_store($this->apcu_prefix . $class, $file);
}

return $file !== false ? $file : null;
return is_string($file) ? $file : null;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions lib/php/lib/Exception/TException.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#[\AllowDynamicProperties]
class TException extends \Exception
{
/**
* @param string|array<int, array<string, mixed>>|null $p1
* @param int|array<string, mixed> $p2
*/
public function __construct(string|array|null $p1 = null, int|array $p2 = 0)
{
if (is_array($p1) && is_array($p2)) {
Expand Down Expand Up @@ -73,6 +77,9 @@ public function __construct(string|array|null $p1 = null, int|array $p2 = 0)
TType::UUID => 'Uuid',
];

/**
* @param array<string, mixed> $spec
*/
private function readMap(mixed &$var, array $spec, TProtocol $input): int
{
$xfer = 0;
Expand Down Expand Up @@ -141,6 +148,9 @@ private function readMap(mixed &$var, array $spec, TProtocol $input): int
return $xfer;
}

/**
* @param array<string, mixed> $spec
*/
private function readList(mixed &$var, array $spec, TProtocol $input, bool $set = false): int
{
$xfer = 0;
Expand Down Expand Up @@ -196,6 +206,9 @@ private function readList(mixed &$var, array $spec, TProtocol $input, bool $set
return $xfer;
}

/**
* @param array<int, array<string, mixed>> $spec
*/
protected function readStruct(string $class, array $spec, TProtocol $input): int
{
$xfer = 0;
Expand Down Expand Up @@ -247,6 +260,10 @@ protected function readStruct(string $class, array $spec, TProtocol $input): int
return $xfer;
}

/**
* @param array<int|string, mixed> $var
* @param array<string, mixed> $spec
*/
private function writeMap(array $var, array $spec, TProtocol $output): int
{
$xfer = 0;
Expand Down Expand Up @@ -307,6 +324,10 @@ private function writeMap(array $var, array $spec, TProtocol $output): int
return $xfer;
}

/**
* @param array<int|string, mixed> $var
* @param array<string, mixed> $spec
*/
private function writeList(array $var, array $spec, TProtocol $output, bool $set = false): int
{
$xfer = 0;
Expand Down Expand Up @@ -352,6 +373,9 @@ private function writeList(array $var, array $spec, TProtocol $output, bool $set
return $xfer;
}

/**
* @param array<int, array<string, mixed>> $spec
*/
protected function writeStruct(string $class, array $spec, TProtocol $output): int
{
$xfer = 0;
Expand Down
9 changes: 6 additions & 3 deletions lib/php/lib/Protocol/TJSONProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ class TJSONProtocol extends TProtocol

public const VERSION = 1;

public static $JSON_CHAR_TABLE = [
/** @var array<int, int|string> */
public static array $JSON_CHAR_TABLE = [
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, // 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1
1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 2
];

public static $ESCAPE_CHARS = ['"', '\\', '/', "b", "f", "n", "r", "t"];
/** @var list<string> */
public static array $ESCAPE_CHARS = ['"', '\\', '/', "b", "f", "n", "r", "t"];

public static $ESCAPE_CHAR_VALS = [
/** @var list<string> */
public static array $ESCAPE_CHAR_VALS = [
'"', '\\', '/', "\x08", "\f", "\n", "\r", "\t",
];

Expand Down
7 changes: 5 additions & 2 deletions lib/php/lib/Serializer/TBinarySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TBinarySerializer
// a transport in which to serialize an object. It has to
// be a string. Otherwise we will break the compatibility with
// normal deserialization.
public static function serialize($object)
public static function serialize(object $object): string
{
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocolAccelerated($transport);
Expand All @@ -66,7 +66,10 @@ public static function serialize($object)
return $transport->getBuffer();
}

public static function deserialize($string_object, $class_name, $buffer_size = 8192)
/**
* @param class-string $class_name
*/
public static function deserialize(string $string_object, string $class_name, int $buffer_size = 8192): object
{
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocolAccelerated($transport);
Expand Down
2 changes: 1 addition & 1 deletion lib/php/lib/Server/TServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
abstract class TServer
{
public function __construct(
protected $processor,
protected object $processor,
protected TServerTransport $transport,
protected TTransportFactoryInterface $inputTransportFactory,
protected TTransportFactoryInterface $outputTransportFactory,
Expand Down
3 changes: 2 additions & 1 deletion lib/php/lib/Transport/TSSLSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class TSSLSocket extends TSocket
/**
* Socket constructor
*
* @param resource|null $context Stream context
* @param resource|null $context Stream context
* @param callable|string|null $debugHandler
*/
public function __construct(
string $host = 'localhost',
Expand Down
2 changes: 2 additions & 0 deletions lib/php/lib/Transport/TSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class TSocket extends TTransport

/**
* Socket constructor
*
* @param callable|string|null $debugHandler
*/
public function __construct(
protected string $host = 'localhost',
Expand Down
13 changes: 6 additions & 7 deletions lib/php/lib/Transport/TSocketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ class TSocketPool extends TSocket
/**
* Socket pool constructor
*
* @param array $hosts List of remote hostnames
* @param mixed $ports Array of remote ports, or a single common port
* @param bool $persist Whether to use a persistent socket
* @param mixed $debugHandler Function for error logging
* @param list<string> $hosts List of remote hostnames
* @param int|list<int> $ports Array of remote ports, or a single common port
* @param callable|string|null $debugHandler Function for error logging
*/
public function __construct(
$hosts = ['localhost'],
$ports = [9090],
$persist = false,
array $hosts = ['localhost'],
int|array $ports = [9090],
bool $persist = false,
$debugHandler = null
) {
parent::__construct('', 0, $persist, $debugHandler);
Expand Down
4 changes: 2 additions & 2 deletions lib/php/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ parameters:
# admit int|string keys so this arm is defensive dead code and
# unreachable at runtime.
-
message: "#^(Cannot call method write\\(\\) on \\(int\\|string\\)|Parameter \\#1 \\$var of method Thrift\\\\(Base\\\\TBase|Exception\\\\TException)::write(Map|List)\\(\\) expects array, \\(int\\|string\\) given)\\.$#"
message: "#^(Cannot call method write\\(\\) on int\\|string|Parameter \\#1 \\$var of method Thrift\\\\(Base\\\\TBase|Exception\\\\TException)::write(Map|List)\\(\\) expects array<int\\|string, mixed>, int\\|string given)\\.$#"
count: 4
path: lib/Base/TBase.php
-
message: "#^(Cannot call method write\\(\\) on \\(int\\|string\\)|Parameter \\#1 \\$var of method Thrift\\\\(Base\\\\TBase|Exception\\\\TException)::write(Map|List)\\(\\) expects array, \\(int\\|string\\) given)\\.$#"
message: "#^(Cannot call method write\\(\\) on int\\|string|Parameter \\#1 \\$var of method Thrift\\\\(Base\\\\TBase|Exception\\\\TException)::write(Map|List)\\(\\) expects array<int\\|string, mixed>, int\\|string given)\\.$#"
count: 4
path: lib/Exception/TException.php
2 changes: 1 addition & 1 deletion lib/php/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 6
paths:
- lib
bootstrapFiles:
Expand Down
Loading