mirror of
				https://github.com/sitelease/sugar-cube-client.git
				synced 2025-10-31 12:02:30 +01:00 
			
		
		
		
	Made four models conform to the ApiModelInterface
+ Updated the methods and class definitions of several models to make them conform to the new ApiModelInterface
This commit is contained in:
		| @ -1,11 +1,19 @@ | ||||
| <?php declare(strict_types=1); | ||||
| <?php | ||||
|  | ||||
| namespace Gitea\Model; | ||||
|  | ||||
| use GuzzleHttp\Psr7\{Uri}; | ||||
| use Psr\Http\Message\{UriInterface}; | ||||
| use GuzzleHttp\Psr7\Uri; | ||||
| use Psr\Http\Message\UriInterface; | ||||
|  | ||||
| use Gitea\Model\PayloadUser; | ||||
| use Gitea\Model\PayloadCommitVerification; | ||||
|  | ||||
| use \InvalidArgumentException; | ||||
|  | ||||
| use Gitea\Model\Abstracts\AbstractApiModel; | ||||
|  | ||||
| /** Represents a commit. */ | ||||
| class PayloadCommit implements \JsonSerializable { | ||||
| class PayloadCommit extends AbstractApiModel { | ||||
|  | ||||
|     /** @var PayloadUser|null The person who authored the commit. */ | ||||
|     private $author; | ||||
| @ -30,26 +38,54 @@ class PayloadCommit implements \JsonSerializable { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new payload commit. | ||||
|      * @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 string $id The commit hash. | ||||
|      * @param string $message The commit message. | ||||
|      */ | ||||
|     function __construct(string $id, string $message) { | ||||
|         $this->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); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -1,8 +1,16 @@ | ||||
| <?php declare(strict_types=1); | ||||
| <?php | ||||
|  | ||||
| namespace Gitea\Model; | ||||
|  | ||||
| use GuzzleHttp\Psr7\Uri; | ||||
| use Psr\Http\Message\UriInterface; | ||||
|  | ||||
| use \InvalidArgumentException; | ||||
|  | ||||
| use Gitea\Model\Abstracts\AbstractApiModel; | ||||
|  | ||||
| /** Represents the GPG verification of a commit. */ | ||||
| class PayloadCommitVerification implements \JsonSerializable { | ||||
| class PayloadCommitVerification extends AbstractApiModel { | ||||
|  | ||||
|     /** @var bool Value indicating whether the verification has succeeded. */ | ||||
|     private $isVerified; | ||||
| @ -18,22 +26,45 @@ class PayloadCommitVerification implements \JsonSerializable { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new verification of a payload commit. | ||||
|      * @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 bool $isVerified Value indicating whether the verification has succeeded. | ||||
|      */ | ||||
|     function __construct(bool $isVerified = false) { | ||||
|         $this->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 : ''); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -1,8 +1,17 @@ | ||||
| <?php declare(strict_types=1); | ||||
| <?php | ||||
|  | ||||
| namespace Gitea\Model; | ||||
|  | ||||
| use GuzzleHttp\Psr7\Uri; | ||||
| use Psr\Http\Message\UriInterface; | ||||
|  | ||||
| use \stdClass; | ||||
| use \InvalidArgumentException; | ||||
|  | ||||
| use Gitea\Model\Abstracts\AbstractApiModel; | ||||
|  | ||||
| /** Represents the author or committer of a commit. */ | ||||
| class PayloadUser implements \JsonSerializable { | ||||
| class PayloadUser extends AbstractApiModel { | ||||
|  | ||||
|     /** @var string The mail address. */ | ||||
|     private $email = ''; | ||||
| @ -15,21 +24,43 @@ class PayloadUser implements \JsonSerializable { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new payload user. | ||||
|      * @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 string $username The name of the Gitea account. | ||||
|      */ | ||||
|     function __construct(string $username) { | ||||
|         $this->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) [ | ||||
|  | ||||
| @ -1,8 +1,16 @@ | ||||
| <?php declare(strict_types=1); | ||||
| <?php | ||||
|  | ||||
| namespace Gitea\Model; | ||||
|  | ||||
| use GuzzleHttp\Psr7\Uri; | ||||
| use Psr\Http\Message\UriInterface; | ||||
|  | ||||
| use \InvalidArgumentException; | ||||
|  | ||||
| use Gitea\Model\Abstracts\AbstractApiModel; | ||||
|  | ||||
| /** Represents a set of permissions. */ | ||||
| class Permission implements \JsonSerializable { | ||||
| class Permission extends AbstractApiModel { | ||||
|  | ||||
|     /** @var bool Value indicating whether administrator access is allowed. */ | ||||
|     private $admin; | ||||
| @ -15,21 +23,49 @@ class Permission implements \JsonSerializable { | ||||
|  | ||||
|     /** | ||||
|      * Creates a new permission. | ||||
|      * @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 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); | ||||
|     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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user