and more typehints

This commit is contained in:
Dylan K. Taylor
2017-07-14 10:56:51 +01:00
parent b9355387da
commit c3b8be3f60
119 changed files with 598 additions and 541 deletions

View File

@ -28,24 +28,27 @@ use pocketmine\utils\MainLogger;
class BanEntry{
public static $format = "Y-m-d H:i:s O";
/** @var string */
private $name;
/** @var \DateTime */
private $creationDate = null;
/** @var string */
private $source = "(Unknown)";
/** @var \DateTime */
private $expirationDate = null;
/** @var string */
private $reason = "Banned by an operator.";
public function __construct($name){
public function __construct(string $name){
$this->name = strtolower($name);
$this->creationDate = new \DateTime();
}
public function getName(){
public function getName() : string{
return $this->name;
}
public function getCreated(){
public function getCreated() : \DateTime{
return $this->creationDate;
}
@ -53,40 +56,40 @@ class BanEntry{
$this->creationDate = $date;
}
public function getSource(){
public function getSource() : string{
return $this->source;
}
public function setSource($source){
public function setSource(string $source){
$this->source = $source;
}
public function getExpires(){
public function getExpires() : \DateTime{
return $this->expirationDate;
}
/**
* @param \DateTime $date
*/
public function setExpires($date){
public function setExpires(\DateTime $date){
$this->expirationDate = $date;
}
public function hasExpired(){
public function hasExpired() : bool{
$now = new \DateTime();
return $this->expirationDate === null ? false : $this->expirationDate < $now;
}
public function getReason(){
public function getReason() : string{
return $this->reason;
}
public function setReason($reason){
public function setReason(string $reason){
$this->reason = $reason;
}
public function getString(){
public function getString() : string{
$str = "";
$str .= $this->getName();
$str .= "|";

View File

@ -40,28 +40,28 @@ class BanList{
/**
* @param string $file
*/
public function __construct($file){
public function __construct(string $file){
$this->file = $file;
}
/**
* @return bool
*/
public function isEnabled(){
public function isEnabled() : bool{
return $this->enabled === true;
}
/**
* @param bool $flag
*/
public function setEnabled($flag){
$this->enabled = (bool) $flag;
public function setEnabled(bool $flag){
$this->enabled = $flag;
}
/**
* @return BanEntry[]
*/
public function getEntries(){
public function getEntries() : array{
$this->removeExpired();
return $this->list;
@ -72,7 +72,7 @@ class BanList{
*
* @return bool
*/
public function isBanned($name){
public function isBanned(string $name) : bool{
$name = strtolower($name);
if(!$this->isEnabled()){
return false;
@ -99,7 +99,7 @@ class BanList{
*
* @return BanEntry
*/
public function addBan($target, $reason = null, $expires = null, $source = null){
public function addBan(string $target, string $reason = null, \DateTime $expires = null, string $source = null) : BanEntry{
$entry = new BanEntry($target);
$entry->setSource($source != null ? $source : $entry->getSource());
$entry->setExpires($expires);
@ -114,7 +114,7 @@ class BanList{
/**
* @param string $name
*/
public function remove($name){
public function remove(string $name){
$name = strtolower($name);
if(isset($this->list[$name])){
unset($this->list[$name]);
@ -148,7 +148,10 @@ class BanList{
}
}
public function save($flag = true){
/**
* @param bool $flag
*/
public function save(bool $flag = true){
$this->removeExpired();
$fp = @fopen($this->file, "w");
if(is_resource($fp)){

View File

@ -34,7 +34,7 @@ abstract class DefaultPermissions{
*
* @return Permission
*/
public static function registerPermission(Permission $perm, Permission $parent = null){
public static function registerPermission(Permission $perm, Permission $parent = null) : Permission{
if($parent instanceof Permission){
$parent->getChildren()[$perm->getName()] = true;

View File

@ -34,16 +34,16 @@ interface Permissible extends ServerOperator{
*
* @return bool
*/
public function isPermissionSet($name);
public function isPermissionSet($name) : bool;
/**
* Returns the permission value if overridden, or the default value if not
*
* @param string|Permission $name
*
* @return mixed
* @return bool
*/
public function hasPermission($name);
public function hasPermission($name) : bool;
/**
* @param Plugin $plugin
@ -68,8 +68,8 @@ interface Permissible extends ServerOperator{
public function recalculatePermissions();
/**
* @return Permission[]
* @return PermissionAttachmentInfo[]
*/
public function getEffectivePermissions();
public function getEffectivePermissions() : array;
}

View File

@ -63,7 +63,7 @@ class PermissibleBase implements Permissible{
/**
* @return bool
*/
public function isOp(){
public function isOp() : bool{
if($this->opable === null){
return false;
}else{
@ -76,7 +76,7 @@ class PermissibleBase implements Permissible{
*
* @throws \Exception
*/
public function setOp($value){
public function setOp(bool $value){
if($this->opable === null){
throw new \LogicException("Cannot change op value as no ServerOperator is set");
}else{
@ -89,7 +89,7 @@ class PermissibleBase implements Permissible{
*
* @return bool
*/
public function isPermissionSet($name){
public function isPermissionSet($name) : bool{
return isset($this->permissions[$name instanceof Permission ? $name->getName() : $name]);
}
@ -98,7 +98,7 @@ class PermissibleBase implements Permissible{
*
* @return bool
*/
public function hasPermission($name){
public function hasPermission($name) : bool{
if($name instanceof Permission){
$name = $name->getName();
}
@ -214,7 +214,7 @@ class PermissibleBase implements Permissible{
/**
* @return PermissionAttachmentInfo[]
*/
public function getEffectivePermissions(){
public function getEffectivePermissions() : array{
return $this->permissions;
}
}

View File

@ -111,28 +111,28 @@ class Permission{
/**
* @return string
*/
public function getName(){
public function getName() : string{
return $this->name;
}
/**
* @return string[]
*/
public function &getChildren(){
public function &getChildren() : array{
return $this->children;
}
/**
* @return string
*/
public function getDefault(){
public function getDefault() : string{
return $this->defaultValue;
}
/**
* @param string $value
*/
public function setDefault($value){
public function setDefault(string $value){
if($value !== $this->defaultValue){
$this->defaultValue = $value;
$this->recalculatePermissibles();
@ -142,7 +142,7 @@ class Permission{
/**
* @return string
*/
public function getDescription(){
public function getDescription() : string{
return $this->description;
}
@ -156,7 +156,7 @@ class Permission{
/**
* @return Permissible[]
*/
public function getPermissibles(){
public function getPermissibles() : array{
return Server::getInstance()->getPluginManager()->getPermissionSubscriptions($this->name);
}
@ -201,7 +201,7 @@ class Permission{
*
* @return Permission[]
*/
public static function loadPermissions(array $data, $default = self::DEFAULT_OP){
public static function loadPermissions(array $data, $default = self::DEFAULT_OP) : array{
$result = [];
foreach($data as $key => $entry){
$result[] = self::loadPermission($key, $entry, $default, $result);

View File

@ -30,14 +30,12 @@ interface ServerOperator{
*
* @return bool
*/
public function isOp();
public function isOp() : bool;
/**
* Sets the operator permission for the current object
*
* @param bool $value
*
* @return void
*/
public function setOp($value);
public function setOp(bool $value);
}