Modernize private property declarations in src/permission

This commit is contained in:
Dylan K. Taylor 2022-05-17 21:28:42 +01:00
parent 6eac2ea7a5
commit 22edca610c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
6 changed files with 32 additions and 65 deletions

View File

@ -36,16 +36,11 @@ class BanEntry{
/** @var string */ /** @var string */
public static $format = "Y-m-d H:i:s O"; public static $format = "Y-m-d H:i:s O";
/** @var string */ private string $name;
private $name; private \DateTime $creationDate;
/** @var \DateTime */ private string $source = "(Unknown)";
private $creationDate; private ?\DateTime $expirationDate = null;
/** @var string */ private string $reason = "Banned by an operator.";
private $source = "(Unknown)";
/** @var \DateTime|null */
private $expirationDate = null;
/** @var string */
private $reason = "Banned by an operator.";
public function __construct(string $name){ public function __construct(string $name){
$this->name = strtolower($name); $this->name = strtolower($name);

View File

@ -32,19 +32,14 @@ use function strtolower;
use function trim; use function trim;
class BanList{ class BanList{
/** @var BanEntry[] */ /** @var BanEntry[] */
private $list = []; private array $list = [];
/** @var string */ private bool $enabled = true;
private $file;
/** @var bool */ public function __construct(
private $enabled = true; private string $file
){}
public function __construct(string $file){
$this->file = $file;
}
public function isEnabled() : bool{ public function isEnabled() : bool{
return $this->enabled; return $this->enabled;

View File

@ -44,19 +44,19 @@ class PermissibleInternal implements Permissible{
* @var bool[] * @var bool[]
* @phpstan-var array<string, bool> * @phpstan-var array<string, bool>
*/ */
private $rootPermissions; private array $rootPermissions;
/** @var PermissionAttachment[] */ /** @var PermissionAttachment[] */
private $attachments = []; private array $attachments = [];
/** @var PermissionAttachmentInfo[] */ /** @var PermissionAttachmentInfo[] */
private $permissions = []; private array $permissions = [];
/** /**
* @var ObjectSet|\Closure[] * @var ObjectSet|\Closure[]
* @phpstan-var ObjectSet<\Closure(array<string, bool> $changedPermissionsOldValues) : void> * @phpstan-var ObjectSet<\Closure(array<string, bool> $changedPermissionsOldValues) : void>
*/ */
private $permissionRecalculationCallbacks; private ObjectSet $permissionRecalculationCallbacks;
/** /**
* @param bool[] $basePermissions * @param bool[] $basePermissions

View File

@ -31,17 +31,7 @@ namespace pocketmine\permission;
* Represents a permission * Represents a permission
*/ */
class Permission{ class Permission{
/** @var string */ private string $description;
private $name;
/** @var string */
private $description;
/**
* @var bool[]
* @phpstan-var array<string, bool>
*/
private $children;
/** /**
* Creates a new Permission object to be attached to Permissible objects * Creates a new Permission object to be attached to Permissible objects
@ -49,10 +39,12 @@ class Permission{
* @param bool[] $children * @param bool[] $children
* @phpstan-param array<string, bool> $children * @phpstan-param array<string, bool> $children
*/ */
public function __construct(string $name, ?string $description = null, array $children = []){ public function __construct(
$this->name = $name; private string $name,
$this->description = $description ?? ""; ?string $description = null,
$this->children = $children; private array $children = []
){
$this->description = $description ?? ""; //TODO: wtf ????
$this->recalculatePermissibles(); $this->recalculatePermissibles();
} }

View File

@ -29,26 +29,23 @@ use function spl_object_id;
class PermissionAttachment{ class PermissionAttachment{
/** @var bool[] */ /** @var bool[] */
private $permissions = []; private array $permissions = [];
/** /**
* @var PermissibleInternal[] * @var PermissibleInternal[]
* @phpstan-var array<int, PermissibleInternal> * @phpstan-var array<int, PermissibleInternal>
*/ */
private $subscribers = []; private array $subscribers = [];
/** @var Plugin */
private $plugin;
/** /**
* @throws PluginException * @throws PluginException
*/ */
public function __construct(Plugin $plugin){ public function __construct(
private Plugin $plugin
){
if(!$plugin->isEnabled()){ if(!$plugin->isEnabled()){
throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
} }
$this->plugin = $plugin;
} }
public function getPlugin() : Plugin{ public function getPlugin() : Plugin{

View File

@ -24,24 +24,12 @@ declare(strict_types=1);
namespace pocketmine\permission; namespace pocketmine\permission;
class PermissionAttachmentInfo{ class PermissionAttachmentInfo{
/** @var string */ public function __construct(
private $permission; private string $permission,
private ?PermissionAttachment $attachment,
/** @var PermissionAttachment|null */ private bool $value,
private $attachment; private ?PermissionAttachmentInfo $groupPermission
){}
/** @var bool */
private $value;
/** @var PermissionAttachmentInfo|null */
private $groupPermission;
public function __construct(string $permission, ?PermissionAttachment $attachment, bool $value, ?PermissionAttachmentInfo $groupPermission){
$this->permission = $permission;
$this->attachment = $attachment;
$this->value = $value;
$this->groupPermission = $groupPermission;
}
public function getPermission() : string{ public function getPermission() : string{
return $this->permission; return $this->permission;