mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
More typehints, documentation fixes and static analysis cleanup
This commit is contained in:
@ -52,7 +52,7 @@ interface Permissible extends ServerOperator{
|
||||
*
|
||||
* @return PermissionAttachment
|
||||
*/
|
||||
public function addAttachment(Plugin $plugin, $name = null, $value = null);
|
||||
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment;
|
||||
|
||||
/**
|
||||
* @param PermissionAttachment $attachment
|
||||
|
@ -122,13 +122,11 @@ class PermissibleBase implements Permissible{
|
||||
*
|
||||
* @param Plugin $plugin
|
||||
* @param string $name
|
||||
* @param bool $value
|
||||
* @param bool $value
|
||||
*
|
||||
* @return PermissionAttachment
|
||||
*
|
||||
* @throws PluginException
|
||||
*/
|
||||
public function addAttachment(Plugin $plugin, $name = null, $value = null){
|
||||
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{
|
||||
if(!$plugin->isEnabled()){
|
||||
throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
|
||||
}
|
||||
|
@ -40,11 +40,11 @@ class Permission{
|
||||
public static $DEFAULT_PERMISSION = self::DEFAULT_OP;
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param bool|string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getByName($value){
|
||||
public static function getByName($value) : string{
|
||||
if(is_bool($value)){
|
||||
if($value === true){
|
||||
return "true";
|
||||
@ -86,7 +86,7 @@ class Permission{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $children = [];
|
||||
private $children;
|
||||
|
||||
/** @var string */
|
||||
private $defaultValue;
|
||||
@ -99,7 +99,7 @@ class Permission{
|
||||
* @param string $defaultValue
|
||||
* @param Permission[] $children
|
||||
*/
|
||||
public function __construct($name, $description = null, $defaultValue = null, array $children = []){
|
||||
public function __construct(string $name, string $description = null, string $defaultValue = null, array $children = []){
|
||||
$this->name = $name;
|
||||
$this->description = $description ?? "";
|
||||
$this->defaultValue = $defaultValue ?? self::$DEFAULT_PERMISSION;
|
||||
@ -149,7 +149,7 @@ class Permission{
|
||||
/**
|
||||
* @param string $value
|
||||
*/
|
||||
public function setDescription($value){
|
||||
public function setDescription(string $value){
|
||||
$this->description = $value;
|
||||
}
|
||||
|
||||
@ -196,12 +196,12 @@ class Permission{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param $default
|
||||
* @param array $data
|
||||
* @param string $default
|
||||
*
|
||||
* @return Permission[]
|
||||
*/
|
||||
public static function loadPermissions(array $data, $default = self::DEFAULT_OP) : array{
|
||||
public static function loadPermissions(array $data, string $default = self::DEFAULT_OP) : array{
|
||||
$result = [];
|
||||
foreach($data as $key => $entry){
|
||||
$result[] = self::loadPermission($key, $entry, $default, $result);
|
||||
@ -220,7 +220,7 @@ class Permission{
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function loadPermission($name, array $data, $default = self::DEFAULT_OP, &$output = []){
|
||||
public static function loadPermission(string $name, array $data, string $default = self::DEFAULT_OP, array &$output = []) : Permission{
|
||||
$desc = null;
|
||||
$children = [];
|
||||
if(isset($data["default"])){
|
||||
|
@ -59,7 +59,7 @@ class PermissionAttachment{
|
||||
/**
|
||||
* @return Plugin
|
||||
*/
|
||||
public function getPlugin(){
|
||||
public function getPlugin() : Plugin{
|
||||
return $this->plugin;
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ class PermissionAttachment{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PermissionRemovedExecutor
|
||||
* @return PermissionRemovedExecutor|null
|
||||
*/
|
||||
public function getRemovalCallback(){
|
||||
return $this->removed;
|
||||
@ -80,14 +80,14 @@ class PermissionAttachment{
|
||||
/**
|
||||
* @return Permissible
|
||||
*/
|
||||
public function getPermissible(){
|
||||
public function getPermissible() : Permissible{
|
||||
return $this->permissible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool[]
|
||||
*/
|
||||
public function getPermissions(){
|
||||
public function getPermissions() : array{
|
||||
return $this->permissions;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ class PermissionAttachment{
|
||||
* @param string|Permission $name
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setPermission($name, $value){
|
||||
public function setPermission($name, bool $value){
|
||||
$name = $name instanceof Permission ? $name->getName() : $name;
|
||||
if(isset($this->permissions[$name])){
|
||||
if($this->permissions[$name] === $value){
|
||||
|
@ -31,25 +31,21 @@ class PermissionAttachmentInfo{
|
||||
/** @var string */
|
||||
private $permission;
|
||||
|
||||
/** @var PermissionAttachment */
|
||||
/** @var PermissionAttachment|null */
|
||||
private $attachment;
|
||||
|
||||
/** @var bool */
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param Permissible $permissible
|
||||
* @param string $permission
|
||||
* @param PermissionAttachment $attachment
|
||||
* @param bool $value
|
||||
* @param Permissible $permissible
|
||||
* @param string $permission
|
||||
* @param PermissionAttachment|null $attachment
|
||||
* @param bool $value
|
||||
*
|
||||
* @throws \InvalidStateException
|
||||
*/
|
||||
public function __construct(Permissible $permissible, $permission, $attachment, $value){
|
||||
if($permission === null){
|
||||
throw new \InvalidStateException("Permission may not be null");
|
||||
}
|
||||
|
||||
public function __construct(Permissible $permissible, string $permission, PermissionAttachment $attachment = null, bool $value){
|
||||
$this->permissible = $permissible;
|
||||
$this->permission = $permission;
|
||||
$this->attachment = $attachment;
|
||||
@ -59,19 +55,19 @@ class PermissionAttachmentInfo{
|
||||
/**
|
||||
* @return Permissible
|
||||
*/
|
||||
public function getPermissible(){
|
||||
public function getPermissible() : Permissible{
|
||||
return $this->permissible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPermission(){
|
||||
public function getPermission() : string{
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PermissionAttachment
|
||||
* @return PermissionAttachment|null
|
||||
*/
|
||||
public function getAttachment(){
|
||||
return $this->attachment;
|
||||
@ -80,7 +76,7 @@ class PermissionAttachmentInfo{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getValue(){
|
||||
public function getValue() : bool{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user