mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 03:52:30 +01:00 
			
		
		
		
	Replacing public properties by getters and setters
This commit is contained in:
		
							
								
								
									
										6
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
								
							| @ -31,6 +31,12 @@ | ||||
|       "label": "robo : upgrade", | ||||
|       "problemMatcher": [], | ||||
|       "type": "shell" | ||||
|     }, | ||||
|     { | ||||
|       "command": "robo watch", | ||||
|       "label": "robo : watch", | ||||
|       "problemMatcher": [], | ||||
|       "type": "shell" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
|  | ||||
| @ -13,27 +13,22 @@ class PayloadCommit implements \JsonSerializable { | ||||
|   /** | ||||
|    * @var PayloadUser|null The person who authored the commit. | ||||
|    */ | ||||
|   public $author; | ||||
|   private $author; | ||||
|  | ||||
|   /** | ||||
|    * @var PayloadUser|null The person who committed the code. | ||||
|    */ | ||||
|   public $committer; | ||||
|   private $committer; | ||||
|  | ||||
|   /** | ||||
|    * @var string The commit hash. | ||||
|    */ | ||||
|   public $id = ''; | ||||
|   private $id; | ||||
|  | ||||
|   /** | ||||
|    * @var string The commit message. | ||||
|    */ | ||||
|   public $message = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var PayloadCommitVerification|null The GPG verification of this commit. | ||||
|    */ | ||||
|   public $verification; | ||||
|   private $message; | ||||
|  | ||||
|   /** | ||||
|    * @var \DateTime|null The commit date. | ||||
| @ -45,21 +40,65 @@ class PayloadCommit implements \JsonSerializable { | ||||
|    */ | ||||
|   private $url; | ||||
|  | ||||
|   /** | ||||
|    * @var PayloadCommitVerification|null The GPG verification of this commit. | ||||
|    */ | ||||
|   private $verification; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new payload commit. | ||||
|    * @param string $id The commit hash. | ||||
|    * @param string $message The commit message. | ||||
|    */ | ||||
|   function __construct(string $id, string $message) { | ||||
|     $this->id = $id; | ||||
|     $this->setMessage($message); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new commit from the specified JSON map. | ||||
|    * @param object $map A JSON map representing a commit. | ||||
|    * @return static The instance corresponding to the specified JSON map. | ||||
|    */ | ||||
|   static function fromJson(object $map): self { | ||||
|     return new static([ | ||||
|       'author' => isset($map->author) && is_object($map->author) ? PayloadUser::fromJson($map->author) : null, | ||||
|       'committer' => isset($map->committer) && is_object($map->committer) ? PayloadUser::fromJson($map->committer) : null, | ||||
|       'id' => isset($map->id) && is_string($map->id) ? $map->id : '', | ||||
|       'message' => isset($map->message) && is_string($map->message) ? $map->message : '', | ||||
|       'timestamp' => isset($map->timestamp) && is_string($map->timestamp) ? $map->timestamp : null, | ||||
|       'url' => isset($map->url) && is_string($map->url) ? $map->url : null, | ||||
|       'verification' => isset($map->verification) && is_object($map->verification) ? PayloadCommitVerification::fromJson($map->verification) : null | ||||
|     ]); | ||||
|     return (new static(isset($map->id) && is_string($map->id) ? $map->id : '', isset($map->message) && is_string($map->message) ? $map->message : '')) | ||||
|       ->setAuthor(isset($map->author) && is_object($map->author) ? PayloadUser::fromJson($map->author) : null) | ||||
|       ->setCommitter(isset($map->committer) && is_object($map->committer) ? PayloadUser::fromJson($map->committer) : null) | ||||
|       ->setTimestamp(isset($map->timestamp) && is_string($map->timestamp) ? $map->timestamp : null) | ||||
|       ->setUrl(isset($map->url) && is_string($map->url) ? $map->url : null) | ||||
|       ->setVerification(isset($map->verification) && is_object($map->verification) ? PayloadCommitVerification::fromJson($map->verification) : null); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the person who authored the commit. | ||||
|    * @return PayloadUser|null The person who authored the commit. | ||||
|    */ | ||||
|   function getAuthor(): ?PayloadUser { | ||||
|     return $this->author; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the person who committed the code. | ||||
|    * @return PayloadUser|null The person who committed the code. | ||||
|    */ | ||||
|   function getCommitter(): ?PayloadUser { | ||||
|     return $this->committer; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the commit hash. | ||||
|    * @return string The commit hash. | ||||
|    */ | ||||
|   function getId(): string { | ||||
|     return $this->id; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the commit message. | ||||
|    * @return string The commit message. | ||||
|    */ | ||||
|   function getMessage(): string { | ||||
|     return $this->message; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @ -78,22 +117,60 @@ class PayloadCommit implements \JsonSerializable { | ||||
|     return $this->url; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the GPG verification of this commit. | ||||
|    * @return UriInterface|null The GPG verification of this commit. | ||||
|    */ | ||||
|   function getVerification(): ?PayloadCommitVerification { | ||||
|     return $this->verification; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) [ | ||||
|       'author', | ||||
|       'committer', | ||||
|       'id', | ||||
|       'message', | ||||
|       'author' => ($author = $this->getAuthor()) ? $author->jsonSerialize() : null, | ||||
|       'committer' => ($committer = $this->getCommitter()) ? $committer->jsonSerialize() : null, | ||||
|       'id' => $this->getId(), | ||||
|       'message' => $this->getMessage(), | ||||
|       'timestamp' => ($date = $this->getTimestamp()) ? $date->format('c') : null, | ||||
|       'url' => ($url = $this->getUrl()) ? (string) $url : null, | ||||
|       'verification' | ||||
|       'verification' => ($verification = $this->getVerification()) ? $verification->jsonSerialize() : null | ||||
|     ]; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the person who authored the commit. | ||||
|    * @param PayloadUser|null $value The new author. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setAuthor(?PayloadUser $value): self { | ||||
|     $this->author = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the person who committed the code. | ||||
|    * @param PayloadUser|null $value The new committer. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setCommitter(?PayloadUser $value): self { | ||||
|     $this->committer = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the commit message. | ||||
|    * @param string $value The new message. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setMessage(string $value): self { | ||||
|     $this->message = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the commit date. | ||||
|    * @param \DateTime|string|null $value The new commit date. | ||||
| @ -113,4 +190,14 @@ class PayloadCommit implements \JsonSerializable { | ||||
|     $this->url = is_string($value) ? new Uri($value) : $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the commit message. | ||||
|    * @param PayloadCommitVerification|null $value The new message. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setVerification(?PayloadCommitVerification $value): self { | ||||
|     $this->verification = $value; | ||||
|     return $this; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -10,22 +10,29 @@ class PayloadCommitVerification implements \JsonSerializable { | ||||
|   /** | ||||
|    * @var bool Value indicating whether the verification has succeeded. | ||||
|    */ | ||||
|   public $isVerified = false; | ||||
|   private $isVerified = false; | ||||
|  | ||||
|   /** | ||||
|    * @var string A custom message sent with the verification request. | ||||
|    */ | ||||
|   public $payload = ''; | ||||
|   private $payload = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var string A message providing details about the verification. | ||||
|    */ | ||||
|   public $reason = ''; | ||||
|   private $reason = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var string The signing key used for the verification. | ||||
|    */ | ||||
|   public $signature = ''; | ||||
|   private $signature = ''; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new verification of a payload commit. | ||||
|    */ | ||||
|   function __construct(bool $isVerified = false) { | ||||
|     // TODO $this->setVerified($isVerified); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new commit from the specified JSON map. | ||||
| @ -41,16 +48,48 @@ class PayloadCommitVerification implements \JsonSerializable { | ||||
|     ]); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the custom message sent with the verification request. | ||||
|    * @return string The custom message sent with the verification request. | ||||
|    */ | ||||
|   function getPayload(): string { | ||||
|     return $this->payload; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the message providing details about the verification. | ||||
|    * @return string The message providing details about the verification. | ||||
|    */ | ||||
|   function getReason(): string { | ||||
|     return $this->reason; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the signing key used for the verification. | ||||
|    * @return string The signing key used for the verification. | ||||
|    */ | ||||
|   function getSignature(): string { | ||||
|     return $this->signature; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * TODO | ||||
|    * @return bool | ||||
|    */ | ||||
|   function isVerified(): bool { | ||||
|     return $this->isVerified; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) [ | ||||
|       'payload', | ||||
|       'reason', | ||||
|       'signature', | ||||
|       'verified' => 'isVerified' | ||||
|       'payload' => $this->getPayload(), | ||||
|       'reason' => $this->getReason(), | ||||
|       'signature' => $this->getSignature(), | ||||
|       'verified' => $this->isVerified() | ||||
|     ]; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -5,22 +5,22 @@ namespace Gitea\Models; | ||||
| /** | ||||
|  * Represents the author or committer of a commit. | ||||
|  */ | ||||
| class PayloadUser { | ||||
| class PayloadUser implements \JsonSerializable { | ||||
|  | ||||
|   /** | ||||
|    * @var string The mail address. | ||||
|    */ | ||||
|   public $email = ''; | ||||
|   private $email = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var string The full name. | ||||
|    */ | ||||
|   public $name = ''; | ||||
|   private $name = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var string The name of the Gitea account. | ||||
|    */ | ||||
|   public $username = ''; | ||||
|   private $username = ''; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new user from the specified JSON map. | ||||
| @ -34,4 +34,21 @@ class PayloadUser { | ||||
|       'username' => isset($map->username) && is_string($map->username) ? $map->username : '' | ||||
|     ]); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) [ | ||||
|       'after' => $this->getAfter(), | ||||
|       'before' => $this->getBefore(), | ||||
|       'compare_url' => ($url = $this->getCompareUrl()) ? (string) $url : null, | ||||
|       'commits' => array_map(function(PayloadCommit $commit) { return $commit->jsonSerialize(); }, $this->getCommits()->getArrayCopy()), | ||||
|       'pusher', | ||||
|       'ref' => $this->getRef(), | ||||
|       'repository', | ||||
|       'sender' | ||||
|     ]; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -5,22 +5,32 @@ namespace Gitea\Models; | ||||
| /** | ||||
|  * Represents a set of permissions. | ||||
|  */ | ||||
| class Permission { | ||||
| class Permission implements \JsonSerializable { | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether administrator access is allowed. | ||||
|    */ | ||||
|   public $admin = false; | ||||
|   private $admin; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether pull is allowed. | ||||
|    */ | ||||
|   public $pull = false; | ||||
|   private $pull; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether push is allowed. | ||||
|    */ | ||||
|   public $push = false; | ||||
|   private $push; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new permission. | ||||
|    * @param bool $admin Value indicating whether administrator access is allowed. | ||||
|    * @param bool $pull Value indicating whether pull is allowed. | ||||
|    * @param bool $push Value indicating whether push is allowed. | ||||
|    */ | ||||
|   function __construct(bool $admin = false, bool $pull = false, bool $push = false) { | ||||
|     $this->setAdmin($admin)->setPull($pull)->setPush($push); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new user from the specified JSON map. | ||||
| @ -28,10 +38,76 @@ class Permission { | ||||
|    * @return static The instance corresponding to the specified JSON map. | ||||
|    */ | ||||
|   static function fromJson(object $map): self { | ||||
|     return new static([ | ||||
|       'admin' => isset($map->admin) && is_bool($map->admin) ? $map->admin : false, | ||||
|       'pull' => isset($map->pull) && is_bool($map->pull) ? $map->pull : false, | ||||
|       'push' => isset($map->push) && is_bool($map->push) ? $map->push : false | ||||
|     ]); | ||||
|     return new static( | ||||
|       isset($map->admin) && is_bool($map->admin) ? $map->admin : false, | ||||
|       isset($map->pull) && is_bool($map->pull) ? $map->pull : false, | ||||
|       isset($map->push) && is_bool($map->push) ? $map->push : false | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets a value indicating whether administrator access is allowed. | ||||
|    * @return bool `true` if administrator access is allowed, otherwise `false`. | ||||
|    */ | ||||
|   function getAdmin(): bool { | ||||
|     return $this->admin; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets a value indicating whether pull is allowed. | ||||
|    * @return bool `true` if pull is allowed, otherwise `false`. | ||||
|    */ | ||||
|   function getPull(): bool { | ||||
|     return $this->pull; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets a value indicating whether push is allowed. | ||||
|    * @return bool `true` if push is allowed, otherwise `false`. | ||||
|    */ | ||||
|   function getPush(): bool { | ||||
|     return $this->push; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) [ | ||||
|       'admin' => $this->getAdmin(), | ||||
|       'pull' => $this->getPull(), | ||||
|       'push' => $this->getPush() | ||||
|     ]; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets a value indicating whether administrator access is allowed. | ||||
|    * @param bool $value `true` to allow administrator access, otherwise `false`. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setAdmin(bool $value): self { | ||||
|     $this->admin = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets a value indicating whether pull is allowed. | ||||
|    * @param bool $value `true` to allow pull, otherwise `false`. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setPull(bool $value): self { | ||||
|     $this->pull = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets a value indicating whether push is allowed. | ||||
|    * @param bool $value `true` to allow push, otherwise `false`. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setPush(bool $value): self { | ||||
|     $this->push = $value; | ||||
|     return $this; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -13,87 +13,87 @@ class Repository implements \JsonSerializable { | ||||
|   /** | ||||
|    * @var string The name of the default branch. | ||||
|    */ | ||||
|   public $defaultBranch = ''; | ||||
|   private $defaultBranch = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var string The repository description. | ||||
|    */ | ||||
|   public $description = ''; | ||||
|   private $description = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var int The number of forks of this repository. | ||||
|    */ | ||||
|   public $forksCount = 0; | ||||
|   private $forksCount = 0; | ||||
|  | ||||
|   /** | ||||
|    * @var string The full name. | ||||
|    */ | ||||
|   public $fullName = ''; | ||||
|   private $fullName = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var int The repository identifier. | ||||
|    */ | ||||
|   public $id = -1; | ||||
|   private $id = -1; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether this repository is empty. | ||||
|    */ | ||||
|   public $isEmpty = false; | ||||
|   private $isEmpty = false; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether this repository is a fork. | ||||
|    */ | ||||
|   public $isFork = false; | ||||
|   private $isFork = false; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether this repository is a mirror. | ||||
|    */ | ||||
|   public $isMirror = false; | ||||
|   private $isMirror = false; | ||||
|  | ||||
|   /** | ||||
|    * @var bool Value indicating whether this repository is private. | ||||
|    */ | ||||
|   public $isPrivate = false; | ||||
|   private $isPrivate = false; | ||||
|  | ||||
|   /** | ||||
|    * @var string The repository name. | ||||
|    */ | ||||
|   public $name = ''; | ||||
|   private $name = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var int The number of open issues of this repository. | ||||
|    */ | ||||
|   public $openIssuesCount = 0; | ||||
|   private $openIssuesCount = 0; | ||||
|  | ||||
|   /** | ||||
|    * @var User|null The repository owner. | ||||
|    */ | ||||
|   public $owner; | ||||
|   private $owner; | ||||
|  | ||||
|   /** | ||||
|    * @var Repository|null The parent repository, if this repository is a fork or a mirror. | ||||
|    */ | ||||
|   public $parent; | ||||
|   private $parent; | ||||
|  | ||||
|   /** | ||||
|    * @var Permission|null The repository permissions. | ||||
|    */ | ||||
|   public $permissions; | ||||
|   private $permissions; | ||||
|  | ||||
|   /** | ||||
|    * @var int The repository size, in kilobytes. | ||||
|    */ | ||||
|   public $size = 0; | ||||
|   private $size = 0; | ||||
|  | ||||
|   /** | ||||
|    * @var int The number of stars of this repository. | ||||
|    */ | ||||
|   public $starsCount = 0; | ||||
|   private $starsCount = 0; | ||||
|  | ||||
|   /** | ||||
|    * @var int The number of watchers of this repository. | ||||
|    */ | ||||
|   public $watchersCount = 0; | ||||
|   private $watchersCount = 0; | ||||
|  | ||||
|   /** | ||||
|    * @var UriInterface|null The HTTP-based URL for cloning this repository. | ||||
|  | ||||
| @ -5,12 +5,20 @@ namespace Gitea\Models; | ||||
| /** | ||||
|  * Warps the version of the Gitea server. | ||||
|  */ | ||||
| class ServerVersion { | ||||
| class ServerVersion implements \JsonSerializable { | ||||
|  | ||||
|   /** | ||||
|    * @var string The version number. | ||||
|    */ | ||||
|   public $version = ''; | ||||
|   private $version; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new server version. | ||||
|    * @param string $version The version number. | ||||
|    */ | ||||
|   function __construct(string $version) { | ||||
|     $this->version = $version; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new server version from the specified JSON map. | ||||
| @ -18,8 +26,22 @@ class ServerVersion { | ||||
|    * @return static The instance corresponding to the specified JSON map. | ||||
|    */ | ||||
|   static function fromJson(object $map): self { | ||||
|     return new static([ | ||||
|       'version' => isset($map->version) && is_string($map->version) ? $map->version : '' | ||||
|     ]); | ||||
|     return new static(isset($map->version) && is_string($map->version) ? $map->version : ''); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the version number. | ||||
|    * @return string The version number. | ||||
|    */ | ||||
|   function getVersion(): string { | ||||
|     return $this->version; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) ['version' => $this->getVersion()]; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -5,27 +5,37 @@ namespace Gitea\Models; | ||||
| /** | ||||
|  * Represents a team in an organization. | ||||
|  */ | ||||
| class Team { | ||||
| class Team implements \JsonSerializable { | ||||
|  | ||||
|   /** | ||||
|    * @var string The team description. | ||||
|    */ | ||||
|   public $description = ''; | ||||
|   private $description = ''; | ||||
|  | ||||
|   /** | ||||
|    * @var int The team identifier. | ||||
|    */ | ||||
|   public $id = -1; | ||||
|   private $id; | ||||
|  | ||||
|   /** | ||||
|    * @var string The team name. | ||||
|    */ | ||||
|   public $name = ''; | ||||
|   private $name; | ||||
|  | ||||
|   /** | ||||
|    * @var string The team permission. | ||||
|    */ | ||||
|   public $permission = TeamPermission::NONE; | ||||
|   private $permission = TeamPermission::NONE; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new team. | ||||
|    * @param int $id The team identifier. | ||||
|    * @param string $name The team name. | ||||
|    */ | ||||
|   function __construct(int $id, string $name = '') { | ||||
|     $this->id = $id; | ||||
|     $this->setName($name); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new user from the specified JSON map. | ||||
| @ -33,11 +43,83 @@ class Team { | ||||
|    * @return static The instance corresponding to the specified JSON map. | ||||
|    */ | ||||
|   static function fromJson(object $map): self { | ||||
|     return new static([ | ||||
|       'description' => isset($map->description) && is_string($map->description) ? $map->description : '', | ||||
|       'id' => isset($map->id) && is_int($map->id) ? $map->id : -1, | ||||
|       'name' => isset($map->name) && is_string($map->name) ? $map->name : '', | ||||
|       'permission' => isset($map->permission) && TeamPermission::isDefined($map->permission) ? $map->permission : TeamPermission::NONE | ||||
|     ]); | ||||
|     return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->name) && is_string($map->name) ? $map->name : '')) | ||||
|       ->setDescription(isset($map->description) && is_string($map->description) ? $map->description : '') | ||||
|       ->setPermission(isset($map->permission) && is_string($map->permission) ? $map->permission : TeamPermission::NONE); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the team description. | ||||
|    * @return string The team description. | ||||
|    */ | ||||
|   function getDescription(): string { | ||||
|     return $this->description; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the team identifier. | ||||
|    * @return int The team identifier. | ||||
|    */ | ||||
|   function getId(): int { | ||||
|     return $this->id; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the team name. | ||||
|    * @return string The team name. | ||||
|    */ | ||||
|   function getName(): string { | ||||
|     return $this->name; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Gets the team permission. | ||||
|    * @return string The team permission. | ||||
|    */ | ||||
|   function getPermission(): string { | ||||
|     return $this->permission; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Converts this object to a map in JSON format. | ||||
|    * @return \stdClass The map in JSON format corresponding to this object. | ||||
|    */ | ||||
|   function jsonSerialize(): \stdClass { | ||||
|     return (object) [ | ||||
|       'description' => $this->getDescription(), | ||||
|       'id' => $this->getId(), | ||||
|       'name' => $this->getName(), | ||||
|       'permission' => $this->getPermission() | ||||
|     ]; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the team description. | ||||
|    * @param string $value The new description. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setDescription(string $value): self { | ||||
|     $this->description = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the team name. | ||||
|    * @param string $value The new name. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setName(string $value): self { | ||||
|     $this->name = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the team permission. | ||||
|    * @param string $value The new permission. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setPermission(string $value): self { | ||||
|     $this->permission = TeamPermission::isDefined($value) ? $value : TeamPermission::NONE; | ||||
|     return $this; | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -28,7 +28,7 @@ class User implements \JsonSerializable { | ||||
|   /** | ||||
|    * @var int The user identifier. | ||||
|    */ | ||||
|   private $id = -1; | ||||
|   private $id; | ||||
|  | ||||
|   /** | ||||
|    * @var string The user locale. | ||||
| @ -38,7 +38,17 @@ class User implements \JsonSerializable { | ||||
|   /** | ||||
|    * @var string The name of the Gitea account. | ||||
|    */ | ||||
|   private $login = ''; | ||||
|   private $login; | ||||
|  | ||||
|   /** | ||||
|    * Creates a new user. | ||||
|    * @param int $id The user identifier. | ||||
|    * @param string $login The name of the Gitea account. | ||||
|    */ | ||||
|   function __construct(int $id, string $login) { | ||||
|     $this->id = $id; | ||||
|     $this->setLogin($login); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Creates a new user from the specified JSON map. | ||||
| @ -46,14 +56,11 @@ class User implements \JsonSerializable { | ||||
|    * @return static The instance corresponding to the specified JSON map. | ||||
|    */ | ||||
|   static function fromJson(object $map): self { | ||||
|     return new static([ | ||||
|       'avatarUrl' => isset($map->avatar_url) && is_string($map->avatar_url) ? $map->avatar_url : null, | ||||
|       'email' => isset($map->email) && is_string($map->email) ? mb_strtolower($map->email) : '', | ||||
|       'fullName' => isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '', | ||||
|       'id' => isset($map->id) && is_int($map->id) ? $map->id : -1, | ||||
|       'language' => isset($map->language) && is_string($map->language) ? $map->language : '', | ||||
|       'login' => isset($map->login) && is_string($map->login) ? $map->login : '' | ||||
|     ]); | ||||
|     return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->login) && is_string($map->login) ? $map->login : '')) | ||||
|       ->setAvatarUrl(isset($map->avatar_url) && is_string($map->avatar_url) ? $map->avatar_url : null) | ||||
|       ->setEmail(isset($map->email) && is_string($map->email) ? mb_strtolower($map->email) : '') | ||||
|       ->setFullName(isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '') | ||||
|       ->setLanguage(isset($map->language) && is_string($map->language) ? $map->language : ''); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| @ -149,16 +156,6 @@ class User implements \JsonSerializable { | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the user identifier. | ||||
|    * @param int $value The new user identifier. | ||||
|    * @return $this This instance. | ||||
|    */ | ||||
|   function setId(int $value): self { | ||||
|     $this->id = $value; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Sets the user locale. | ||||
|    * @param string $value The new user locale. | ||||
|  | ||||
		Reference in New Issue
	
	Block a user