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

@ -25,7 +25,6 @@ namespace pocketmine\scheduler;
use pocketmine\Collectable;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
/**
* Class used to run async tasks in other threads.
@ -47,7 +46,7 @@ abstract class AsyncTask extends Collectable{
private $result = null;
private $serialized = false;
private $cancelRun = false;
/** @var int */
/** @var int|null */
private $taskId = null;
private $crashed = false;
@ -90,7 +89,7 @@ abstract class AsyncTask extends Collectable{
$this->setGarbage();
}
public function isCrashed(){
public function isCrashed() : bool{
return $this->crashed;
}
@ -105,14 +104,14 @@ abstract class AsyncTask extends Collectable{
$this->cancelRun = true;
}
public function hasCancelledRun(){
public function hasCancelledRun() : bool{
return $this->cancelRun === true;
}
/**
* @return bool
*/
public function hasResult(){
public function hasResult() : bool{
return $this->result !== null;
}
@ -120,15 +119,18 @@ abstract class AsyncTask extends Collectable{
* @param mixed $result
* @param bool $serialize
*/
public function setResult($result, $serialize = true){
public function setResult($result, bool $serialize = true){
$this->result = $serialize ? serialize($result) : $result;
$this->serialized = $serialize;
}
public function setTaskId($taskId){
public function setTaskId(int $taskId){
$this->taskId = $taskId;
}
/**
* @return int|null
*/
public function getTaskId(){
return $this->taskId;
}
@ -140,7 +142,7 @@ abstract class AsyncTask extends Collectable{
* @param string $identifier
* @return mixed
*/
public function getFromThreadStore($identifier){
public function getFromThreadStore(string $identifier){
global $store;
return ($this->isGarbage() or !isset($store[$identifier])) ? null : $store[$identifier];
}
@ -152,7 +154,7 @@ abstract class AsyncTask extends Collectable{
* @param string $identifier
* @param mixed $value
*/
public function saveToThreadStore($identifier, $value){
public function saveToThreadStore(string $identifier, $value){
global $store;
if(!$this->isGarbage()){
$store[$identifier] = $value;