diff --git a/src/Api/Organizations.php b/src/Api/Organizations.php index 5f2719f..5c18b27 100644 --- a/src/Api/Organizations.php +++ b/src/Api/Organizations.php @@ -5,7 +5,7 @@ namespace Gitea\Api; use GuzzleHttp\Psr7\Response; use Gitea\Client; -use Gitea\Models\Organization; +use Gitea\Model\Organization; use Gitea\Api\Abstracts\AbstractApi; diff --git a/src/Api/Repositories.php b/src/Api/Repositories.php index 5f4a07b..4274b4d 100644 --- a/src/Api/Repositories.php +++ b/src/Api/Repositories.php @@ -6,7 +6,7 @@ use GuzzleHttp\Exception\ServerException; use Gitea\Client; use Gitea\Collections\ApiItemCollection; -use Gitea\Models\Repository; +use Gitea\Model\Repository; use Gitea\Api\Abstracts\AbstractAllApi; diff --git a/src/Model/Organization.php b/src/Model/Organization.php index a7aaee7..2e558a8 100644 --- a/src/Model/Organization.php +++ b/src/Model/Organization.php @@ -1,6 +1,6 @@ setUserName($username); - $this->setVisibility($visibility); - } + /** + * Creates a new organization. + * @param string $username The organization name. + * @param string $visibility The organization visibility. + */ + function __construct(string $username, string $visibility = "private") { + $this->setUserName($username); + $this->setVisibility($visibility); + } - /** - * Creates a new organization from the specified JSON map. - * @param object $map A JSON map representing an organization. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return (new static(isset($map->username) && is_string($map->username) ? $map->username : '', isset($map->visibility) && is_string($map->visibility) ? $map->visibility : 'private')) - ->setAvatarURL(isset($map->avatar_url) && is_string($map->avatar_url) ? new Uri($map->avatar_url) : null) - ->setDescription(isset($map->description) && is_string($map->description) ? $map->description : '') - ->setFullName(isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '') - ->setLocation(isset($map->location) && is_string($map->location) ? $map->location : '') - ->setWebsite(isset($map->website) && is_string($map->website) ? new Uri($map->website) : null); - } + /** + * Creates a new organization from the specified JSON map. + * @param object $map A JSON map representing an organization. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + return (new static(isset($map->username) && is_string($map->username) ? $map->username : '', isset($map->visibility) && is_string($map->visibility) ? $map->visibility : 'private')) + ->setAvatarURL(isset($map->avatar_url) && is_string($map->avatar_url) ? new Uri($map->avatar_url) : null) + ->setDescription(isset($map->description) && is_string($map->description) ? $map->description : '') + ->setFullName(isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '') + ->setLocation(isset($map->location) && is_string($map->location) ? $map->location : '') + ->setWebsite(isset($map->website) && is_string($map->website) ? new Uri($map->website) : null); + } - /** - * 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) [ - 'avatar_url' => ($url = $this->getAvatarURL()) ? (string) $url : null, - 'description' => $this->getDescription(), - 'full_name' => $this->getFullName(), - 'id' => $this->getId(), - 'location' => $this->getLocation(), - 'username' => $this->getUsername(), - 'visibility' => $this->getVisibility(), - 'website' => ($url = $this->getWebsite()) ? (string) $url : null - ]; - } + /** + * 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) [ + 'avatar_url' => ($url = $this->getAvatarURL()) ? (string) $url : null, + 'description' => $this->getDescription(), + 'full_name' => $this->getFullName(), + 'id' => $this->getId(), + 'location' => $this->getLocation(), + 'username' => $this->getUsername(), + 'visibility' => $this->getVisibility(), + 'website' => ($url = $this->getWebsite()) ? (string) $url : null + ]; + } - /** - * Gets the organization identifier. - * @return int The organization identifier. - */ - function getId(): int { - return $this->id; - } + /** + * Gets the organization identifier. + * @return int The organization identifier. + */ + function getId(): int { + return $this->id; + } - public function getAvatarURL(): ?UriInterface { - return $this->avatarURL; - } + public function getAvatarURL(): ?UriInterface { + return $this->avatarURL; + } - public function setAvatarURL(?UriInterface $value): self { - $this->avatarURL = $value; - return $this; - } + public function setAvatarURL(?UriInterface $value): self { + $this->avatarURL = $value; + return $this; + } - public function getDescription() { - return $this->description; - } + public function getDescription() { + return $this->description; + } - public function setDescription(string $value): self { - $this->description = $value; - return $this; - } + public function setDescription(string $value): self { + $this->description = $value; + return $this; + } - public function getFullName() { - return $this->fullName; - } + public function getFullName() { + return $this->fullName; + } - public function setFullName(string $value): self { - $this->fullName = $value; - return $this; - } + public function setFullName(string $value): self { + $this->fullName = $value; + return $this; + } - public function getLocation() { - return $this->location; - } + public function getLocation() { + return $this->location; + } - public function setLocation(string $value): self { - $this->location = $value; - return $this; - } + public function setLocation(string $value): self { + $this->location = $value; + return $this; + } - public function getUsername() { - return $this->username; - } + public function getUsername() { + return $this->username; + } - public function setUsername(string $value): self { - $this->username = $value; - return $this; - } + public function setUsername(string $value): self { + $this->username = $value; + return $this; + } - public function getVisibility() { - return $this->visibility; - } + public function getVisibility() { + return $this->visibility; + } - public function setVisibility(string $value): self { - $this->visibility = $value; - return $this; - } + public function setVisibility(string $value): self { + $this->visibility = $value; + return $this; + } - public function getWebsite(): ?UriInterface { - return $this->website; - } + public function getWebsite(): ?UriInterface { + return $this->website; + } - public function setWebsite(?UriInterface $value): self { - $this->website = $value; - return $this; - } + public function setWebsite(?UriInterface $value): self { + $this->website = $value; + return $this; + } } diff --git a/src/Model/PayloadCommit.php b/src/Model/PayloadCommit.php index cb043a0..6b03f67 100644 --- a/src/Model/PayloadCommit.php +++ b/src/Model/PayloadCommit.php @@ -1,5 +1,5 @@ id = $id; - $this->setMessage($message); - } + /** + * 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(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) ? new \DateTime($map->timestamp) : null) - ->setUrl(isset($map->url) && is_string($map->url) ? new Uri($map->url) : null) - ->setVerification(isset($map->verification) && is_object($map->verification) ? PayloadCommitVerification::fromJson($map->verification) : null); - } + /** + * 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(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) ? new \DateTime($map->timestamp) : null) + ->setUrl(isset($map->url) && is_string($map->url) ? new Uri($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 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 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 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; - } + /** + * Gets the commit message. + * @return string The commit message. + */ + function getMessage(): string { + return $this->message; + } - /** - * Gets the commit date. - * @return \DateTime|null The commit date. - */ - function getTimestamp(): ?\DateTime { - return $this->timestamp; - } + /** + * Gets the commit date. + * @return \DateTime|null The commit date. + */ + function getTimestamp(): ?\DateTime { + return $this->timestamp; + } - /** - * Gets the URL to the commit's history. - * @return UriInterface|null The URL to the commit's history. - */ - function getUrl(): ?UriInterface { - return $this->url; - } + /** + * Gets the URL to the commit's history. + * @return UriInterface|null The URL to the commit's history. + */ + function getUrl(): ?UriInterface { + return $this->url; + } - /** - * Gets the GPG verification of this commit. - * @return PayloadCommitVerification|null The GPG verification of this commit. - */ - function getVerification(): ?PayloadCommitVerification { - return $this->verification; - } + /** + * Gets the GPG verification of this commit. + * @return PayloadCommitVerification|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' => ($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 = $this->getVerification()) ? $verification->jsonSerialize() : null - ]; - } + /** + * 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' => ($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 = $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 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 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 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|null $value The new commit date. - * @return $this This instance. - */ - function setTimestamp(?\DateTime $value): self { - $this->timestamp = $value; - return $this; - } + /** + * Sets the commit date. + * @param \DateTime|null $value The new commit date. + * @return $this This instance. + */ + function setTimestamp(?\DateTime $value): self { + $this->timestamp = $value; + return $this; + } - /** - * Sets the URL to the commit's history. - * @param UriInterface|null $value The new commit URL. - * @return $this This instance. - */ - function setUrl(?UriInterface $value): self { - $this->url = $value; - return $this; - } + /** + * Sets the URL to the commit's history. + * @param UriInterface|null $value The new commit URL. + * @return $this This instance. + */ + function setUrl(?UriInterface $value): self { + $this->url = $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; - } + /** + * 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; + } } diff --git a/src/Model/PayloadCommitVerification.php b/src/Model/PayloadCommitVerification.php index 8b463b3..a652d25 100644 --- a/src/Model/PayloadCommitVerification.php +++ b/src/Model/PayloadCommitVerification.php @@ -1,123 +1,123 @@ setVerified($isVerified); - } + /** + * Creates a new verification of a payload commit. + * @param bool $isVerified Value indicating whether the verification has succeeded. + */ + function __construct(bool $isVerified = false) { + $this->setVerified($isVerified); + } - /** - * 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(isset($map->verified) && is_bool($map->verified) ? $map->verified : false)) - ->setPayload(isset($map->payload) && is_string($map->payload) ? $map->payload : '') - ->setReason(isset($map->reason) && is_string($map->reason) ? $map->reason : '') - ->setSignature(isset($map->signature) && is_string($map->signature) ? $map->signature : ''); - } + /** + * 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(isset($map->verified) && is_bool($map->verified) ? $map->verified : false)) + ->setPayload(isset($map->payload) && is_string($map->payload) ? $map->payload : '') + ->setReason(isset($map->reason) && is_string($map->reason) ? $map->reason : '') + ->setSignature(isset($map->signature) && is_string($map->signature) ? $map->signature : ''); + } - /** - * 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 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 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; - } + /** + * Gets the signing key used for the verification. + * @return string The signing key used for the verification. + */ + function getSignature(): string { + return $this->signature; + } - /** - * Gets a value indicating whether the verification has succeeded. - * @return bool `true` if the verification has succeeded, otherwise `false`. - */ - function isVerified(): bool { - return $this->isVerified; - } + /** + * Gets a value indicating whether the verification has succeeded. + * @return bool `true` if the verification has succeeded, otherwise `false`. + */ + 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' => $this->getPayload(), - 'reason' => $this->getReason(), - 'signature' => $this->getSignature(), - 'verified' => $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' => $this->getPayload(), + 'reason' => $this->getReason(), + 'signature' => $this->getSignature(), + 'verified' => $this->isVerified() + ]; + } - /** - * Sets the custom message sent with the verification request. - * @param string $value A new custom message. - * @return $this This instance. - */ - function setPayload(string $value): self { - $this->payload = $value; - return $this; - } + /** + * Sets the custom message sent with the verification request. + * @param string $value A new custom message. + * @return $this This instance. + */ + function setPayload(string $value): self { + $this->payload = $value; + return $this; + } - /** - * Sets the message providing details about the verification. - * @param string $value A new message providing details about the verification. - * @return $this This instance. - */ - function setReason(string $value): self { - $this->reason = $value; - return $this; - } + /** + * Sets the message providing details about the verification. + * @param string $value A new message providing details about the verification. + * @return $this This instance. + */ + function setReason(string $value): self { + $this->reason = $value; + return $this; + } - /** - * Sets the signing key used for the verification. - * @param string $value The new signing key. - * @return $this This instance. - */ - function setSignature(string $value): self { - $this->signature = $value; - return $this; - } + /** + * Sets the signing key used for the verification. + * @param string $value The new signing key. + * @return $this This instance. + */ + function setSignature(string $value): self { + $this->signature = $value; + return $this; + } - /** - * Sets a value indicating whether the verification has succeeded. - * @param bool $value `true` if the verification has succeeded, otherwise `false`. - * @return $this This instance. - */ - function setVerified(bool $value): self { - $this->isVerified = $value; - return $this; - } + /** + * Sets a value indicating whether the verification has succeeded. + * @param bool $value `true` if the verification has succeeded, otherwise `false`. + * @return $this This instance. + */ + function setVerified(bool $value): self { + $this->isVerified = $value; + return $this; + } } diff --git a/src/Model/PayloadUser.php b/src/Model/PayloadUser.php index df293d8..01e8baa 100644 --- a/src/Model/PayloadUser.php +++ b/src/Model/PayloadUser.php @@ -1,90 +1,90 @@ username = $username; - } + /** + * Creates a new payload user. + * @param string $username The name of the Gitea account. + */ + function __construct(string $username) { + $this->username = $username; + } - /** - * Creates a new user from the specified JSON map. - * @param object $map A JSON map representing a user. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return (new static(isset($map->username) && is_string($map->username) ? $map->username : '')) - ->setEmail(isset($map->email) && is_string($map->email) ? mb_strtolower($map->email) : '') - ->setName(isset($map->name) && is_string($map->name) ? $map->name : ''); - } + /** + * Creates a new user from the specified JSON map. + * @param object $map A JSON map representing a user. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + return (new static(isset($map->username) && is_string($map->username) ? $map->username : '')) + ->setEmail(isset($map->email) && is_string($map->email) ? mb_strtolower($map->email) : '') + ->setName(isset($map->name) && is_string($map->name) ? $map->name : ''); + } - /** - * Gets the mail address. - * @return string The mail address. - */ - function getEmail(): string { - return $this->email; - } + /** + * Gets the mail address. + * @return string The mail address. + */ + function getEmail(): string { + return $this->email; + } - /** - * Gets the full name. - * @return string The full name. - */ - function getName(): string { - return $this->name; - } + /** + * Gets the full name. + * @return string The full name. + */ + function getName(): string { + return $this->name; + } - /** - * Gets the name of the Gitea account. - * @return string The name of the Gitea account. - */ - function getUsername(): string { - return $this->username; - } + /** + * Gets the name of the Gitea account. + * @return string The name of the Gitea account. + */ + function getUsername(): string { + return $this->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) [ - 'email' => $this->getEmail(), - 'name' => $this->getName(), - 'username' => $this->getUsername() - ]; - } + /** + * 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) [ + 'email' => $this->getEmail(), + 'name' => $this->getName(), + 'username' => $this->getUsername() + ]; + } - /** - * Sets the mail address. - * @param string $value The new mail address. - * @return $this This instance. - */ - function setEmail(string $value): self { - $this->email = $value; - return $this; - } + /** + * Sets the mail address. + * @param string $value The new mail address. + * @return $this This instance. + */ + function setEmail(string $value): self { + $this->email = $value; + return $this; + } - /** - * Sets the full name. - * @param string $value The new full name. - * @return $this This instance. - */ - function setName(string $value): self { - $this->name = $value; - return $this; - } + /** + * Sets the full name. + * @param string $value The new full name. + * @return $this This instance. + */ + function setName(string $value): self { + $this->name = $value; + return $this; + } } diff --git a/src/Model/Permission.php b/src/Model/Permission.php index 4be835c..a285ed1 100644 --- a/src/Model/Permission.php +++ b/src/Model/Permission.php @@ -1,104 +1,104 @@ setAdmin($admin)->setPull($pull)->setPush($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. - * @param object $map A JSON map representing a user. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - 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 - ); - } + /** + * Creates a new user from the specified JSON map. + * @param object $map A JSON map representing a user. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + 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 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 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; - } + /** + * 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() - ]; - } + /** + * 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 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 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; - } + /** + * 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; + } } diff --git a/src/Model/Repository.php b/src/Model/Repository.php index e6786bb..6129aab 100644 --- a/src/Model/Repository.php +++ b/src/Model/Repository.php @@ -1,5 +1,5 @@ id = $id; - $this->setFullName($fullName); - } - - /** - * Creates a new repository from the specified JSON map. - * @param object $map A JSON map representing a repository. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '')) - ->setCloneUrl(isset($map->clone_url) && is_string($map->clone_url) ? new Uri($map->clone_url) : null) - ->setCreatedAt(isset($map->created_at) && is_string($map->created_at) ? new \DateTime($map->created_at) : null) - ->setDefaultBranch(isset($map->default_branch) && is_string($map->default_branch) ? $map->default_branch : '') - ->setDescription(isset($map->description) && is_string($map->description) ? $map->description : '') - ->setEmpty(isset($map->empty) && is_bool($map->empty) ? $map->empty : true) - ->setFork(isset($map->fork) && is_bool($map->fork) ? $map->fork : false) - ->setForksCount(isset($map->forks_count) && is_int($map->forks_count) ? $map->forks_count : 0) - ->setHtmlUrl(isset($map->html_url) && is_string($map->html_url) ? new Uri($map->html_url) : null) - ->setMirror(isset($map->mirror) && is_bool($map->mirror) ? $map->mirror : false) - ->setName(isset($map->name) && is_string($map->name) ? $map->name : '') - ->setOpenIssuesCount(isset($map->open_issues_count) && is_int($map->open_issues_count) ? $map->open_issues_count : 0) - ->setOwner(isset($map->owner) && is_object($map->owner) ? User::fromJson($map->owner) : null) - ->setParent(isset($map->parent) && is_object($map->parent) ? Repository::fromJson($map->parent) : null) - ->setPermissions(isset($map->permissions) && is_object($map->permissions) ? Permission::fromJson($map->permissions) : null) - ->setPrivate(isset($map->private) && is_bool($map->private) ? $map->private : false) - ->setSize(isset($map->size) && is_int($map->size) ? $map->size : 0) - ->setSshUrl(isset($map->ssh_url) && is_string($map->ssh_url) ? new Uri($map->ssh_url) : null) - ->setStarsCount(isset($map->stars_count) && is_int($map->stars_count) ? $map->stars_count : 0) - ->setUpdatedAt(isset($map->updated_at) && is_string($map->updated_at) ? new \DateTime($map->updated_at) : null) - ->setWatchersCount(isset($map->watchers_count) && is_int($map->watchers_count) ? $map->watchers_count : 0) - ->setWebsite(isset($map->website) && is_string($map->website) ? new Uri($map->website) : null); - } - - /** - * Gets the HTTP-based URL for cloning this repository. - * @return UriInterface|null The HTTP-based URL for cloning this repository. - */ - function getCloneUrl(): ?UriInterface { - return $this->cloneUrl; - } - - /** - * Gets the date the repository was created. - * @return \DateTime|null The date the repository was created. - */ - function getCreatedAt(): ?\DateTime { - return $this->createdAt; - } - - /** - * Gets the name of the default branch. - * @return string The name of the default branch. - */ - function getDefaultBranch(): string { - return $this->defaultBranch; - } - - /** - * Gets the repository description. - * @return string The repository description. - */ - function getDescription(): string { - return $this->description; - } - - /** - * Gets the number of forks of this repository. - * @return int The number of forks of this repository. - */ - function getForksCount(): int { - return $this->forksCount; - } - - /** - * Gets the full name. - * @return string The full name. - */ - function getFullName(): string { - return $this->fullName; - } - - /** - * Gets the Gitea URL of this repository. - * @return UriInterface|null The Gitea URL of this repository. - */ - function getHtmlUrl(): ?UriInterface { - return $this->htmlUrl; - } - - /** - * Gets the repository identifier. - * @return int The repository identifier. - */ - function getId(): int { - return $this->id; - } - - /** - * Gets the repository name. - * @return string The repository name. - */ - function getName(): string { - if (mb_strlen($this->name)) return $this->name; - return mb_strlen($fullName = $this->getFullName()) ? explode('/', $fullName)[1] : ''; - } - - /** - * Gets the number of open issues of this repository. - * @return int The number of open issues of this repository. - */ - function getOpenIssuesCount(): int { - return $this->openIssuesCount; - } - - /** - * Gets the repository owner. - * @return User|null The repository owner. - */ - function getOwner(): ?User { - return $this->owner; - } - - /** - * Gets the parent repository, if this repository is a fork or a mirror. - * @return Repository|null The parent repository, if this repository is a fork or a mirror. - */ - function getParent(): ?Repository { - return $this->parent; - } - - /** - * Gets the repository permissions. - * @return Permission|null The repository permissions. - */ - function getPermissions(): ?Permission { - return $this->permissions; - } - - /** - * Gets the repository size, in kilobytes. - * @return int The repository size, in kilobytes. - */ - function getSize(): int { - return $this->size; - } - - /** - * Gets the SSH-based URL for cloning this repository. - * @return UriInterface|null The SSH-based URL for cloning this repository. - */ - function getSshUrl(): ?UriInterface { - return $this->sshUrl; - } - - /** - * Gets the number of stars of this repository. - * @return int The number of stars of this repository. - */ - function getStarsCount(): int { - return $this->starsCount; - } - - /** - * Gets the date the repository was updated. - * @return \DateTime|null The date the repository was updated. - */ - function getUpdatedAt(): ?\DateTime { - return $this->updatedAt; - } - - /** - * Gets the number of watchers of this repository. - * @return int The number of watchers of this repository. - */ - function getWatchersCount(): int { - return $this->watchersCount; - } - - /** - * Gets the URL of the repository website. - * @return UriInterface|null The URL of the repository website. - */ - function getWebsite(): ?UriInterface { - return $this->website; - } - - /** - * Gets a value indicating whether this repository is empty. - * @return bool `true` if this repository is empty, otherwise `false`. - */ - function isEmpty(): bool { - return $this->isEmpty; - } - - /** - * Gets a value indicating whether this repository is a fork. - * @return bool `true` if this repository is a fork, otherwise `false`. - */ - function isFork(): bool { - return $this->isFork; - } - - /** - * Gets a value indicating whether this repository is a mirror. - * @return bool `true` if this repository is a mirror, otherwise `false`. - */ - function isMirror(): bool { - return $this->isMirror; - } - - /** - * Gets a value indicating whether this repository is private. - * @return bool `true` if this repository is private, otherwise `false`. - */ - function isPrivate(): bool { - return $this->isPrivate; - } - - /** - * 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) [ - 'clone_url' => ($url = $this->getCloneUrl()) ? (string) $url : null, - 'created_at' => ($date = $this->getCreatedAt()) ? $date->format('c') : null, - 'default_branch' => $this->getDefaultBranch(), - 'description' => $this->getDescription(), - 'empty' => $this->isEmpty(), - 'fork' => $this->isFork(), - 'forks_count' => $this->getForksCount(), - 'full_name' => $this->getFullName(), - 'html_url' => ($url = $this->getHtmlUrl()) ? (string) $url : null, - 'id' => $this->getId(), - 'mirror' => $this->isMirror(), - 'name' => $this->getName(), - 'open_issues_count' => $this->getOpenIssuesCount(), - 'owner' => ($user = $this->getOwner()) ? $user->jsonSerialize() : null, - 'parent' => ($repository = $this->getParent()) ? $repository->jsonSerialize() : null, - 'permissions' => ($perms = $this->getPermissions()) ? $perms->jsonSerialize() : null, - 'private' => $this->isPrivate(), - 'size' => $this->getSize(), - 'ssh_url' => ($url = $this->getSshUrl()) ? (string) $url : null, - 'stars_count' => $this->getStarsCount(), - 'updated_at' => ($date = $this->getUpdatedAt()) ? $date->format('c') : null, - 'watchers_count' => $this->getWatchersCount(), - 'website' => ($url = $this->getWebsite()) ? (string) $url : null, - ]; - } - - /** - * Sets the HTTP-based URL for cloning this repository. - * @param UriInterface|null $value The new URL for cloning this repository. - * @return $this This instance. - */ - function setCloneUrl(?UriInterface $value): self { - $this->cloneUrl = $value; - return $this; - } - - /** - * Sets the date the repository was created. - * @param \DateTime|null $value The new date of creation. - * @return $this This instance. - */ - function setCreatedAt(?\DateTime $value): self { - $this->createdAt = $value; - return $this; - } - - /** - * Sets the name of the default branch. - * @param string $value The new default branch. - * @return $this This instance. - */ - function setDefaultBranch(string $value): self { - $this->defaultBranch = $value; - return $this; - } - - /** - * Sets the repository description. - * @param string $value The new repository description. - * @return $this This instance. - */ - function setDescription(string $value): self { - $this->description = $value; - return $this; - } - - /** - * Sets a value indicating whether this repository is empty. - * @param bool $value `true` if this repository is empty, otherwise `false`. - * @return $this This instance. - */ - function setEmpty(bool $value): self { - $this->isEmpty = $value; - return $this; - } - - /** - * Sets a value indicating whether this repository is a fork. - * @param bool $value `true` if this repository is a fork, otherwise `false`. - * @return $this This instance. - */ - function setFork(bool $value): self { - $this->isFork = $value; - return $this; - } - - /** - * Sets the number of forks of this repository. - * @param int $value The new number of forks. - * @return $this This instance. - */ - function setForksCount(int $value): self { - $this->forksCount = max(0, $value); - return $this; - } - - /** - * Sets the full name. - * @param string $value The new full name. - * @return $this This instance. - */ - function setFullName(string $value): self { - $this->fullName = $value; - return $this; - } - - /** - * Sets the Gitea URL of this repository. - * @param UriInterface|null $value The new Gitea URL. - * @return $this This instance. - */ - function setHtmlUrl(?UriInterface $value): self { - $this->htmlUrl = $value; - return $this; - } - - /** - * Sets a value indicating whether this repository is a mirror. - * @param bool $value `true` if this repository is a mirror, otherwise `false`. - * @return $this This instance. - */ - function setMirror(bool $value): self { - $this->isMirror = $value; - return $this; - } - - /** - * Sets the repository name. - * @param string $value The new repository name. - * @return $this This instance. - */ - function setName(string $value): self { - $this->name = $value; - return $this; - } - - /** - * Sets the number of open issues of this repository. - * @param int $value The new number of open issues. - * @return $this This instance. - */ - function setOpenIssuesCount(int $value): self { - $this->openIssuesCount = max(0, $value); - return $this; - } - - /** - * Sets the repository owner. - * @param User|null $value The new owner. - * @return $this This instance. - */ - function setOwner(?User $value): self { - $this->owner = $value; - return $this; - } - - /** - * Sets the parent repository, if this repository is a fork or a mirror. - * @param Repository|null $value The new parent repository. - * @return $this This instance. - */ - function setParent(?Repository $value): self { - $this->parent = $value; - return $this; - } - - /** - * Sets the repository permissions. - * @param Permission|null $value The new permissions. - * @return $this This instance. - */ - function setPermissions(?Permission $value): self { - $this->permissions = $value; - return $this; - } - - /** - * Sets a value indicating whether this repository is private. - * @param bool $value `true` if this repository is private, otherwise `false`. - * @return $this This instance. - */ - function setPrivate(bool $value): self { - $this->isPrivate = $value; - return $this; - } - - /** - * Sets the repository size, in kilobytes. - * @param int $value The new repository size, in kilobytes. - * @return $this This instance. - */ - function setSize(int $value): self { - $this->size = $value; - return $this; - } - - /** - * Sets the SSH-based URL for cloning this repository. - * @param UriInterface|null $value The new URL for cloning this repository. - * @return $this This instance. - */ - function setSshUrl(?UriInterface $value): self { - $this->sshUrl = $value; - return $this; - } - - /** - * Sets the number of stars of this repository. - * @param int $value The new number of stars. - * @return $this This instance. - */ - function setStarsCount(int $value): self { - $this->starsCount = max(0, $value); - return $this; - } - - /** - * Sets the date the repository was updated. - * @param \DateTime|null $value The new date of update. - * @return $this This instance. - */ - function setUpdatedAt(?\DateTime $value): self { - $this->updatedAt = $value; - return $this; - } - - /** - * Sets the number of watchers of this repository. - * @param int $value The new number of watchers. - * @return $this This instance. - */ - function setWatchersCount(int $value): self { - $this->watchersCount = max(0, $value); - return $this; - } - - /** - * Sets the URL of the repository website. - * @param UriInterface|null $value The new repository website. - * @return $this This instance. - */ - function setWebsite(?UriInterface $value): self { - $this->website = $value; - return $this; - } - - /** - * Undocumented function - * - * Call: - * $giteaClient->projects->fetchall - * - * @author Benjamin Blake (sitelease.ca) - * - * @param Type $var - * @return void - */ - public static function getAll(Type $var = null) - { - - } - - /** - * Undocumented function - * - * Example: - * ``` - * $giteaClient->repositories->fetchall(); - * ``` - * - * @author Benjamin Blake (sitelease.ca) - * - * @param Type $var - * @return void - */ - public function get(Type $var = null) - { - - } + /** @var UriInterface|null The HTTP-based URL for cloning this repository. */ + private $cloneUrl; + + /** @var \DateTime|null The date the repository was created. */ + private $createdAt; + + /** @var string The name of the default branch. */ + private $defaultBranch = ''; + + /** @var string The repository description. */ + private $description = ''; + + /** @var int The number of forks of this repository. */ + private $forksCount = 0; + + /** @var string The full name. */ + private $fullName; + + /** @var UriInterface|null The Gitea URL of this repository. */ + private $htmlUrl; + + /** @var int The repository identifier. */ + private $id; + + /** @var bool Value indicating whether this repository is empty. */ + private $isEmpty = true; + + /** @var bool Value indicating whether this repository is a fork. */ + private $isFork = false; + + /** @var bool Value indicating whether this repository is a mirror. */ + private $isMirror = false; + + /** @var bool Value indicating whether this repository is private. */ + private $isPrivate = false; + + /** @var string The repository name. */ + private $name = ''; + + /** @var int The number of open issues of this repository. */ + private $openIssuesCount = 0; + + /** @var User|null The repository owner. */ + private $owner; + + /** @var Repository|null The parent repository, if this repository is a fork or a mirror. */ + private $parent; + + /** @var Permission|null The repository permissions. */ + private $permissions; + + /** @var int The repository size, in kilobytes. */ + private $size = 0; + + /** @var UriInterface|null The SSH-based URL for cloning this repository. */ + private $sshUrl; + + /** @var int The number of stars of this repository. */ + private $starsCount = 0; + + /** @var \DateTime|null The date the repository was updated. */ + private $updatedAt; + + /** @var int The number of watchers of this repository. */ + private $watchersCount = 0; + + /** @var UriInterface|null The URL of the repository website. */ + private $website; + + /** + * Creates a new repository. + * @param int $id The repository identifier. + * @param string $fullName The full name of the repository. + */ + function __construct(int $id, string $fullName, object $giteaClient = null) { + $this->id = $id; + $this->setFullName($fullName); + } + + /** + * Creates a new repository from the specified JSON map. + * @param object $map A JSON map representing a repository. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->full_name) && is_string($map->full_name) ? $map->full_name : '')) + ->setCloneUrl(isset($map->clone_url) && is_string($map->clone_url) ? new Uri($map->clone_url) : null) + ->setCreatedAt(isset($map->created_at) && is_string($map->created_at) ? new \DateTime($map->created_at) : null) + ->setDefaultBranch(isset($map->default_branch) && is_string($map->default_branch) ? $map->default_branch : '') + ->setDescription(isset($map->description) && is_string($map->description) ? $map->description : '') + ->setEmpty(isset($map->empty) && is_bool($map->empty) ? $map->empty : true) + ->setFork(isset($map->fork) && is_bool($map->fork) ? $map->fork : false) + ->setForksCount(isset($map->forks_count) && is_int($map->forks_count) ? $map->forks_count : 0) + ->setHtmlUrl(isset($map->html_url) && is_string($map->html_url) ? new Uri($map->html_url) : null) + ->setMirror(isset($map->mirror) && is_bool($map->mirror) ? $map->mirror : false) + ->setName(isset($map->name) && is_string($map->name) ? $map->name : '') + ->setOpenIssuesCount(isset($map->open_issues_count) && is_int($map->open_issues_count) ? $map->open_issues_count : 0) + ->setOwner(isset($map->owner) && is_object($map->owner) ? User::fromJson($map->owner) : null) + ->setParent(isset($map->parent) && is_object($map->parent) ? Repository::fromJson($map->parent) : null) + ->setPermissions(isset($map->permissions) && is_object($map->permissions) ? Permission::fromJson($map->permissions) : null) + ->setPrivate(isset($map->private) && is_bool($map->private) ? $map->private : false) + ->setSize(isset($map->size) && is_int($map->size) ? $map->size : 0) + ->setSshUrl(isset($map->ssh_url) && is_string($map->ssh_url) ? new Uri($map->ssh_url) : null) + ->setStarsCount(isset($map->stars_count) && is_int($map->stars_count) ? $map->stars_count : 0) + ->setUpdatedAt(isset($map->updated_at) && is_string($map->updated_at) ? new \DateTime($map->updated_at) : null) + ->setWatchersCount(isset($map->watchers_count) && is_int($map->watchers_count) ? $map->watchers_count : 0) + ->setWebsite(isset($map->website) && is_string($map->website) ? new Uri($map->website) : null); + } + + /** + * Gets the HTTP-based URL for cloning this repository. + * @return UriInterface|null The HTTP-based URL for cloning this repository. + */ + function getCloneUrl(): ?UriInterface { + return $this->cloneUrl; + } + + /** + * Gets the date the repository was created. + * @return \DateTime|null The date the repository was created. + */ + function getCreatedAt(): ?\DateTime { + return $this->createdAt; + } + + /** + * Gets the name of the default branch. + * @return string The name of the default branch. + */ + function getDefaultBranch(): string { + return $this->defaultBranch; + } + + /** + * Gets the repository description. + * @return string The repository description. + */ + function getDescription(): string { + return $this->description; + } + + /** + * Gets the number of forks of this repository. + * @return int The number of forks of this repository. + */ + function getForksCount(): int { + return $this->forksCount; + } + + /** + * Gets the full name. + * @return string The full name. + */ + function getFullName(): string { + return $this->fullName; + } + + /** + * Gets the Gitea URL of this repository. + * @return UriInterface|null The Gitea URL of this repository. + */ + function getHtmlUrl(): ?UriInterface { + return $this->htmlUrl; + } + + /** + * Gets the repository identifier. + * @return int The repository identifier. + */ + function getId(): int { + return $this->id; + } + + /** + * Gets the repository name. + * @return string The repository name. + */ + function getName(): string { + if (mb_strlen($this->name)) return $this->name; + return mb_strlen($fullName = $this->getFullName()) ? explode('/', $fullName)[1] : ''; + } + + /** + * Gets the number of open issues of this repository. + * @return int The number of open issues of this repository. + */ + function getOpenIssuesCount(): int { + return $this->openIssuesCount; + } + + /** + * Gets the repository owner. + * @return User|null The repository owner. + */ + function getOwner(): ?User { + return $this->owner; + } + + /** + * Gets the parent repository, if this repository is a fork or a mirror. + * @return Repository|null The parent repository, if this repository is a fork or a mirror. + */ + function getParent(): ?Repository { + return $this->parent; + } + + /** + * Gets the repository permissions. + * @return Permission|null The repository permissions. + */ + function getPermissions(): ?Permission { + return $this->permissions; + } + + /** + * Gets the repository size, in kilobytes. + * @return int The repository size, in kilobytes. + */ + function getSize(): int { + return $this->size; + } + + /** + * Gets the SSH-based URL for cloning this repository. + * @return UriInterface|null The SSH-based URL for cloning this repository. + */ + function getSshUrl(): ?UriInterface { + return $this->sshUrl; + } + + /** + * Gets the number of stars of this repository. + * @return int The number of stars of this repository. + */ + function getStarsCount(): int { + return $this->starsCount; + } + + /** + * Gets the date the repository was updated. + * @return \DateTime|null The date the repository was updated. + */ + function getUpdatedAt(): ?\DateTime { + return $this->updatedAt; + } + + /** + * Gets the number of watchers of this repository. + * @return int The number of watchers of this repository. + */ + function getWatchersCount(): int { + return $this->watchersCount; + } + + /** + * Gets the URL of the repository website. + * @return UriInterface|null The URL of the repository website. + */ + function getWebsite(): ?UriInterface { + return $this->website; + } + + /** + * Gets a value indicating whether this repository is empty. + * @return bool `true` if this repository is empty, otherwise `false`. + */ + function isEmpty(): bool { + return $this->isEmpty; + } + + /** + * Gets a value indicating whether this repository is a fork. + * @return bool `true` if this repository is a fork, otherwise `false`. + */ + function isFork(): bool { + return $this->isFork; + } + + /** + * Gets a value indicating whether this repository is a mirror. + * @return bool `true` if this repository is a mirror, otherwise `false`. + */ + function isMirror(): bool { + return $this->isMirror; + } + + /** + * Gets a value indicating whether this repository is private. + * @return bool `true` if this repository is private, otherwise `false`. + */ + function isPrivate(): bool { + return $this->isPrivate; + } + + /** + * 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) [ + 'clone_url' => ($url = $this->getCloneUrl()) ? (string) $url : null, + 'created_at' => ($date = $this->getCreatedAt()) ? $date->format('c') : null, + 'default_branch' => $this->getDefaultBranch(), + 'description' => $this->getDescription(), + 'empty' => $this->isEmpty(), + 'fork' => $this->isFork(), + 'forks_count' => $this->getForksCount(), + 'full_name' => $this->getFullName(), + 'html_url' => ($url = $this->getHtmlUrl()) ? (string) $url : null, + 'id' => $this->getId(), + 'mirror' => $this->isMirror(), + 'name' => $this->getName(), + 'open_issues_count' => $this->getOpenIssuesCount(), + 'owner' => ($user = $this->getOwner()) ? $user->jsonSerialize() : null, + 'parent' => ($repository = $this->getParent()) ? $repository->jsonSerialize() : null, + 'permissions' => ($perms = $this->getPermissions()) ? $perms->jsonSerialize() : null, + 'private' => $this->isPrivate(), + 'size' => $this->getSize(), + 'ssh_url' => ($url = $this->getSshUrl()) ? (string) $url : null, + 'stars_count' => $this->getStarsCount(), + 'updated_at' => ($date = $this->getUpdatedAt()) ? $date->format('c') : null, + 'watchers_count' => $this->getWatchersCount(), + 'website' => ($url = $this->getWebsite()) ? (string) $url : null, + ]; + } + + /** + * Sets the HTTP-based URL for cloning this repository. + * @param UriInterface|null $value The new URL for cloning this repository. + * @return $this This instance. + */ + function setCloneUrl(?UriInterface $value): self { + $this->cloneUrl = $value; + return $this; + } + + /** + * Sets the date the repository was created. + * @param \DateTime|null $value The new date of creation. + * @return $this This instance. + */ + function setCreatedAt(?\DateTime $value): self { + $this->createdAt = $value; + return $this; + } + + /** + * Sets the name of the default branch. + * @param string $value The new default branch. + * @return $this This instance. + */ + function setDefaultBranch(string $value): self { + $this->defaultBranch = $value; + return $this; + } + + /** + * Sets the repository description. + * @param string $value The new repository description. + * @return $this This instance. + */ + function setDescription(string $value): self { + $this->description = $value; + return $this; + } + + /** + * Sets a value indicating whether this repository is empty. + * @param bool $value `true` if this repository is empty, otherwise `false`. + * @return $this This instance. + */ + function setEmpty(bool $value): self { + $this->isEmpty = $value; + return $this; + } + + /** + * Sets a value indicating whether this repository is a fork. + * @param bool $value `true` if this repository is a fork, otherwise `false`. + * @return $this This instance. + */ + function setFork(bool $value): self { + $this->isFork = $value; + return $this; + } + + /** + * Sets the number of forks of this repository. + * @param int $value The new number of forks. + * @return $this This instance. + */ + function setForksCount(int $value): self { + $this->forksCount = max(0, $value); + return $this; + } + + /** + * Sets the full name. + * @param string $value The new full name. + * @return $this This instance. + */ + function setFullName(string $value): self { + $this->fullName = $value; + return $this; + } + + /** + * Sets the Gitea URL of this repository. + * @param UriInterface|null $value The new Gitea URL. + * @return $this This instance. + */ + function setHtmlUrl(?UriInterface $value): self { + $this->htmlUrl = $value; + return $this; + } + + /** + * Sets a value indicating whether this repository is a mirror. + * @param bool $value `true` if this repository is a mirror, otherwise `false`. + * @return $this This instance. + */ + function setMirror(bool $value): self { + $this->isMirror = $value; + return $this; + } + + /** + * Sets the repository name. + * @param string $value The new repository name. + * @return $this This instance. + */ + function setName(string $value): self { + $this->name = $value; + return $this; + } + + /** + * Sets the number of open issues of this repository. + * @param int $value The new number of open issues. + * @return $this This instance. + */ + function setOpenIssuesCount(int $value): self { + $this->openIssuesCount = max(0, $value); + return $this; + } + + /** + * Sets the repository owner. + * @param User|null $value The new owner. + * @return $this This instance. + */ + function setOwner(?User $value): self { + $this->owner = $value; + return $this; + } + + /** + * Sets the parent repository, if this repository is a fork or a mirror. + * @param Repository|null $value The new parent repository. + * @return $this This instance. + */ + function setParent(?Repository $value): self { + $this->parent = $value; + return $this; + } + + /** + * Sets the repository permissions. + * @param Permission|null $value The new permissions. + * @return $this This instance. + */ + function setPermissions(?Permission $value): self { + $this->permissions = $value; + return $this; + } + + /** + * Sets a value indicating whether this repository is private. + * @param bool $value `true` if this repository is private, otherwise `false`. + * @return $this This instance. + */ + function setPrivate(bool $value): self { + $this->isPrivate = $value; + return $this; + } + + /** + * Sets the repository size, in kilobytes. + * @param int $value The new repository size, in kilobytes. + * @return $this This instance. + */ + function setSize(int $value): self { + $this->size = $value; + return $this; + } + + /** + * Sets the SSH-based URL for cloning this repository. + * @param UriInterface|null $value The new URL for cloning this repository. + * @return $this This instance. + */ + function setSshUrl(?UriInterface $value): self { + $this->sshUrl = $value; + return $this; + } + + /** + * Sets the number of stars of this repository. + * @param int $value The new number of stars. + * @return $this This instance. + */ + function setStarsCount(int $value): self { + $this->starsCount = max(0, $value); + return $this; + } + + /** + * Sets the date the repository was updated. + * @param \DateTime|null $value The new date of update. + * @return $this This instance. + */ + function setUpdatedAt(?\DateTime $value): self { + $this->updatedAt = $value; + return $this; + } + + /** + * Sets the number of watchers of this repository. + * @param int $value The new number of watchers. + * @return $this This instance. + */ + function setWatchersCount(int $value): self { + $this->watchersCount = max(0, $value); + return $this; + } + + /** + * Sets the URL of the repository website. + * @param UriInterface|null $value The new repository website. + * @return $this This instance. + */ + function setWebsite(?UriInterface $value): self { + $this->website = $value; + return $this; + } + } diff --git a/src/Model/ServerVersion.php b/src/Model/ServerVersion.php index b3aab9b..e9136d3 100644 --- a/src/Model/ServerVersion.php +++ b/src/Model/ServerVersion.php @@ -1,42 +1,42 @@ version = $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. - * @param object $map A JSON map representing a server version. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return new static(isset($map->version) && is_string($map->version) ? $map->version : ''); - } + /** + * Creates a new server version from the specified JSON map. + * @param object $map A JSON map representing a server version. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + 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; - } + /** + * 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()]; - } + /** + * 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()]; + } } diff --git a/src/Model/StatusState.php b/src/Model/StatusState.php index 7a380fe..9f39058 100644 --- a/src/Model/StatusState.php +++ b/src/Model/StatusState.php @@ -1,24 +1,24 @@ id = $id; - $this->setName($name); - } + /** + * 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. - * @param object $map A JSON map representing a user. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - 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); - } + /** + * Creates a new user from the specified JSON map. + * @param object $map A JSON map representing a user. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + 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 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 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 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; - } + /** + * 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() - ]; - } + /** + * 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 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 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::coerce($value, TeamPermission::none); - return $this; - } + /** + * Sets the team permission. + * @param string $value The new permission. + * @return $this This instance. + */ + function setPermission(string $value): self { + $this->permission = TeamPermission::coerce($value, TeamPermission::none); + return $this; + } } diff --git a/src/Model/TeamPermission.php b/src/Model/TeamPermission.php index 504e765..7de316f 100644 --- a/src/Model/TeamPermission.php +++ b/src/Model/TeamPermission.php @@ -1,24 +1,24 @@ id = $id; - $this->setTime($time); - } + /** + * Creates a new entry. + * @param int $id The entry identifier. + * @param int $time The elapsed time, in seconds. + */ + function __construct(int $id, int $time) { + $this->id = $id; + $this->setTime($time); + } - /** - * Creates a new entry from the specified JSON map. - * @param object $map A JSON map representing an entry. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->time) && is_int($map->time) ? $map->time : 0)) - ->setCreatedAt(isset($map->created) && is_string($map->created) ? new \DateTime($map->created) : null) - ->setIssueId(isset($map->issue_id) && is_int($map->issue_id) ? $map->issue_id : -1) - ->setUserId(isset($map->user_id) && is_int($map->user_id) ? $map->user_id : -1); - } + /** + * Creates a new entry from the specified JSON map. + * @param object $map A JSON map representing an entry. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + return (new static(isset($map->id) && is_int($map->id) ? $map->id : -1, isset($map->time) && is_int($map->time) ? $map->time : 0)) + ->setCreatedAt(isset($map->created) && is_string($map->created) ? new \DateTime($map->created) : null) + ->setIssueId(isset($map->issue_id) && is_int($map->issue_id) ? $map->issue_id : -1) + ->setUserId(isset($map->user_id) && is_int($map->user_id) ? $map->user_id : -1); + } - /** - * Gets the date the entry was created. - * @return \DateTime|null The date the entry was created. - */ - function getCreatedAt(): ?\DateTime { - return $this->createdAt; - } + /** + * Gets the date the entry was created. + * @return \DateTime|null The date the entry was created. + */ + function getCreatedAt(): ?\DateTime { + return $this->createdAt; + } - /** - * Gets the entry identifier. - * @return int The entry identifier. - */ - function getId(): int { - return $this->id; - } + /** + * Gets the entry identifier. + * @return int The entry identifier. + */ + function getId(): int { + return $this->id; + } - /** - * Gets the identifier of the associated issue or pull request. - * @return int The identifier of the associated issue or pull request. - */ - function getIssueId(): int { - return $this->issueId; - } + /** + * Gets the identifier of the associated issue or pull request. + * @return int The identifier of the associated issue or pull request. + */ + function getIssueId(): int { + return $this->issueId; + } - /** - * Gets the elapsed time, in seconds. - * @return int The elapsed time, in seconds. - */ - function getTime(): int { - return $this->time; - } + /** + * Gets the elapsed time, in seconds. + * @return int The elapsed time, in seconds. + */ + function getTime(): int { + return $this->time; + } - /** - * Gets the identifier of the initiating user. - * @return int The identifier of the initiating user. - */ - function getUserId(): int { - return $this->userId; - } + /** + * Gets the identifier of the initiating user. + * @return int The identifier of the initiating user. + */ + function getUserId(): int { + return $this->userId; + } - /** - * 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) [ - 'created' => ($date = $this->getCreatedAt()) ? $date->format('c') : null, - 'id' => $this->getId(), - 'issue_id' => $this->getIssueId(), - 'time' => $this->getTime(), - 'user_id' => $this->getUserId() - ]; - } + /** + * 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) [ + 'created' => ($date = $this->getCreatedAt()) ? $date->format('c') : null, + 'id' => $this->getId(), + 'issue_id' => $this->getIssueId(), + 'time' => $this->getTime(), + 'user_id' => $this->getUserId() + ]; + } - /** - * Sets the date the entry was created. - * @param \DateTime|null $value The new date of creation. - * @return $this This instance. - */ - function setCreatedAt(?\DateTime $value): self { - $this->createdAt = $value; - return $this; - } + /** + * Sets the date the entry was created. + * @param \DateTime|null $value The new date of creation. + * @return $this This instance. + */ + function setCreatedAt(?\DateTime $value): self { + $this->createdAt = $value; + return $this; + } - /** - * Sets the identifier of the associated issue or pull request. - * @param int $value The new issue identifier. - * @return $this This instance. - */ - function setIssueId(int $value): self { - $this->issueId = $value; - return $this; - } + /** + * Sets the identifier of the associated issue or pull request. + * @param int $value The new issue identifier. + * @return $this This instance. + */ + function setIssueId(int $value): self { + $this->issueId = $value; + return $this; + } - /** - * Sets the elapsed time, in seconds. - * @param int $value The new elapsed time, in seconds. - * @return $this This instance. - */ - function setTime(int $value): self { - $this->time = $value; - return $this; - } + /** + * Sets the elapsed time, in seconds. + * @param int $value The new elapsed time, in seconds. + * @return $this This instance. + */ + function setTime(int $value): self { + $this->time = $value; + return $this; + } - /** - * Sets the identifier of the initiating user. - * @param int $value The new user identifier. - * @return $this This instance. - */ - function setUserId(int $value): self { - $this->userId = $value; - return $this; - } + /** + * Sets the identifier of the initiating user. + * @param int $value The new user identifier. + * @return $this This instance. + */ + function setUserId(int $value): self { + $this->userId = $value; + return $this; + } } diff --git a/src/Model/User.php b/src/Model/User.php index cc465fc..d5d37bf 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1,5 +1,5 @@ id = $id; - $this->setLogin($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. - * @param object $map A JSON map representing a user. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - 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) ? new Uri($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 : ''); - } + /** + * Creates a new user from the specified JSON map. + * @param object $map A JSON map representing a user. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + 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) ? new Uri($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 : ''); + } - /** - * Gets the URL of the avatar image. - * @return UriInterface|null The URL of the avatar image. - */ - function getAvatarUrl(): ?UriInterface { - return $this->avatarUrl; - } + /** + * Gets the URL of the avatar image. + * @return UriInterface|null The URL of the avatar image. + */ + function getAvatarUrl(): ?UriInterface { + return $this->avatarUrl; + } - /** - * Gets the mail address. - * @return string The mail address. - */ - function getEmail(): string { - return $this->email; - } + /** + * Gets the mail address. + * @return string The mail address. + */ + function getEmail(): string { + return $this->email; + } - /** - * Gets the full name. - * @return string The full name. - */ - function getFullName(): string { - return $this->fullName; - } + /** + * Gets the full name. + * @return string The full name. + */ + function getFullName(): string { + return $this->fullName; + } - /** - * Gets the user identifier. - * @return int The user identifier. - */ - function getId(): int { - return $this->id; - } + /** + * Gets the user identifier. + * @return int The user identifier. + */ + function getId(): int { + return $this->id; + } - /** - * Gets the user locale. - * @return string The user locale. - */ - function getLanguage(): string { - return $this->language; - } + /** + * Gets the user locale. + * @return string The user locale. + */ + function getLanguage(): string { + return $this->language; + } - /** - * Gets the name of the Gitea account. - * @return string The name of the Gitea account. - */ - function getLogin(): string { - return $this->login; - } + /** + * Gets the name of the Gitea account. + * @return string The name of the Gitea account. + */ + function getLogin(): string { + return $this->login; + } - /** - * 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) [ - 'avatar_url' => ($url = $this->getAvatarUrl()) ? (string) $url : null, - 'email' => $this->getEmail(), - 'full_name' => $this->getFullName(), - 'id' => $this->getId(), - 'language' => $this->getLanguage(), - 'login' => $this->getLogin() - ]; - } + /** + * 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) [ + 'avatar_url' => ($url = $this->getAvatarUrl()) ? (string) $url : null, + 'email' => $this->getEmail(), + 'full_name' => $this->getFullName(), + 'id' => $this->getId(), + 'language' => $this->getLanguage(), + 'login' => $this->getLogin() + ]; + } - /** - * Sets the URL of the avatar image. - * @param UriInterface|null $value The new avatar URL. - * @return $this This instance. - */ - function setAvatarUrl(?UriInterface $value): self { - $this->avatarUrl = $value; - return $this; - } + /** + * Sets the URL of the avatar image. + * @param UriInterface|null $value The new avatar URL. + * @return $this This instance. + */ + function setAvatarUrl(?UriInterface $value): self { + $this->avatarUrl = $value; + return $this; + } - /** - * Sets the mail address. - * @param string $value The new mail address. - * @return $this This instance. - */ - function setEmail(string $value): self { - $this->email = $value; - return $this; - } + /** + * Sets the mail address. + * @param string $value The new mail address. + * @return $this This instance. + */ + function setEmail(string $value): self { + $this->email = $value; + return $this; + } - /** - * Sets the full name. - * @param string $value The new full name. - * @return $this This instance. - */ - function setFullName(string $value): self { - $this->fullName = $value; - return $this; - } + /** + * Sets the full name. + * @param string $value The new full name. + * @return $this This instance. + */ + function setFullName(string $value): self { + $this->fullName = $value; + return $this; + } - /** - * Sets the user locale. - * @param string $value The new user locale. - * @return $this This instance. - */ - function setLanguage(string $value): self { - $this->language = $value; - return $this; - } + /** + * Sets the user locale. + * @param string $value The new user locale. + * @return $this This instance. + */ + function setLanguage(string $value): self { + $this->language = $value; + return $this; + } - /** - * Sets the name of the Gitea account. - * @param string $value The new Gitea account. - * @return $this This instance. - */ - function setLogin(string $value): self { - $this->login = $value; - return $this; - } + /** + * Sets the name of the Gitea account. + * @param string $value The new Gitea account. + * @return $this This instance. + */ + function setLogin(string $value): self { + $this->login = $value; + return $this; + } } diff --git a/src/PushEvent.php b/src/PushEvent.php index 82210c7..22e6234 100644 --- a/src/PushEvent.php +++ b/src/PushEvent.php @@ -8,232 +8,232 @@ use Psr\Http\Message\{UriInterface}; /** Represents a Gitea push event. */ class PushEvent implements \JsonSerializable { - /** @var string The hash of the new Git revision. */ - private $after = ''; + /** @var string The hash of the new Git revision. */ + private $after = ''; - /** @var string The hash of the previous Git revision. */ - private $before = ''; + /** @var string The hash of the previous Git revision. */ + private $before = ''; - /** @var \ArrayObject The revision commits. */ - private $commits; + /** @var \ArrayObject The revision commits. */ + private $commits; - /** @var UriInterface|null The URL for comparing the revisions. */ - private $compareUrl; + /** @var UriInterface|null The URL for comparing the revisions. */ + private $compareUrl; - /** @var User|null The user who pushed the commits. */ - private $pusher; + /** @var User|null The user who pushed the commits. */ + private $pusher; - /** @var string The Git reference. */ - private $ref = ''; + /** @var string The Git reference. */ + private $ref = ''; - /** @var Repository|null The repository where the commits were pushed. */ - private $repository; + /** @var Repository|null The repository where the commits were pushed. */ + private $repository; - /** @var string The secret used to validate this event. */ - private $secret = ''; + /** @var string The secret used to validate this event. */ + private $secret = ''; - /** @var User|null The user who sent this event. */ - private $sender; + /** @var User|null The user who sent this event. */ + private $sender; - /** Creates a new event. */ - function __construct() { - $this->commits = new \ArrayObject; - } + /** Creates a new event. */ + function __construct() { + $this->commits = new \ArrayObject; + } - /** - * Creates a new event from the specified JSON map. - * @param object $map A JSON map representing an event. - * @return static The instance corresponding to the specified JSON map. - */ - static function fromJson(object $map): self { - return (new static) - ->setAfter(isset($map->after) && is_string($map->after) ? $map->after : '') - ->setBefore(isset($map->before) && is_string($map->before) ? $map->before : '') - ->setCompareUrl(isset($map->compare_url) && is_string($map->compare_url) ? new Uri($map->compare_url) : null) - ->setCommits(isset($map->commits) && is_array($map->commits) ? array_map([PayloadCommit::class, 'fromJson'], $map->commits) : []) - ->setPusher(isset($map->pusher) && is_object($map->pusher) ? User::fromJson($map->pusher) : null) - ->setRef(isset($map->ref) && is_string($map->ref) ? $map->ref : '') - ->setRepository(isset($map->repository) && is_object($map->repository) ? Repository::fromJson($map->repository) : null) - ->setSecret(isset($map->secret) && is_string($map->secret) ? $map->secret : '') - ->setSender(isset($map->sender) && is_object($map->sender) ? User::fromJson($map->sender) : null); - } + /** + * Creates a new event from the specified JSON map. + * @param object $map A JSON map representing an event. + * @return static The instance corresponding to the specified JSON map. + */ + static function fromJson(object $map): self { + return (new static) + ->setAfter(isset($map->after) && is_string($map->after) ? $map->after : '') + ->setBefore(isset($map->before) && is_string($map->before) ? $map->before : '') + ->setCompareUrl(isset($map->compare_url) && is_string($map->compare_url) ? new Uri($map->compare_url) : null) + ->setCommits(isset($map->commits) && is_array($map->commits) ? array_map([PayloadCommit::class, 'fromJson'], $map->commits) : []) + ->setPusher(isset($map->pusher) && is_object($map->pusher) ? User::fromJson($map->pusher) : null) + ->setRef(isset($map->ref) && is_string($map->ref) ? $map->ref : '') + ->setRepository(isset($map->repository) && is_object($map->repository) ? Repository::fromJson($map->repository) : null) + ->setSecret(isset($map->secret) && is_string($map->secret) ? $map->secret : '') + ->setSender(isset($map->sender) && is_object($map->sender) ? User::fromJson($map->sender) : null); + } - /** - * Gets the hash of the new Git revision. - * @return string The hash of the new Git revision. - */ - function getAfter(): string { - return $this->after; - } + /** + * Gets the hash of the new Git revision. + * @return string The hash of the new Git revision. + */ + function getAfter(): string { + return $this->after; + } - /** - * Gets the hash of the new previous revision. - * @return string The hash of the previous Git revision. - */ - function getBefore(): string { - return $this->before; - } + /** + * Gets the hash of the new previous revision. + * @return string The hash of the previous Git revision. + */ + function getBefore(): string { + return $this->before; + } - /** - * Gets the revision commits. - * @return \ArrayObject The revision commits. - */ - function getCommits(): \ArrayObject { - return $this->commits; - } + /** + * Gets the revision commits. + * @return \ArrayObject The revision commits. + */ + function getCommits(): \ArrayObject { + return $this->commits; + } - /** - * Gets the URL for comparing the revisions. - * @return UriInterface|null The URL for comparing the revisions. - */ - function getCompareUrl(): ?UriInterface { - return $this->compareUrl; - } + /** + * Gets the URL for comparing the revisions. + * @return UriInterface|null The URL for comparing the revisions. + */ + function getCompareUrl(): ?UriInterface { + return $this->compareUrl; + } - /** - * Gets the user who pushed the commits. - * @return User|null The user who pushed the commits. - */ - function getPusher(): ?User { - return $this->pusher; - } + /** + * Gets the user who pushed the commits. + * @return User|null The user who pushed the commits. + */ + function getPusher(): ?User { + return $this->pusher; + } - /** - * Gets the Git reference. - * @return string The Git reference. - */ - function getRef(): string { - return $this->ref; - } + /** + * Gets the Git reference. + * @return string The Git reference. + */ + function getRef(): string { + return $this->ref; + } - /** - * Gets the repository where the commits were pushed. - * @return Repository|null The repository where the commits were pushed. - */ - function getRepository(): ?Repository { - return $this->repository; - } + /** + * Gets the repository where the commits were pushed. + * @return Repository|null The repository where the commits were pushed. + */ + function getRepository(): ?Repository { + return $this->repository; + } - /** - * Gets the secret used to validate this event. - * @return string The secret used to validate this event. - */ - function getSecret(): string { - return $this->secret; - } + /** + * Gets the secret used to validate this event. + * @return string The secret used to validate this event. + */ + function getSecret(): string { + return $this->secret; + } - /** - * Gets the user who sent this event. - * @return User|null The user who sent this event. - */ - function getSender(): ?User { - return $this->sender; - } + /** + * Gets the user who sent this event. + * @return User|null The user who sent this event. + */ + function getSender(): ?User { + return $this->sender; + } - /** - * 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' => ($user = $this->getPusher()) ? $user->jsonSerialize() : null, - 'ref' => $this->getRef(), - 'repository' => ($repository = $this->getRepository()) ? $repository->jsonSerialize() : null, - 'sender' => ($user = $this->getSender()) ? $user->jsonSerialize() : null - ]; - } + /** + * 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' => ($user = $this->getPusher()) ? $user->jsonSerialize() : null, + 'ref' => $this->getRef(), + 'repository' => ($repository = $this->getRepository()) ? $repository->jsonSerialize() : null, + 'sender' => ($user = $this->getSender()) ? $user->jsonSerialize() : null + ]; + } - /** - * Sets the hash of the new Git revision. - * @param string $value The hash of the new Git revision. - * @return $this This instance. - */ - function setAfter(string $value): self { - $this->after = $value; - return $this; - } + /** + * Sets the hash of the new Git revision. + * @param string $value The hash of the new Git revision. + * @return $this This instance. + */ + function setAfter(string $value): self { + $this->after = $value; + return $this; + } - /** - * Sets the hash of the new previous revision. - * @param string $value The hash of the new previous revision. - * @return $this This instance. - */ - function setBefore(string $value): self { - $this->before = $value; - return $this; - } + /** + * Sets the hash of the new previous revision. + * @param string $value The hash of the new previous revision. + * @return $this This instance. + */ + function setBefore(string $value): self { + $this->before = $value; + return $this; + } - /** - * Sets the revision commits. - * @param PayloadCommit[] $values The revision commits. - * @return $this This instance. - */ - function setCommits(array $values): self { - $this->getCommits()->exchangeArray($values); - return $this; - } + /** + * Sets the revision commits. + * @param PayloadCommit[] $values The revision commits. + * @return $this This instance. + */ + function setCommits(array $values): self { + $this->getCommits()->exchangeArray($values); + return $this; + } - /** - * Sets the URL for comparing the revisions. - * @param UriInterface|null $value The URL for comparing the revisions. - * @return $this This instance. - */ - function setCompareUrl(?UriInterface $value): self { - $this->compareUrl = $value; - return $this; - } + /** + * Sets the URL for comparing the revisions. + * @param UriInterface|null $value The URL for comparing the revisions. + * @return $this This instance. + */ + function setCompareUrl(?UriInterface $value): self { + $this->compareUrl = $value; + return $this; + } - /** - * Sets the user who pushed the commits. - * @param User|null $value The new pusher. - * @return $this This instance. - */ - function setPusher(?User $value): self { - $this->pusher = $value; - return $this; - } + /** + * Sets the user who pushed the commits. + * @param User|null $value The new pusher. + * @return $this This instance. + */ + function setPusher(?User $value): self { + $this->pusher = $value; + return $this; + } - /** - * Sets the Git reference. - * @param string $value The new Git reference. - * @return $this This instance. - */ - function setRef(string $value): self { - $this->ref = $value; - return $this; - } + /** + * Sets the Git reference. + * @param string $value The new Git reference. + * @return $this This instance. + */ + function setRef(string $value): self { + $this->ref = $value; + return $this; + } - /** - * Sets the repository where the commits were pushed. - * @param Repository|null $value The new repository. - * @return $this This instance. - */ - function setRepository(?Repository $value): self { - $this->repository = $value; - return $this; - } + /** + * Sets the repository where the commits were pushed. + * @param Repository|null $value The new repository. + * @return $this This instance. + */ + function setRepository(?Repository $value): self { + $this->repository = $value; + return $this; + } - /** - * Sets the secret used to validate this event. - * @param string $value The new secret used to validate this event. - * @return $this This instance. - */ - function setSecret(string $value): self { - $this->secret = $value; - return $this; - } + /** + * Sets the secret used to validate this event. + * @param string $value The new secret used to validate this event. + * @return $this This instance. + */ + function setSecret(string $value): self { + $this->secret = $value; + return $this; + } - /** - * Sets the user who sent this event. - * @param User|null $value The new sender. - * @return $this This instance. - */ - function setSender(?User $value): self { - $this->sender = $value; - return $this; - } + /** + * Sets the user who sent this event. + * @param User|null $value The new sender. + * @return $this This instance. + */ + function setSender(?User $value): self { + $this->sender = $value; + return $this; + } }