Moar typehints

This commit is contained in:
Dylan K. Taylor
2017-07-05 18:21:04 +01:00
parent 08b8debd78
commit 8fc1501e89
14 changed files with 111 additions and 88 deletions

View File

@ -43,9 +43,9 @@ class AsyncPool{
/** @var int[] */
private $workerUsage = [];
public function __construct(Server $server, $size){
public function __construct(Server $server, int $size){
$this->server = $server;
$this->size = (int) $size;
$this->size = $size;
for($i = 0; $i < $this->size; ++$i){
$this->workerUsage[$i] = 0;
@ -55,12 +55,11 @@ class AsyncPool{
}
}
public function getSize(){
public function getSize() : int{
return $this->size;
}
public function increaseSize($newSize){
$newSize = (int) $newSize;
public function increaseSize(int $newSize){
if($newSize > $this->size){
for($i = $this->size; $i < $newSize; ++$i){
$this->workerUsage[$i] = 0;
@ -72,12 +71,11 @@ class AsyncPool{
}
}
public function submitTaskToWorker(AsyncTask $task, $worker){
public function submitTaskToWorker(AsyncTask $task, int $worker){
if(isset($this->tasks[$task->getTaskId()]) or $task->isGarbage()){
return;
}
$worker = (int) $worker;
if($worker < 0 or $worker >= $this->size){
throw new \InvalidArgumentException("Invalid worker $worker");
}
@ -106,7 +104,7 @@ class AsyncPool{
$this->submitTaskToWorker($task, $selectedWorker);
}
private function removeTask(AsyncTask $task, $force = false){
private function removeTask(AsyncTask $task, bool $force = false){
if(isset($this->taskWorkers[$task->getTaskId()])){
if(!$force and ($task->isRunning() or !$task->isGarbage())){
return;