From 00eaa15cf2dc67e7c860c23f779d44a58be0867c Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 19 Apr 2020 19:36:39 +0800 Subject: [PATCH] add PHPDoc --- app/Models/Player.php | 13 +++++ app/Models/Report.php | 12 +++++ app/Models/Texture.php | 16 ++++++ app/Models/User.php | 19 +++++++- app/Services/Facades/Option.php | 7 +-- app/Services/OptionForm.php | 86 ++++++++++----------------------- 6 files changed, 86 insertions(+), 67 deletions(-) diff --git a/app/Models/Player.php b/app/Models/Player.php index 2d43270e..7c262a6c 100644 --- a/app/Models/Player.php +++ b/app/Models/Player.php @@ -6,7 +6,20 @@ use App\Events\PlayerProfileUpdated; use App\Models; use DateTimeInterface; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; +/** + * @property int $pid + * @property int $uid + * @property string $name + * @property int $tid_skin + * @property int $tid_cape + * @property Carbon $last_modified + * @property User $user + * @property Texture $skin + * @property Texture $cape + * @property string $model + */ class Player extends Model { public const CREATED_AT = null; diff --git a/app/Models/Report.php b/app/Models/Report.php index 193a7274..29769455 100644 --- a/app/Models/Report.php +++ b/app/Models/Report.php @@ -4,7 +4,19 @@ namespace App\Models; use DateTimeInterface; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; +/** + * @property int $id + * @property int $tid + * @property int $uploader + * @property int $reporter + * @property string $reason + * @property int $status + * @property Carbon $report_at + * @property Texture $texture + * @property User $informer The reporter. + */ class Report extends Model { public const CREATED_AT = 'report_at'; diff --git a/app/Models/Texture.php b/app/Models/Texture.php index 6cc86c8f..7d8322d6 100644 --- a/app/Models/Texture.php +++ b/app/Models/Texture.php @@ -3,8 +3,24 @@ namespace App\Models; use DateTimeInterface; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; +/** + * @property int $tid + * @property string $name + * @property string $type + * @property string $hash + * @property int $size + * @property int $uploader + * @property bool $public + * @property Carbon $upload_at + * @property int $likes + * @property string $model + * @property User $owner + * @property Collection $likers + */ class Texture extends Model { public $primaryKey = 'tid'; diff --git a/app/Models/User.php b/app/Models/User.php index 3efb24c2..b759bd03 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,11 +4,28 @@ namespace App\Models; use App\Models\Concerns\HasPassword; use DateTimeInterface; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Passport\HasApiTokens; use Tymon\JWTAuth\Contracts\JWTSubject; +/** + * @property int $uid + * @property string $email + * @property string $password + * @property string $nickname + * @property int $avatar + * @property int $score + * @property int $permission + * @property string $ip + * @property string $last_sign_at + * @property string $register_at + * @property bool $verified + * @property string $player_name + * @property Collection $players + * @property Collection $closet + */ class User extends Authenticatable implements JWTSubject { use Notifiable; @@ -69,7 +86,7 @@ class User extends Authenticatable implements JWTSubject public function players() { - return $this->hasMany('App\Models\Player', 'uid'); + return $this->hasMany(Player::class, 'uid'); } public function getAuthIdentifier() diff --git a/app/Services/Facades/Option.php b/app/Services/Facades/Option.php index 43f9a8e7..c2a73a31 100644 --- a/app/Services/Facades/Option.php +++ b/app/Services/Facades/Option.php @@ -7,17 +7,12 @@ use Illuminate\Support\Facades\Facade; class Option extends Facade { - /** - * Get the registered name of the component. - * - * @return string - */ protected static function getFacadeAccessor() { return 'options'; } - public static function form($id, $title, $callback) + public static function form(string $id, string $title, $callback): OptionForm { $form = new OptionForm($id, $title); diff --git a/app/Services/OptionForm.php b/app/Services/OptionForm.php index 962cfce4..6e4a43e8 100644 --- a/app/Services/OptionForm.php +++ b/app/Services/OptionForm.php @@ -8,6 +8,13 @@ use Illuminate\Support\Str; use Option; use ReflectionClass; +/** + * @method OptionFormText text(string $id, string|null $name) + * @method OptionFormCheckbox checkbox(string $id, string|null $name) + * @method OptionFormTextarea textarea(string $id, string|null $name) + * @method OptionFormSelect select(string $id, string|null $name) + * @method OptionFormGroup group(string $id, string|null $name) + */ class OptionForm { /** @@ -39,13 +46,8 @@ class OptionForm /** * Create a new option form instance. - * - * @param string $id - * @param string $title - * - * @return void */ - public function __construct($id, $title = self::AUTO_DETECT) + public function __construct(string $id, string $title = self::AUTO_DETECT) { $this->id = $id; @@ -88,12 +90,8 @@ class OptionForm /** * Set the box type of option form. - * - * @param string $type - * - * @return $this */ - public function type($type) + public function type(string $type): self { $this->type = $type; @@ -104,10 +102,8 @@ class OptionForm * Add a hint to option form. * * @param array $info - * - * @return $this */ - public function hint($hintContent = self::AUTO_DETECT) + public function hint($hintContent = self::AUTO_DETECT): self { if ($hintContent == self::AUTO_DETECT) { $hintContent = trans("options.$this->id.hint"); @@ -123,10 +119,8 @@ class OptionForm * * @param string|array $key * @param mixed $value - * - * @return $this */ - public function with($key, $value = null) + public function with($key, $value = null): self { if (is_array($key)) { $this->values = array_merge($this->values, $key); @@ -139,10 +133,8 @@ class OptionForm /** * Add a button at the footer of option form. - * - * @return $this */ - public function addButton(array $info) + public function addButton(array $info): self { $info = array_merge([ 'style' => 'default', @@ -166,11 +158,8 @@ class OptionForm * Add a message to the top of option form. * * @param string $msg - * @param string $style - * - * @return $this */ - public function addMessage($msg = self::AUTO_DETECT, $style = 'info') + public function addMessage($msg = self::AUTO_DETECT, string $style = 'info'): self { if ($msg == self::AUTO_DETECT) { $msg = trans("options.$this->id.message"); @@ -185,11 +174,8 @@ class OptionForm * Add an alert to the top of option form. * * @param string $msg - * @param string $style - * - * @return $this */ - public function addAlert($msg = self::AUTO_DETECT, $style = 'info') + public function addAlert($msg = self::AUTO_DETECT, string $style = 'info'): self { if ($msg == self::AUTO_DETECT) { $msg = trans("options.$this->id.alert"); @@ -202,10 +188,8 @@ class OptionForm /** * Add callback which will be executed before handling options. - * - * @return $this */ - public function before(callable $callback) + public function before(callable $callback): self { $this->hookBefore = $callback; @@ -214,10 +198,8 @@ class OptionForm /** * Add callback which will be executed after handling options. - * - * @return $this */ - public function after(callable $callback) + public function after(callable $callback): self { $this->hookAfter = $callback; @@ -226,10 +208,8 @@ class OptionForm /** * Add callback which will be always executed. - * - * @return $this */ - public function always(callable $callback) + public function always(callable $callback): self { $this->alwaysCallback = $callback; @@ -238,12 +218,8 @@ class OptionForm /** * Handle the HTTP post request and update modified options. - * - * @param callable $callback - * - * @return $this */ - public function handle(callable $callback = null) + public function handle(callable $callback = null): self { $request = request(); $allPostData = $request->all(); @@ -297,22 +273,16 @@ class OptionForm /** * Load value from $this->values & options by given id. - * - * @param string $id - * - * @return mixed */ - protected function getValueById($id) + protected function getValueById(string $id) { return Arr::get($this->values, $id, option_localized($id)); } /** * Assign value for option items whose value haven't been set. - * - * @return void */ - protected function assignValues() + protected function assignValues(): void { // Load values for items if not set manually foreach ($this->items as $item) { @@ -331,21 +301,21 @@ class OptionForm } } - public function renderWithoutTable() + public function renderWithoutTable(): self { $this->renderWithoutTable = true; return $this; } - public function renderInputTagsOnly() + public function renderInputTagsOnly(): self { $this->renderInputTagsOnly = true; return $this; } - public function renderWithoutSubmitButton() + public function renderWithoutSubmitButton(): self { $this->renderWithoutSubmitButton = true; @@ -354,10 +324,8 @@ class OptionForm /** * Get the string contents of the option form. - * - * @return string */ - public function render() + public function render(): string { if (!is_null($this->alwaysCallback)) { call_user_func($this->alwaysCallback, $this); @@ -382,10 +350,8 @@ class OptionForm /** * Get the string contents of the option form. - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->render(); } @@ -409,7 +375,7 @@ class OptionFormItem protected $parentId; - public function __construct($id, $name = null) + public function __construct(string $id, $name = null) { $this->id = $id; $this->name = $name;