More typehints, documentation fixes and static analysis cleanup

This commit is contained in:
Dylan K. Taylor
2017-07-15 12:12:06 +01:00
parent 24bdf330d5
commit dbb92096e4
66 changed files with 309 additions and 219 deletions

View File

@ -41,10 +41,9 @@ class RCON{
private $workers = [];
private $clientsPerThread;
public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
public function __construct(Server $server, string $password, int $port = 19132, string $interface = "0.0.0.0", int $threads = 1, int $clientsPerThread = 50){
$this->server = $server;
$this->workers = [];
$this->password = (string) $password;
$this->password = $password;
$this->server->getLogger()->info("Starting remote control listener");
if($this->password === ""){
throw new \InvalidArgumentException("Empty password");
@ -54,7 +53,7 @@ class RCON{
$this->clientsPerThread = (int) max(1, $clientsPerThread);
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($this->socket === false or !@socket_bind($this->socket, $interface, (int) $port) or !@socket_listen($this->socket)){
if($this->socket === false or !@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket)){
throw new \RuntimeException(trim(socket_strerror(socket_last_error())));
}

View File

@ -30,6 +30,7 @@ class RCONInstance extends Thread{
public $stop;
public $cmd;
public $response;
/** @var resource */
private $socket;
private $password;
private $maxClients;
@ -39,14 +40,18 @@ class RCONInstance extends Thread{
return $this->waiting === true;
}
public function __construct($socket, $password, $maxClients = 50){
/**
* @param resource $socket
* @param string $password
* @param int $maxClients
*/
public function __construct($socket, string $password, int $maxClients = 50){
$this->stop = false;
$this->cmd = "";
$this->response = "";
$this->socket = $socket;
$this->password = $password;
$this->maxClients = (int) $maxClients;
$this->maxClients = $maxClients;
for($n = 0; $n < $this->maxClients; ++$n){
$this->{"client" . $n} = null;
$this->{"status" . $n} = 0;
@ -192,7 +197,7 @@ class RCONInstance extends Thread{
exit(0);
}
public function getThreadName(){
public function getThreadName() : string{
return "RCON";
}
}