diff --git a/src/Model/PayloadCommit.php b/src/Model/PayloadCommit.php index 6b03f67..5ff26d1 100644 --- a/src/Model/PayloadCommit.php +++ b/src/Model/PayloadCommit.php @@ -1,11 +1,19 @@ -id = $id; - $this->setMessage($message); + function __construct(object $giteaClient, object $apiRequester, ...$args) { + $this->setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 2) { + $id = $args[0]; + $message = $args[1]; + if (!is_string($id)) { + $argumentType = gettype($id); + throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + if (!is_string($message)) { + $argumentType = gettype($message); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + $this->id = $id; + $this->setMessage($message); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } } /** * Creates a new commit from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object * @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); + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + return ( + new static( + $giteaClient, + $apiRequester, + 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($giteaClient, $apiRequester, $map->author) : null) + ->setCommitter(isset($map->committer) && is_object($map->committer) ? PayloadUser::fromJson($giteaClient, $apiRequester, $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($giteaClient, $apiRequester, $map->verification) : null); } /** diff --git a/src/Model/PayloadCommitVerification.php b/src/Model/PayloadCommitVerification.php index a652d25..5799a79 100644 --- a/src/Model/PayloadCommitVerification.php +++ b/src/Model/PayloadCommitVerification.php @@ -1,8 +1,16 @@ -setVerified($isVerified); + function __construct(object $giteaClient, object $apiRequester, ...$args) { + + $this->setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 1) { + $isVerified = $args[0]; + if (!is_bool($isVerified)) { + $argumentType = gettype($isVerified); + throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the boolean type, but a \"$argumentType\" was passed in"); + } + $this->setVerified($isVerified); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } } /** * Creates a new commit from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object * @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 : ''); + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + return ( + new static( + $giteaClient, + $apiRequester, + 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 : ''); } /** diff --git a/src/Model/PayloadUser.php b/src/Model/PayloadUser.php index 01e8baa..56b524e 100644 --- a/src/Model/PayloadUser.php +++ b/src/Model/PayloadUser.php @@ -1,8 +1,17 @@ -username = $username; + function __construct(object $giteaClient, object $apiRequester, ...$args) { + $this->setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 1) { + $username = $args[0]; + if (!is_string($username)) { + $argumentType = gettype($username); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the string type, but a \"$argumentType\" was passed in"); + } + $this->username = $username; + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } } /** * Creates a new user from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object * @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 : ''); + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { + return ( + new static( + $giteaClient, + $apiRequester, + 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 : ''); } /** @@ -58,7 +89,7 @@ class PayloadUser implements \JsonSerializable { /** * Converts this object to a map in JSON format. - * @return \stdClass The map in JSON format corresponding to this object. + * @return stdClass The map in JSON format corresponding to this object. */ function jsonSerialize(): \stdClass { return (object) [ diff --git a/src/Model/Permission.php b/src/Model/Permission.php index a285ed1..5925bba 100644 --- a/src/Model/Permission.php +++ b/src/Model/Permission.php @@ -1,8 +1,16 @@ -setAdmin($admin)->setPull($pull)->setPush($push); + function __construct(object $giteaClient, object $apiRequester, ...$args) { + $this->setGiteaClient($giteaClient); + $this->setApiRequester($apiRequester); + if (count($args) >= 2) { + $admin = $args[0]; + $pull = $args[1]; + $push = $args[1]; + if (!is_bool($admin)) { + $argumentType = gettype($admin); + throw new InvalidArgumentException("The \"__construct()\" function requires the 3rd parameter to be of the boolean type, but a \"$argumentType\" was passed in"); + } + if (!is_bool($pull)) { + $argumentType = gettype($pull); + throw new InvalidArgumentException("The \"__construct()\" function requires the 4th parameter to be of the boolean type, but a \"$argumentType\" was passed in"); + } + if (!is_bool($push)) { + $argumentType = gettype($push); + throw new InvalidArgumentException("The \"__construct()\" function requires the 5th parameter to be of the boolean type, but a \"$argumentType\" was passed in"); + } + $this->setAdmin($admin)->setPull($pull)->setPush($push); + } else { + $numArgs = func_num_args(); + throw new InvalidArgumentException("The \"__construct()\" function requires 4 parameters but only $numArgs were passed in"); + } } /** * Creates a new user from the specified JSON map. + * @param object $giteaClient The Gitea client that originally made the request for this object's data + * @param object $apiRequester The Api requester that created this object * @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 { + static function fromJson(object $giteaClient, object $apiRequester, object $map): self { return new static( + $giteaClient, + $apiRequester, 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