Browse Source

Code formatting

main
Cédric Belin 2 months ago
parent
commit
ddd0abed16
28 changed files with 783 additions and 774 deletions
  1. +8
    -3
      .editorconfig
  2. +1
    -1
      .github/workflows/build.yaml
  3. +5
    -5
      .vscode/settings.json
  4. +54
    -54
      composer.json
  5. +1
    -1
      doc/index.md
  6. +6
    -6
      doc/installation.md
  7. +9
    -5
      etc/mkdocs.yaml
  8. +22
    -22
      etc/phpdoc.xml
  9. +4
    -4
      etc/phpstan.neon
  10. +13
    -13
      etc/phpunit.xml
  11. +7
    -7
      example/main.php
  12. +99
    -99
      src/PushEvent.php
  13. +54
    -54
      src/models/PayloadCommit.php
  14. +49
    -49
      src/models/PayloadCommitVerification.php
  15. +29
    -29
      src/models/PayloadUser.php
  16. +27
    -27
      src/models/Permission.php
  17. +164
    -164
      src/models/Repository.php
  18. +22
    -22
      src/models/ServerVersion.php
  19. +11
    -11
      src/models/StatusState.php
  20. +37
    -37
      src/models/Team.php
  21. +11
    -11
      src/models/TeamPermission.php
  22. +53
    -53
      src/models/TrackedTime.php
  23. +53
    -53
      src/models/User.php
  24. +34
    -34
      src/models/UserHeatmapData.php
  25. +5
    -5
      test/index.php
  26. +3
    -3
      tool/clean.ps1
  27. +1
    -1
      tool/doc.ps1
  28. +1
    -1
      tool/upgrade.ps1

+ 8
- 3
.editorconfig View File

@@ -3,11 +3,16 @@ root = true

[*]
charset = utf-8
indent_size = 2
indent_style = space
indent_style = tab
insert_final_newline = true
max_line_length = 200
quote_type = double
tab_width = 2
trim_trailing_whitespace = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
indent_style = space

+ 1
- 1
.github/workflows/build.yaml View File

@@ -3,7 +3,7 @@ on:
pull_request:
push:
schedule:
- cron: '0 0 1 * *'
- cron: "0 0 1 * *"
jobs:
test:
runs-on: ubuntu-latest


+ 5
- 5
.vscode/settings.json View File

@@ -1,7 +1,7 @@
{
"editor.insertSpaces": true,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
"editor.insertSpaces": false,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}

+ 54
- 54
composer.json View File

@@ -1,56 +1,56 @@
{
"description": "Gitea client library for the Yii Framework.",
"homepage": "https://docs.belin.io/yii2-gitea",
"license": "MIT",
"name": "cedx/yii2-gitea",
"type": "yii2-extension",
"version": "0.4.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"psr-4": {"yii\\gitea\\": "src/"}
},
"autoload-dev": {
"psr-4": {"yii\\gitea\\": "test/"}
},
"config": {
"fxp-asset": {"enabled": false},
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"api",
"client",
"git",
"gitea",
"scm",
"vcs",
"yii2"
],
"repositories": [
{"type": "composer", "url": "https://asset-packagist.org"}
],
"require": {
"php": ">=7.4.0",
"cedx/enum": "^8.2.0",
"nyholm/psr7": "^1.2.1",
"yiisoft/yii2": "^2.0.35",
"yiisoft/yii2-httpclient": "^2.0.12"
},
"require-dev": {
"cedx/coveralls": "^13.0.0",
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"coverage": "coveralls var/coverage.xml",
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/yii2-gitea",
"issues": "https://git.belin.io/cedx/yii2-gitea/issues"
}
"description": "Gitea client library for the Yii Framework.",
"homepage": "https://docs.belin.io/yii2-gitea",
"license": "MIT",
"name": "cedx/yii2-gitea",
"type": "yii2-extension",
"version": "0.4.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"psr-4": {"yii\\gitea\\": "src/"}
},
"autoload-dev": {
"psr-4": {"yii\\gitea\\": "test/"}
},
"config": {
"fxp-asset": {"enabled": false},
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"api",
"client",
"git",
"gitea",
"scm",
"vcs",
"yii2"
],
"repositories": [
{"type": "composer", "url": "https://asset-packagist.org"}
],
"require": {
"php": ">=7.4.0",
"cedx/enum": "^8.2.0",
"nyholm/psr7": "^1.2.1",
"yiisoft/yii2": "^2.0.35",
"yiisoft/yii2-httpclient": "^2.0.12"
},
"require-dev": {
"cedx/coveralls": "^13.0.0",
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"coverage": "coveralls var/coverage.xml",
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/yii2-gitea",
"issues": "https://git.belin.io/cedx/yii2-gitea/issues"
}
}

+ 1
- 1
doc/index.md View File

@@ -6,7 +6,7 @@
![Gitea](img/gitea.png)

!!! danger "Not production ready"
This project is a **work in progress**.
This project is a **work in progress**.

## Quick start
Install the latest version of **Gitea for Yii** with [Composer](https://getcomposer.org):


+ 6
- 6
doc/installation.md View File

@@ -3,7 +3,7 @@
## Requirements
Before installing **Gitea for Yii**, you need to make sure you have [PHP](https://www.php.net)
and [Composer](https://getcomposer.org), the PHP package manager, up and running.
You can verify if you're already good to go with the following commands:

```shell
@@ -15,8 +15,8 @@ composer --version
```

!!! info
If you plan to play with the package sources, you will also need the latest versions of
[PowerShell](https://docs.microsoft.com/en-us/powershell) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material).
If you plan to play with the package sources, you will also need the latest versions of
[PowerShell](https://docs.microsoft.com/en-us/powershell) and [Material for MkDocs](https://squidfunk.github.io/mkdocs-material).

## Installing with Composer package manager

@@ -33,8 +33,8 @@ Now in your [PHP](https://www.php.net) code, you can use:
```php
<?php
use yii\gitea\models\{
Repository,
Team,
User
Repository,
Team,
User
};
```

+ 9
- 5
etc/mkdocs.yaml View File

@@ -8,19 +8,23 @@ site_dir: ../www

repo_name: git.belin.io
repo_url: https://git.belin.io/cedx/yii2-gitea
edit_uri: ''
edit_uri: ""

copyright: Copyright &copy; 2018 - 2020 Cédric Belin
extra:
social:
- icon: fontawesome/solid/globe
link: 'https://belin.io'
link: "https://belin.io"
name: Belin.io
- icon: fontawesome/brands/github
link: 'https://github.com/cedx'
link: "https://github.com/cedx"
name: GitHub
- icon: fontawesome/brands/twitter
link: 'https://twitter.com/cedxbelin'
link: "https://twitter.com/cedxbelin"
name: Twitter
- icon: fontawesome/brands/linkedin
link: 'https://linkedin.com/in/cedxbelin'
link: "https://linkedin.com/in/cedxbelin"
name: LinkedIn

markdown_extensions:
- admonition


+ 22
- 22
etc/phpdoc.xml View File

@@ -1,25 +1,25 @@
<?xml version="1.0"?>
<phpdocumentor
configVersion="3"
xmlns="http://www.phpdoc.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://docs.phpdoc.org/latest/phpdoc.xsd">
<title>Gitea for Yii</title>
<paths>
<cache>../var/phpdoc</cache>
<output>../doc/api</output>
</paths>
<version number="0.4.0">
<api>
<markers>
<marker>TODO</marker>
</markers>
<source dsn="..">
<path>src</path>
</source>
<visibility>protected</visibility>
<visibility>public</visibility>
</api>
</version>
configVersion="3"
xmlns="http://www.phpdoc.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://docs.phpdoc.org/latest/phpdoc.xsd">
<title>Gitea for Yii</title>
<paths>
<cache>../var/phpdoc</cache>
<output>../doc/api</output>
</paths>
<version number="0.4.0">
<api>
<markers>
<marker>TODO</marker>
</markers>
<source dsn="..">
<path>src</path>
</source>
<visibility>protected</visibility>
<visibility>public</visibility>
</api>
</version>
</phpdocumentor>

+ 4
- 4
etc/phpstan.neon View File

@@ -1,5 +1,5 @@
parameters:
autoload_files: [../vendor/yiisoft/yii2/Yii.php]
checkMissingIterableValueType: false
level: max
paths: [../src, ../test]
autoload_files: [../vendor/yiisoft/yii2/Yii.php]
checkMissingIterableValueType: false
level: max
paths: [../src, ../test]

+ 13
- 13
etc/phpunit.xml View File

@@ -1,18 +1,18 @@
<?xml version="1.0"?>
<phpunit bootstrap="../test/index.php" cacheResult="false" testdox="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
</filter>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="../var/coverage.xml"/>
</logging>
<logging>
<log type="coverage-clover" target="../var/coverage.xml"/>
</logging>

<testsuites>
<testsuite name="all">
<directory suffix="Test.php">../test</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">../test</directory>
</testsuite>
</testsuites>
</phpunit>

+ 7
- 7
example/main.php View File

@@ -10,12 +10,12 @@ use yii\web\{BadRequestHttpException};
* @throws BadRequestHttpException The request headers or the request body are invalid.
*/
function main(): PushEvent {
/** @var \yii\web\Request $request */
$request = Yii::$app->getRequest();
$headers = $request->getHeaders();
if (!$headers->has('X-Gitea-Delivery') || !$headers->has('X-Gitea-Event')) throw new BadRequestHttpException('Invalid payload data.');
/** @var \yii\web\Request $request */
$request = Yii::$app->getRequest();
$headers = $request->getHeaders();
if (!$headers->has("X-Gitea-Delivery") || !$headers->has("X-Gitea-Event")) throw new BadRequestHttpException("Invalid payload data.");

$data = Json::decode($request->getRawBody());
if (!is_array($data)) throw new BadRequestHttpException('Invalid payload data.');
return PushEvent::fromJson($data);
$data = Json::decode($request->getRawBody());
if (!is_array($data)) throw new BadRequestHttpException("Invalid payload data.");
return PushEvent::fromJson($data);
}

+ 99
- 99
src/PushEvent.php View File

@@ -12,103 +12,103 @@ use yii\gitea\models\{PayloadCommit, Repository, User};
*/
class PushEvent extends Model {

/** @var string The hash of the new Git revision. */
public string $after = '';
/** @var string The hash of the previous Git revision. */
public string $before = '';
/** @var UriInterface|null The URL for comparing the revisions. */
public ?UriInterface $compareUrl = null;
/** @var User|null The user who pushed the commits. */
public ?User $pusher = null;
/** @var string The Git reference. */
public string $ref = '';
/** @var Repository|null The repository where the commits were pushed. */
public ?Repository $repository = null;
/** @var string The secret used to validate this event. */
public string $secret = '';
/** @var User|null The user who sent this event. */
public ?User $sender = null;
/** @var \ArrayObject<int, PayloadCommit> The revision commits. */
private \ArrayObject $commits;
/**
* Creates a new event.
* @param array<string, mixed> $config Name-value pairs that will be used to initialize the object properties.
*/
function __construct(array $config = []) {
$this->commits = new \ArrayObject;
parent::__construct($config);
}
/**
* Creates a new event from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing an event.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'after' => isset($map['after']) && is_string($map['after']) ? $map['after'] : '',
'before' => isset($map['before']) && is_string($map['before']) ? $map['before'] : '',
'compareUrl' => isset($map['compare_url']) && is_string($map['compare_url']) ? new Uri($map['compare_url']) : null,
'commits' => isset($map['commits']) && is_array($map['commits']) ? array_map([PayloadCommit::class, 'fromJson'], $map['commits']) : [],
'pusher' => isset($map['pusher']) && is_array($map['pusher']) ? User::fromJson($map['pusher']) : null,
'ref' => isset($map['ref']) && is_string($map['ref']) ? $map['ref'] : '',
'repository' => isset($map['repository']) && is_array($map['repository']) ? Repository::fromJson($map['repository']) : null,
'secret' => isset($map['secret']) && is_string($map['secret']) ? $map['secret'] : '',
'sender' => isset($map['sender']) && is_array($map['sender']) ? User::fromJson($map['sender']) : null
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'after',
'before',
'compare_url' => fn(self $model) => $model->compareUrl ? (string) $model->compareUrl : null,
'commits',
'pusher',
'ref',
'repository',
'sender'
];
}
/**
* Gets the revision commits.
* @return \ArrayObject<int, PayloadCommit> The revision commits.
*/
function getCommits(): \ArrayObject {
return $this->commits;
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['after', 'before', 'ref', 'secret'], 'trim']
];
}
/**
* 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;
}
/** @var string The hash of the new Git revision. */
public string $after = "";
/** @var string The hash of the previous Git revision. */
public string $before = "";
/** @var UriInterface|null The URL for comparing the revisions. */
public ?UriInterface $compareUrl = null;
/** @var User|null The user who pushed the commits. */
public ?User $pusher = null;
/** @var string The Git reference. */
public string $ref = "";
/** @var Repository|null The repository where the commits were pushed. */
public ?Repository $repository = null;
/** @var string The secret used to validate this event. */
public string $secret = "";
/** @var User|null The user who sent this event. */
public ?User $sender = null;
/** @var \ArrayObject<int, PayloadCommit> The revision commits. */
private \ArrayObject $commits;
/**
* Creates a new event.
* @param array<string, mixed> $config Name-value pairs that will be used to initialize the object properties.
*/
function __construct(array $config = []) {
$this->commits = new \ArrayObject;
parent::__construct($config);
}
/**
* Creates a new event from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing an event.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"after" => isset($map["after"]) && is_string($map["after"]) ? $map["after"] : "",
"before" => isset($map["before"]) && is_string($map["before"]) ? $map["before"] : "",
"compareUrl" => isset($map["compare_url"]) && is_string($map["compare_url"]) ? new Uri($map["compare_url"]) : null,
"commits" => isset($map["commits"]) && is_array($map["commits"]) ? array_map([PayloadCommit::class, "fromJson"], $map["commits"]) : [],
"pusher" => isset($map["pusher"]) && is_array($map["pusher"]) ? User::fromJson($map["pusher"]) : null,
"ref" => isset($map["ref"]) && is_string($map["ref"]) ? $map["ref"] : "",
"repository" => isset($map["repository"]) && is_array($map["repository"]) ? Repository::fromJson($map["repository"]) : null,
"secret" => isset($map["secret"]) && is_string($map["secret"]) ? $map["secret"] : "",
"sender" => isset($map["sender"]) && is_array($map["sender"]) ? User::fromJson($map["sender"]) : null
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"after",
"before",
"compare_url" => fn(self $model) => $model->compareUrl ? (string) $model->compareUrl : null,
"commits",
"pusher",
"ref",
"repository",
"sender"
];
}
/**
* Gets the revision commits.
* @return \ArrayObject<int, PayloadCommit> The revision commits.
*/
function getCommits(): \ArrayObject {
return $this->commits;
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["after", "before", "ref", "secret"], "trim"]
];
}
/**
* 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;
}
}

+ 54
- 54
src/models/PayloadCommit.php View File

@@ -8,67 +8,67 @@ use yii\base\{Model};
/** Represents a commit. */
class PayloadCommit extends Model {

/** @var PayloadUser|null The person who authored the commit. */
public ?PayloadUser $author = null;
/** @var PayloadUser|null The person who authored the commit. */
public ?PayloadUser $author = null;

/** @var PayloadUser|null The person who committed the code. */
public ?PayloadUser $committer = null;
/** @var PayloadUser|null The person who committed the code. */
public ?PayloadUser $committer = null;

/** @var string The commit hash. */
public string $id = '';
/** @var string The commit hash. */
public string $id = "";

/** @var string The commit message. */
public string $message = '';
/** @var string The commit message. */
public string $message = "";

/** @var \DateTimeInterface|null The commit date. */
public ?\DateTimeInterface $timestamp = null;
/** @var \DateTimeInterface|null The commit date. */
public ?\DateTimeInterface $timestamp = null;

/** @var UriInterface|null The URL to the commit's history. */
public ?UriInterface $url = null;
/** @var UriInterface|null The URL to the commit's history. */
public ?UriInterface $url = null;

/** @var PayloadCommitVerification|null The GPG verification of this commit. */
public ?PayloadCommitVerification $verification = null;
/** @var PayloadCommitVerification|null The GPG verification of this commit. */
public ?PayloadCommitVerification $verification = null;

/**
* Creates a new commit from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a commit.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'author' => isset($map['author']) && is_array($map['author']) ? PayloadUser::fromJson($map['author']) : null,
'committer' => isset($map['committer']) && is_array($map['committer']) ? PayloadUser::fromJson($map['committer']) : null,
'id' => isset($map['id']) && is_string($map['id']) ? $map['id'] : '',
'message' => isset($map['message']) && is_string($map['message']) ? $map['message'] : '',
'timestamp' => isset($map['timestamp']) && is_string($map['timestamp']) ? new \DateTimeImmutable($map['timestamp']) : null,
'url' => isset($map['url']) && is_string($map['url']) ? new Uri($map['url']) : null,
'verification' => isset($map['verification']) && is_array($map['verification']) ? PayloadCommitVerification::fromJson($map['verification']) : null
]);
}
/**
* Creates a new commit from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a commit.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"author" => isset($map["author"]) && is_array($map["author"]) ? PayloadUser::fromJson($map["author"]) : null,
"committer" => isset($map["committer"]) && is_array($map["committer"]) ? PayloadUser::fromJson($map["committer"]) : null,
"id" => isset($map["id"]) && is_string($map["id"]) ? $map["id"] : "",
"message" => isset($map["message"]) && is_string($map["message"]) ? $map["message"] : "",
"timestamp" => isset($map["timestamp"]) && is_string($map["timestamp"]) ? new \DateTimeImmutable($map["timestamp"]) : null,
"url" => isset($map["url"]) && is_string($map["url"]) ? new Uri($map["url"]) : null,
"verification" => isset($map["verification"]) && is_array($map["verification"]) ? PayloadCommitVerification::fromJson($map["verification"]) : null
]);
}

/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'author',
'committer',
'id',
'message',
'timestamp' => fn(self $model) => $model->timestamp ? $model->timestamp->format('c') : null,
'url' => fn(self $model) => $model->url ? (string) $model->url : null,
'verification'
];
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"author",
"committer",
"id",
"message",
"timestamp" => fn(self $model) => $model->timestamp ? $model->timestamp->format("c") : null,
"url" => fn(self $model) => $model->url ? (string) $model->url : null,
"verification"
];
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['id', 'message'], 'trim']
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["id", "message"], "trim"]
];
}
}

+ 49
- 49
src/models/PayloadCommitVerification.php View File

@@ -6,53 +6,53 @@ use yii\base\{Model};
/** Represents the GPG verification of a commit. */
class PayloadCommitVerification extends Model {

/** @var bool Value indicating whether the verification has succeeded. */
public bool $isVerified = false;
/** @var string A custom message sent with the verification request. */
public string $payload = '';
/** @var string A message providing details about the verification. */
public string $reason = '';
/** @var string The signing key used for the verification. */
public string $signature = '';
/**
* Creates a new commit from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a commit.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'isVerified' => isset($map['verified']) && is_bool($map['verified']) ? $map['verified'] : false,
'payload' => isset($map['payload']) && is_string($map['payload']) ? $map['payload'] : '',
'reason' => isset($map['reason']) && is_string($map['reason']) ? $map['reason'] : '',
'signature' => isset($map['signature']) && is_string($map['signature']) ? $map['signature'] : ''
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'payload',
'reason',
'signature',
'verified' => 'isVerified'
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['payload', 'reason', 'signature'], 'trim'],
['isVerified', 'boolean', 'falseValue' => false, 'trueValue' => true]
];
}
/** @var bool Value indicating whether the verification has succeeded. */
public bool $isVerified = false;
/** @var string A custom message sent with the verification request. */
public string $payload = "";
/** @var string A message providing details about the verification. */
public string $reason = "";
/** @var string The signing key used for the verification. */
public string $signature = "";
/**
* Creates a new commit from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a commit.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"isVerified" => isset($map["verified"]) && is_bool($map["verified"]) ? $map["verified"] : false,
"payload" => isset($map["payload"]) && is_string($map["payload"]) ? $map["payload"] : "",
"reason" => isset($map["reason"]) && is_string($map["reason"]) ? $map["reason"] : "",
"signature" => isset($map["signature"]) && is_string($map["signature"]) ? $map["signature"] : ""
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"payload",
"reason",
"signature",
"verified" => "isVerified"
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["payload", "reason", "signature"], "trim"],
["isVerified", "boolean", "falseValue" => false, "trueValue" => true]
];
}
}

+ 29
- 29
src/models/PayloadUser.php View File

@@ -6,37 +6,37 @@ use yii\base\{Model};
/** Represents the author or committer of a commit. */
class PayloadUser extends Model {

/** @var string The mail address. */
public string $email = '';
/** @var string The mail address. */
public string $email = "";

/** @var string The full name. */
public string $name = '';
/** @var string The full name. */
public string $name = "";

/** @var string The name of the Gitea account. */
public string $username = '';
/** @var string The name of the Gitea account. */
public string $username = "";

/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'email' => isset($map['email']) && is_string($map['email']) ? mb_strtolower($map['email']) : '',
'name' => isset($map['name']) && is_string($map['name']) ? $map['name'] : '',
'username' => isset($map['username']) && is_string($map['username']) ? $map['username'] : ''
]);
}
/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"email" => isset($map["email"]) && is_string($map["email"]) ? mb_strtolower($map["email"]) : "",
"name" => isset($map["name"]) && is_string($map["name"]) ? $map["name"] : "",
"username" => isset($map["username"]) && is_string($map["username"]) ? $map["username"] : ""
]);
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['email', 'name', 'username'], 'trim'],
['email', 'filter', 'filter' => 'mb_strtolower'],
['email', 'email']
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["email", "name", "username"], "trim"],
["email", "filter", "filter" => "mb_strtolower"],
["email", "email"]
];
}
}

+ 27
- 27
src/models/Permission.php View File

@@ -6,35 +6,35 @@ use yii\base\{Model};
/** Represents a set of permissions. */
class Permission extends Model {

/** @var bool Value indicating whether administrator access is allowed. */
public bool $admin = false;
/** @var bool Value indicating whether administrator access is allowed. */
public bool $admin = false;

/** @var bool Value indicating whether pull is allowed. */
public bool $pull = false;
/** @var bool Value indicating whether pull is allowed. */
public bool $pull = false;

/** @var bool Value indicating whether push is allowed. */
public bool $push = false;
/** @var bool Value indicating whether push is allowed. */
public bool $push = false;

/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'admin' => isset($map['admin']) && is_bool($map['admin']) ? $map['admin'] : false,
'pull' => isset($map['pull']) && is_bool($map['pull']) ? $map['pull'] : false,
'push' => isset($map['push']) && is_bool($map['push']) ? $map['push'] : false
]);
}
/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"admin" => isset($map["admin"]) && is_bool($map["admin"]) ? $map["admin"] : false,
"pull" => isset($map["pull"]) && is_bool($map["pull"]) ? $map["pull"] : false,
"push" => isset($map["push"]) && is_bool($map["push"]) ? $map["push"] : false
]);
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['admin', 'pull', 'push'], 'boolean', 'falseValue' => false, 'trueValue' => true]
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["admin", "pull", "push"], "boolean", "falseValue" => false, "trueValue" => true]
];
}
}

+ 164
- 164
src/models/Repository.php View File

@@ -11,168 +11,168 @@ use yii\base\{Model};
*/
class Repository extends Model {

/** @var UriInterface|null The HTTP-based URL for cloning this repository. */
public ?UriInterface $cloneUrl = null;
/** @var \DateTimeInterface|null The date the repository was created. */
public ?\DateTimeInterface $createdAt = null;
/** @var string The name of the default branch. */
public string $defaultBranch = '';
/** @var string The repository description. */
public string $description = '';
/** @var int The number of forks of this repository. */
public int $forksCount = 0;
/** @var string The full name. */
public string $fullName = '';
/** @var UriInterface|null The Gitea URL of this repository. */
public ?UriInterface $htmlUrl = null;
/** @var int The repository identifier. */
public int $id = -1;
/** @var bool Value indicating whether this repository is empty. */
public bool $isEmpty = false;
/** @var bool Value indicating whether this repository is a fork. */
public bool $isFork = false;
/** @var bool Value indicating whether this repository is a mirror. */
public bool $isMirror = false;
/** @var bool Value indicating whether this repository is private. */
public bool $isPrivate = false;
/** @var int The number of open issues of this repository. */
public int $openIssuesCount = 0;
/** @var User|null The repository owner. */
public ?User $owner = null;
/** @var Repository|null The parent repository, if this repository is a fork or a mirror. */
public ?Repository $parent = null;
/** @var Permission|null The repository permissions. */
public ?Permission $permissions = null;
/** @var int The repository size, in kilobytes. */
public int $size = 0;
/** @var UriInterface|null The SSH-based URL for cloning this repository. */
public ?UriInterface $sshUrl = null;
/** @var int The number of stars of this repository. */
public int $starsCount = 0;
/** @var \DateTimeInterface|null The date the repository was updated. */
public ?\DateTimeInterface $updatedAt = null;
/** @var int The number of watchers of this repository. */
public int $watchersCount = 0;
/** @var UriInterface|null The URL of the repository website. */
public ?UriInterface $website = null;
/** @var string The repository name. */
private string $name = '';
/**
* Creates a new repository from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a repository.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'cloneUrl' => isset($map['clone_url']) && is_string($map['clone_url']) ? new Uri($map['clone_url']) : null,
'createdAt' => isset($map['created_at']) && is_string($map['created_at']) ? new \DateTimeImmutable($map['created_at']) : null,
'defaultBranch' => isset($map['default_branch']) && is_string($map['default_branch']) ? $map['default_branch'] : '',
'description' => isset($map['description']) && is_string($map['description']) ? $map['description'] : '',
'forksCount' => isset($map['forks_count']) && is_int($map['forks_count']) ? $map['forks_count'] : 0,
'fullName' => isset($map['full_name']) && is_string($map['full_name']) ? $map['full_name'] : '',
'htmlUrl' => isset($map['html_url']) && is_string($map['html_url']) ? new Uri($map['html_url']) : null,
'id' => isset($map['id']) && is_int($map['id']) ? $map['id'] : -1,
'isEmpty' => isset($map['empty']) && is_bool($map['empty']) ? $map['empty'] : false,
'isFork' => isset($map['fork']) && is_bool($map['fork']) ? $map['fork'] : false,
'isMirror' => isset($map['mirror']) && is_bool($map['mirror']) ? $map['mirror'] : false,
'isPrivate' => isset($map['private']) && is_bool($map['private']) ? $map['private'] : false,
'name' => isset($map['name']) && is_string($map['name']) ? $map['name'] : '',
'openIssuesCount' => isset($map['open_issues_count']) && is_int($map['open_issues_count']) ? $map['open_issues_count'] : 0,
'owner' => isset($map['owner']) && is_array($map['owner']) ? User::fromJson($map['owner']) : null,
'parent' => isset($map['parent']) && is_array($map['parent']) ? Repository::fromJson($map['parent']) : null,
'permissions' => isset($map['permissions']) && is_array($map['permissions']) ? Permission::fromJson($map['permissions']) : null,
'size' => isset($map['size']) && is_int($map['size']) ? $map['size'] : 0,
'sshUrl' => isset($map['ssh_url']) && is_string($map['ssh_url']) ? new Uri($map['ssh_url']) : null,
'starsCount' => isset($map['stars_count']) && is_int($map['stars_count']) ? $map['stars_count'] : 0,
'updatedAt' => isset($map['updated_at']) && is_string($map['updated_at']) ? new \DateTimeImmutable($map['updated_at']) : null,
'watchersCount' => isset($map['watchers_count']) && is_int($map['watchers_count']) ? $map['watchers_count'] : 0,
'website' => isset($map['website']) && is_string($map['website']) ? new Uri($map['website']) : null,
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'clone_url' => fn(self $model) => $model->cloneUrl ? (string) $model->cloneUrl : null,
'created_at' => fn(self $model) => $model->createdAt ? $model->createdAt->format('c') : null,
'default_branch' => 'defaultBranch',
'description',
'empty' => 'isEmpty',
'fork' => 'isFork',
'forks_count' => 'forksCount',
'full_name' => 'fullName',
'html_url' => fn(self $model) => $model->htmlUrl ? (string) $model->htmlUrl : null,
'id',
'mirror' => 'isMirror',
'name',
'open_issues_count' => 'openIssuesCount',
'owner',
'parent',
'permissions',
'private' => 'isPrivate',
'size',
'ssh_url' => fn(self $model) => $model->sshUrl ? (string) $model->sshUrl : null,
'stars_count' => 'starsCount',
'updated_at' => fn(self $model) => $model->updatedAt ? $model->updatedAt->format('c') : null,
'watchers_count' => 'watchersCount',
'website' => fn(self $model) => $model->website ? (string) $model->website : null
];
}
/**
* Gets the repository name.
* @return string The repository name.
*/
function getName(): string {
if (mb_strlen($this->name)) return $this->name;
return mb_strlen($this->fullName) ? explode('/', $this->fullName)[1] : '';
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['defaultBranch', 'description', 'fullName', 'name'], 'trim'],
[['isEmpty', 'isFork', 'isMirror', 'isPrivate'], 'boolean', 'falseValue' => false, 'trueValue' => true],
[['forksCount', 'id', 'openIssuesCount', 'size', 'starsCount', 'watchersCount'], 'integer', 'min' => 0]
];
}
/**
* 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;
}
/** @var UriInterface|null The HTTP-based URL for cloning this repository. */
public ?UriInterface $cloneUrl = null;
/** @var \DateTimeInterface|null The date the repository was created. */
public ?\DateTimeInterface $createdAt = null;
/** @var string The name of the default branch. */
public string $defaultBranch = "";
/** @var string The repository description. */
public string $description = "";
/** @var int The number of forks of this repository. */
public int $forksCount = 0;
/** @var string The full name. */
public string $fullName = "";
/** @var UriInterface|null The Gitea URL of this repository. */
public ?UriInterface $htmlUrl = null;
/** @var int The repository identifier. */
public int $id = -1;
/** @var bool Value indicating whether this repository is empty. */
public bool $isEmpty = false;
/** @var bool Value indicating whether this repository is a fork. */
public bool $isFork = false;
/** @var bool Value indicating whether this repository is a mirror. */
public bool $isMirror = false;
/** @var bool Value indicating whether this repository is private. */
public bool $isPrivate = false;
/** @var int The number of open issues of this repository. */
public int $openIssuesCount = 0;
/** @var User|null The repository owner. */
public ?User $owner = null;
/** @var Repository|null The parent repository, if this repository is a fork or a mirror. */
public ?Repository $parent = null;
/** @var Permission|null The repository permissions. */
public ?Permission $permissions = null;
/** @var int The repository size, in kilobytes. */
public int $size = 0;
/** @var UriInterface|null The SSH-based URL for cloning this repository. */
public ?UriInterface $sshUrl = null;
/** @var int The number of stars of this repository. */
public int $starsCount = 0;
/** @var \DateTimeInterface|null The date the repository was updated. */
public ?\DateTimeInterface $updatedAt = null;
/** @var int The number of watchers of this repository. */
public int $watchersCount = 0;
/** @var UriInterface|null The URL of the repository website. */
public ?UriInterface $website = null;
/** @var string The repository name. */
private string $name = "";
/**
* Creates a new repository from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a repository.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"cloneUrl" => isset($map["clone_url"]) && is_string($map["clone_url"]) ? new Uri($map["clone_url"]) : null,
"createdAt" => isset($map["created_at"]) && is_string($map["created_at"]) ? new \DateTimeImmutable($map["created_at"]) : null,
"defaultBranch" => isset($map["default_branch"]) && is_string($map["default_branch"]) ? $map["default_branch"] : "",
"description" => isset($map["description"]) && is_string($map["description"]) ? $map["description"] : "",
"forksCount" => isset($map["forks_count"]) && is_int($map["forks_count"]) ? $map["forks_count"] : 0,
"fullName" => isset($map["full_name"]) && is_string($map["full_name"]) ? $map["full_name"] : "",
"htmlUrl" => isset($map["html_url"]) && is_string($map["html_url"]) ? new Uri($map["html_url"]) : null,
"id" => isset($map["id"]) && is_int($map["id"]) ? $map["id"] : -1,
"isEmpty" => isset($map["empty"]) && is_bool($map["empty"]) ? $map["empty"] : false,
"isFork" => isset($map["fork"]) && is_bool($map["fork"]) ? $map["fork"] : false,
"isMirror" => isset($map["mirror"]) && is_bool($map["mirror"]) ? $map["mirror"] : false,
"isPrivate" => isset($map["private"]) && is_bool($map["private"]) ? $map["private"] : false,
"name" => isset($map["name"]) && is_string($map["name"]) ? $map["name"] : "",
"openIssuesCount" => isset($map["open_issues_count"]) && is_int($map["open_issues_count"]) ? $map["open_issues_count"] : 0,
"owner" => isset($map["owner"]) && is_array($map["owner"]) ? User::fromJson($map["owner"]) : null,
"parent" => isset($map["parent"]) && is_array($map["parent"]) ? Repository::fromJson($map["parent"]) : null,
"permissions" => isset($map["permissions"]) && is_array($map["permissions"]) ? Permission::fromJson($map["permissions"]) : null,
"size" => isset($map["size"]) && is_int($map["size"]) ? $map["size"] : 0,
"sshUrl" => isset($map["ssh_url"]) && is_string($map["ssh_url"]) ? new Uri($map["ssh_url"]) : null,
"starsCount" => isset($map["stars_count"]) && is_int($map["stars_count"]) ? $map["stars_count"] : 0,
"updatedAt" => isset($map["updated_at"]) && is_string($map["updated_at"]) ? new \DateTimeImmutable($map["updated_at"]) : null,
"watchersCount" => isset($map["watchers_count"]) && is_int($map["watchers_count"]) ? $map["watchers_count"] : 0,
"website" => isset($map["website"]) && is_string($map["website"]) ? new Uri($map["website"]) : null,
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"clone_url" => fn(self $model) => $model->cloneUrl ? (string) $model->cloneUrl : null,
"created_at" => fn(self $model) => $model->createdAt ? $model->createdAt->format("c") : null,
"default_branch" => "defaultBranch",
"description",
"empty" => "isEmpty",
"fork" => "isFork",
"forks_count" => "forksCount",
"full_name" => "fullName",
"html_url" => fn(self $model) => $model->htmlUrl ? (string) $model->htmlUrl : null,
"id",
"mirror" => "isMirror",
"name",
"open_issues_count" => "openIssuesCount",
"owner",
"parent",
"permissions",
"private" => "isPrivate",
"size",
"ssh_url" => fn(self $model) => $model->sshUrl ? (string) $model->sshUrl : null,
"stars_count" => "starsCount",
"updated_at" => fn(self $model) => $model->updatedAt ? $model->updatedAt->format("c") : null,
"watchers_count" => "watchersCount",
"website" => fn(self $model) => $model->website ? (string) $model->website : null
];
}
/**
* Gets the repository name.
* @return string The repository name.
*/
function getName(): string {
if (mb_strlen($this->name)) return $this->name;
return mb_strlen($this->fullName) ? explode("/", $this->fullName)[1] : "";
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["defaultBranch", "description", "fullName", "name"], "trim"],
[["isEmpty", "isFork", "isMirror", "isPrivate"], "boolean", "falseValue" => false, "trueValue" => true],
[["forksCount", "id", "openIssuesCount", "size", "starsCount", "watchersCount"], "integer", "min" => 0]
];
}
/**
* 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;
}
}

+ 22
- 22
src/models/ServerVersion.php View File

@@ -6,28 +6,28 @@ use yii\base\{Model};
/** Wraps the version of the Gitea server.*/
class ServerVersion extends Model {

/** @var string The version number. */
public string $version = '';
/** @var string The version number. */
public string $version = "";

/**
* Creates a new server version from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a server version.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'version' => isset($map['version']) && is_string($map['version']) ? $map['version'] : ''
]);
}
/**
* Creates a new server version from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a server version.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"version" => isset($map["version"]) && is_string($map["version"]) ? $map["version"] : ""
]);
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
['version', 'trim'],
['version', 'required']
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
["version", "trim"],
["version", "required"]
];
}
}

+ 11
- 11
src/models/StatusState.php View File

@@ -5,20 +5,20 @@ use Enum\{EnumTrait};

/** Defines the state of a Gitea status.*/
final class StatusState {
use EnumTrait;
use EnumTrait;

/** @var string The status is an error. */
const error = 'error';
/** @var string The status is an error. */
const error = "error";

/** @var string The status is a failure. */
const failure = 'failure';
/** @var string The status is a failure. */
const failure = "failure";

/** @var string The status is pending. */
const pending = 'pending';
/** @var string The status is pending. */
const pending = "pending";

/** @var string The status is a success. */
const success = 'success';
/** @var string The status is a success. */
const success = "success";

/** @var string The status is a warning. */
const warning = 'warning';
/** @var string The status is a warning. */
const warning = "warning";
}

+ 37
- 37
src/models/Team.php View File

@@ -6,41 +6,41 @@ use yii\base\{Model};
/** Represents a team in an organization. */
class Team extends Model {

/** @var string The team description. */
public string $description = '';
/** @var int The team identifier. */
public int $id = -1;
/** @var string The team name. */
public string $name = '';
/** @var string The team permission. */
public string $permission = TeamPermission::none;
/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'description' => isset($map['description']) && is_string($map['description']) ? $map['description'] : '',
'id' => isset($map['id']) && is_int($map['id']) ? $map['id'] : -1,
'name' => isset($map['name']) && is_string($map['name']) ? $map['name'] : '',
'permission' => TeamPermission::coerce($map['permission'] ?? TeamPermission::none, TeamPermission::none)
]);
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['description', 'name', 'permission'], 'trim'],
['id', 'integer', 'min' => 0],
['permission', 'in', 'range' => TeamPermission::getValues()]
];
}
/** @var string The team description. */
public string $description = "";
/** @var int The team identifier. */
public int $id = -1;
/** @var string The team name. */
public string $name = "";
/** @var string The team permission. */
public string $permission = TeamPermission::none;
/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"description" => isset($map["description"]) && is_string($map["description"]) ? $map["description"] : "",
"id" => isset($map["id"]) && is_int($map["id"]) ? $map["id"] : -1,
"name" => isset($map["name"]) && is_string($map["name"]) ? $map["name"] : "",
"permission" => TeamPermission::coerce($map["permission"] ?? TeamPermission::none, TeamPermission::none)
]);
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["description", "name", "permission"], "trim"],
["id", "integer", "min" => 0],
["permission", "in", "range" => TeamPermission::getValues()]
];
}
}

+ 11
- 11
src/models/TeamPermission.php View File

@@ -5,20 +5,20 @@ use Enum\{EnumTrait};

/** Defines the permission of a team. */
final class TeamPermission {
use EnumTrait;
use EnumTrait;

/** @var string The team has the administrator permission. */
const admin = 'admin';
/** @var string The team has the administrator permission. */
const admin = "admin";

/** @var string The team doesn't have any permission. */
const none = 'none';
/** @var string The team doesn't have any permission. */
const none = "none";

/** @var string The team has the owner permission. */
const owner = 'owner';
/** @var string The team has the owner permission. */
const owner = "owner";

/** @var string The team has the read permission. */
const read = 'read';
/** @var string The team has the read permission. */
const read = "read";

/** @var string The team has the write permission. */
const write = 'write';
/** @var string The team has the write permission. */
const write = "write";
}

+ 53
- 53
src/models/TrackedTime.php View File

@@ -6,57 +6,57 @@ use yii\base\{Model};
/** Represents the worked time for an issue or pull request. */
class TrackedTime extends Model {

/** @var \DateTimeInterface|null The date the entry was created. */
public ?\DateTimeInterface $createdAt = null;
/** @var int The entry identifier. */
public int $id = -1;
/** @var int The identifier of the associated issue or pull request. */
public int $issueId = -1;
/** @var int The elapsed time, in seconds. */
public int $time = 0;
/** @var int The identifier of the initiating user. */
public int $userId = -1;
/**
* Creates a new entry from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing an entry.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'createdAt' => isset($map['created']) && is_string($map['created']) ? new \DateTimeImmutable($map['created']) : null,
'id' => isset($map['id']) && is_int($map['id']) ? $map['id'] : -1,
'issueId' => isset($map['issue_id']) && is_int($map['issue_id']) ? $map['issue_id'] : -1,
'time' => isset($map['time']) && is_int($map['time']) ? $map['time'] : 0,
'userId' => isset($map['user_id']) && is_int($map['user_id']) ? $map['user_id'] : -1
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'created' => fn(self $model) => $model->createdAt ? $model->createdAt->format('c') : null,
'id',
'issue_id' => 'issueId',
'time',
'user_id' => 'userId'
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['id', 'issueId', 'time', 'userId'], 'integer', 'min' => 0]
];
}
/** @var \DateTimeInterface|null The date the entry was created. */
public ?\DateTimeInterface $createdAt = null;
/** @var int The entry identifier. */
public int $id = -1;
/** @var int The identifier of the associated issue or pull request. */
public int $issueId = -1;
/** @var int The elapsed time, in seconds. */
public int $time = 0;
/** @var int The identifier of the initiating user. */
public int $userId = -1;
/**
* Creates a new entry from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing an entry.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"createdAt" => isset($map["created"]) && is_string($map["created"]) ? new \DateTimeImmutable($map["created"]) : null,
"id" => isset($map["id"]) && is_int($map["id"]) ? $map["id"] : -1,
"issueId" => isset($map["issue_id"]) && is_int($map["issue_id"]) ? $map["issue_id"] : -1,
"time" => isset($map["time"]) && is_int($map["time"]) ? $map["time"] : 0,
"userId" => isset($map["user_id"]) && is_int($map["user_id"]) ? $map["user_id"] : -1
]);
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"created" => fn(self $model) => $model->createdAt ? $model->createdAt->format("c") : null,
"id",
"issue_id" => "issueId",
"time",
"user_id" => "userId"
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["id", "issueId", "time", "userId"], "integer", "min" => 0]
];
}
}

+ 53
- 53
src/models/User.php View File

@@ -8,65 +8,65 @@ use yii\base\{Model};
/** Represents a Gitea user. */
class User extends Model {

/** @var UriInterface|null The URL to the user's avatar. */
public ?UriInterface $avatarUrl = null;
/** @var UriInterface|null The URL to the user's avatar. */
public ?UriInterface $avatarUrl = null;

/** @var string The mail address. */
public string $email = '';
/** @var string The mail address. */
public string $email = "";

/** @var string The full name. */
public string $fullName = '';
/** @var string The full name. */
public string $fullName = "";

/** @var int The user identifier. */
public int $id = -1;
/** @var int The user identifier. */
public int $id = -1;

/** @var string The user locale. */
public string $language = '';
/** @var string The user locale. */
public string $language = "";

/** @var string The name of the Gitea account. */
public string $login = '';
/** @var string The name of the Gitea account. */
public string $login = "";

/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'avatarUrl' => isset($map['avatar_url']) && is_string($map['avatar_url']) ? new Uri($map['avatar_url']) : null,
'email' => isset($map['email']) && is_string($map['email']) ? mb_strtolower($map['email']) : '',
'fullName' => isset($map['full_name']) && is_string($map['full_name']) ? $map['full_name'] : '',
'id' => isset($map['id']) && is_int($map['id']) ? $map['id'] : -1,
'language' => isset($map['language']) && is_string($map['language']) ? $map['language'] : '',
'login' => isset($map['login']) && is_string($map['login']) ? $map['login'] : ''
]);
}
/**
* Creates a new user from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing a user.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"avatarUrl" => isset($map["avatar_url"]) && is_string($map["avatar_url"]) ? new Uri($map["avatar_url"]) : null,
"email" => isset($map["email"]) && is_string($map["email"]) ? mb_strtolower($map["email"]) : "",
"fullName" => isset($map["full_name"]) && is_string($map["full_name"]) ? $map["full_name"] : "",
"id" => isset($map["id"]) && is_int($map["id"]) ? $map["id"] : -1,
"language" => isset($map["language"]) && is_string($map["language"]) ? $map["language"] : "",
"login" => isset($map["login"]) && is_string($map["login"]) ? $map["login"] : ""
]);
}

/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'avatar_url' => fn(self $model) => $model->avatarUrl ? (string) $model->avatarUrl : null,
'email',
'full_name' => 'fullName',
'id',
'language',
'login'
];
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"avatar_url" => fn(self $model) => $model->avatarUrl ? (string) $model->avatarUrl : null,
"email",
"full_name" => "fullName",
"id",
"language",
"login"
];
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['email', 'fullName', 'language', 'login'], 'trim'],
['email', 'filter', 'filter' => 'mb_strtolower'],
['email', 'email'],
['id', 'integer', 'min' => 0]
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[["email", "fullName", "language", "login"], "trim"],
["email", "filter", "filter" => "mb_strtolower"],
["email", "email"],
["id", "integer", "min" => 0]
];
}
}

+ 34
- 34
src/models/UserHeatmapData.php View File

@@ -6,42 +6,42 @@ use yii\base\{Model};
/** Represents the data needed to create a user heatmap. */
class UserHeatmapData extends Model {

/** @var int The contribution number. */
public int $contributions = 0;
/** @var int The contribution number. */
public int $contributions = 0;

/** @var \DateTimeInterface|null The contributions date. */
public ?\DateTimeInterface $timestamp = null;
/** @var \DateTimeInterface|null The contributions date. */
public ?\DateTimeInterface $timestamp = null;

/**
* Creates new heatmap data from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing heatmap data.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
'contributions' => isset($map['contributions']) && is_int($map['contributions']) ? max(0, $map['contributions']) : 0,
'timestamp' => isset($map['timestamp']) && is_int($map['timestamp']) ? new \DateTimeImmutable("@{$map['timestamp']}") : null,
]);
}
/**
* Creates new heatmap data from the specified JSON map.
* @param array<string, mixed> $map A JSON map representing heatmap data.
* @return self The instance corresponding to the specified JSON map.
*/
static function fromJson(array $map): self {
return new self([
"contributions" => isset($map["contributions"]) && is_int($map["contributions"]) ? max(0, $map["contributions"]) : 0,
"timestamp" => isset($map["timestamp"]) && is_int($map["timestamp"]) ? new \DateTimeImmutable("@{$map['timestamp']}") : null,
]);
}

/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
'contributions',
'timestamp' => fn(self $model) => $model->timestamp ? $model->timestamp->format('c') : null
];
}
/**
* Returns the list of fields that should be returned by default.
* @return mixed[] The list of field names or field definitions.
*/
function fields(): array {
return [
"contributions",
"timestamp" => fn(self $model) => $model->timestamp ? $model->timestamp->format("c") : null
];
}

/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
['contributions', 'integer', 'min' => 0]
];
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
["contributions", "integer", "min" => 0]
];
}
}

+ 5
- 5
test/index.php View File

@@ -2,15 +2,15 @@
use yii\console\{Application};

// Set the environment.
define('YII_DEBUG', true);
define('YII_ENV', 'test');
define("YII_DEBUG", true);
define("YII_ENV", "test");

// Load the class library.
$rootPath = (new SplFileInfo(__DIR__))->getPath();
require_once "$rootPath/vendor/autoload.php";
require_once "$rootPath/vendor/yiisoft/yii2/Yii.php";
Yii::setAlias('@root', $rootPath);
Yii::setAlias('@yii/gitea', "$rootPath/src");
Yii::setAlias("@root", $rootPath);
Yii::setAlias("@yii/gitea", "$rootPath/src");

// Start the application.
new Application(['id' => 'yii2-gitea', 'basePath' => '@root/src']);
new Application(["id" => "yii2-gitea", "basePath" => "@root/src"]);

+ 3
- 3
tool/clean.ps1 View File

@@ -2,10 +2,10 @@
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

foreach ($item in 'build', 'doc/api', 'www') {
if (Test-Path $item) { Remove-Item $item -Recurse }
foreach ($item in "build", "doc/api", "www") {
if (Test-Path $item) { Remove-Item $item -Recurse }
}

foreach ($item in Get-ChildItem var -Exclude .gitkeep) {
Remove-Item $item -Recurse
Remove-Item $item -Recurse
}

+ 1
- 1
tool/doc.ps1 View File

@@ -2,7 +2,7 @@
Set-StrictMode -Version Latest
Set-Location (Split-Path $PSScriptRoot)

$phpdoc = $IsWindows ? 'php "C:/Program Files/PHP/share/phpDocumentor.phar"' : 'phpdoc';
$phpdoc = $IsWindows ? 'php "C:/Program Files/PHP/share/phpDocumentor.phar"' : "phpdoc";
Invoke-Expression "$phpdoc --config=etc/phpdoc.xml"

if (-not (Test-Path doc/api/images)) { New-Item doc/api/images -ItemType Directory | Out-Null }


+ 1
- 1
tool/upgrade.ps1 View File

@@ -6,5 +6,5 @@ git reset --hard
git fetch --all --prune
git pull --rebase

$composer = $IsWindows ? 'php "C:/Program Files/PHP/share/composer.phar"' : 'composer'
$composer = $IsWindows ? 'php "C:/Program Files/PHP/share/composer.phar"' : "composer"
Invoke-Expression "$composer update --no-interaction"

Loading…
Cancel
Save