Add type hints from DocBlocks
This commit is contained in:
@@ -24,7 +24,7 @@ class Analytics extends Model
|
||||
* @param array $attributes Model attributes.
|
||||
* @return static
|
||||
*/
|
||||
public static function createWithSession(array $attributes)
|
||||
public static function createWithSession(array $attributes): static
|
||||
{
|
||||
$previousRow = self::where('useragent', $attributes['useragent'])
|
||||
->where('ip', $attributes['ip'])
|
||||
|
||||
@@ -32,7 +32,7 @@ class Article extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class Article extends Model
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments()
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(\App\Models\Attachment::class, 'attachable');
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class Attachment extends Model
|
||||
*
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function attachable()
|
||||
public function attachable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class Attachment extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function media()
|
||||
public function media(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Media::class);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Event extends Model
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function attachments()
|
||||
public function attachments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(\App\Models\Attachment::class, 'attachable');
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class Event extends Model
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function users()
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'event_user', 'event_id', 'user_id');
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class EventUser extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function event()
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class EventUser extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class Media extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
@@ -136,7 +136,7 @@ class Media extends Model
|
||||
* @param string $type The variant type to get.
|
||||
* @return array The variant data.
|
||||
*/
|
||||
public static function getTypeVariants(string $type)
|
||||
public static function getTypeVariants(string $type): array
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === true) {
|
||||
return self::$variantTypes[$type];
|
||||
@@ -151,7 +151,7 @@ class Media extends Model
|
||||
* @param mixed $value The value to mutate.
|
||||
* @return array The mutated value.
|
||||
*/
|
||||
public function getVariantsAttribute(mixed $value)
|
||||
public function getVariantsAttribute(mixed $value): array
|
||||
{
|
||||
if (is_string($value) === true) {
|
||||
return json_decode($value, true);
|
||||
@@ -166,7 +166,7 @@ class Media extends Model
|
||||
* @param mixed $value The value to mutate.
|
||||
* @return void
|
||||
*/
|
||||
public function setVariantsAttribute(mixed $value)
|
||||
public function setVariantsAttribute(mixed $value): void
|
||||
{
|
||||
if (is_array($value) !== true) {
|
||||
$value = [];
|
||||
@@ -182,7 +182,7 @@ class Media extends Model
|
||||
* @param string $variant The initial variant.
|
||||
* @return string The previous variant name (or '').
|
||||
*/
|
||||
public function getPreviousVariant(string $type, string $variant)
|
||||
public function getPreviousVariant(string $type, string $variant): string
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === false) {
|
||||
return '';
|
||||
@@ -206,7 +206,7 @@ class Media extends Model
|
||||
* @param string $variant The initial variant.
|
||||
* @return string The next variant name (or '').
|
||||
*/
|
||||
public function getNextVariant(string $type, string $variant)
|
||||
public function getNextVariant(string $type, string $variant): string
|
||||
{
|
||||
if (isset(self::$variantTypes[$type]) === false) {
|
||||
return '';
|
||||
@@ -230,7 +230,7 @@ class Media extends Model
|
||||
* @param boolean $returnNearest Return the nearest variant if request is not found.
|
||||
* @return string The URL.
|
||||
*/
|
||||
public function getVariantURL(string $variant, bool $returnNearest = true)
|
||||
public function getVariantURL(string $variant, bool $returnNearest = true): string
|
||||
{
|
||||
$variants = $this->variants;
|
||||
if (isset($variants[$variant]) === true) {
|
||||
@@ -259,7 +259,7 @@ class Media extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteFile()
|
||||
public function deleteFile(): void
|
||||
{
|
||||
$fileName = $this->name;
|
||||
$baseName = pathinfo($fileName, PATHINFO_FILENAME);
|
||||
@@ -282,7 +282,7 @@ class Media extends Model
|
||||
* @return void
|
||||
* @throws InvalidArgumentException Exception.
|
||||
*/
|
||||
private function invalidateCFCache()
|
||||
private function invalidateCFCache(): void
|
||||
{
|
||||
$zone_id = env("CLOUDFLARE_ZONE_ID");
|
||||
$api_key = env("CLOUDFLARE_API_KEY");
|
||||
@@ -314,7 +314,7 @@ class Media extends Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlPath()
|
||||
public function getUrlPath(): string
|
||||
{
|
||||
$url = config("filesystems.disks.$this->storage.url");
|
||||
return "$url/";
|
||||
@@ -325,7 +325,7 @@ class Media extends Model
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlAttribute()
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
if (isset($this->attributes['name']) === true) {
|
||||
return self::getUrlPath() . $this->name;
|
||||
@@ -339,7 +339,7 @@ class Media extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
@@ -350,7 +350,7 @@ class Media extends Model
|
||||
* @param string $storage The storage ID to move to.
|
||||
* @return void
|
||||
*/
|
||||
public function moveToStorage(string $storage)
|
||||
public function moveToStorage(string $storage): void
|
||||
{
|
||||
if ($storage !== $this->storage && Config::has("filesystems.disks.$storage") === true) {
|
||||
$this->status = "Processing media";
|
||||
@@ -366,7 +366,7 @@ class Media extends Model
|
||||
* @param Illuminate\Http\UploadedFile $file The file.
|
||||
* @return null|Media The result or null if not successful.
|
||||
*/
|
||||
public static function createFromUploadedFile(Request $request, UploadedFile $file)
|
||||
public static function createFromUploadedFile(Request $request, UploadedFile $file): ?Media
|
||||
{
|
||||
$request->merge([
|
||||
'title' => $request->get('title', ''),
|
||||
@@ -401,7 +401,7 @@ class Media extends Model
|
||||
* @param Illuminate\Http\UploadedFile $file The file.
|
||||
* @return null|Media The media item.
|
||||
*/
|
||||
public function updateWithUploadedFile(UploadedFile $file)
|
||||
public function updateWithUploadedFile(UploadedFile $file): ?Media
|
||||
{
|
||||
if ($file === null || $file->isValid() !== true) {
|
||||
throw new \Exception('The file is invalid.', self::INVALID_FILE_ERROR);
|
||||
@@ -497,7 +497,7 @@ class Media extends Model
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getMaxUploadSize()
|
||||
public static function getMaxUploadSize(): int
|
||||
{
|
||||
$sizes = [
|
||||
ini_get('upload_max_filesize'),
|
||||
@@ -561,7 +561,7 @@ class Media extends Model
|
||||
* @param boolean $ignoreCache Ignore the file list cache.
|
||||
* @return boolean If the file exists on any storage disks.
|
||||
*/
|
||||
public static function fileExistsInStorage(string $fileName, bool $ignoreCache = false)
|
||||
public static function fileExistsInStorage(string $fileName, bool $ignoreCache = false): bool
|
||||
{
|
||||
$disks = array_keys(Config::get('filesystems.disks'));
|
||||
|
||||
@@ -608,7 +608,7 @@ class Media extends Model
|
||||
* @param string $fileName The file name to test.
|
||||
* @return boolean If the file name contains the special suffix.
|
||||
*/
|
||||
public static function fileNameHasSuffix(string $fileName)
|
||||
public static function fileNameHasSuffix(string $fileName): bool
|
||||
{
|
||||
$suffix = '/(-\d+x\d+|-scaled)$/i';
|
||||
$fileNameWithoutExtension = pathinfo($fileName, PATHINFO_FILENAME);
|
||||
@@ -622,7 +622,7 @@ class Media extends Model
|
||||
* @param string $fileName Filename to sanitize.
|
||||
* @return string
|
||||
*/
|
||||
private static function sanitizeFilename(string $fileName)
|
||||
private static function sanitizeFilename(string $fileName): string
|
||||
{
|
||||
/*
|
||||
# file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
|
||||
@@ -27,7 +27,7 @@ class Permission extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function permissions()
|
||||
public function permissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Permission::class);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissionsAttribute()
|
||||
public function getPermissionsAttribute(): array
|
||||
{
|
||||
return $this->permissions()->pluck('permission')->toArray();
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string $permission Permission to test.
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasPermission(string $permission)
|
||||
public function hasPermission(string $permission): bool
|
||||
{
|
||||
return ($this->permissions()->where('permission', $permission)->first() !== null);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string|array $permissions The permission(s) to give.
|
||||
* @return Collection
|
||||
*/
|
||||
public function givePermission($permissions)
|
||||
public function givePermission($permissions): Collection
|
||||
{
|
||||
if (is_array($permissions) === false) {
|
||||
$permissions = [$permissions];
|
||||
@@ -139,7 +139,7 @@ class User extends Authenticatable implements Auditable
|
||||
* @param string|array $permissions The permission(s) to revoke.
|
||||
* @return integer
|
||||
*/
|
||||
public function revokePermission($permissions)
|
||||
public function revokePermission($permissions): int
|
||||
{
|
||||
if (is_array($permissions) === false) {
|
||||
$permissions = [$permissions];
|
||||
@@ -155,7 +155,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function media()
|
||||
public function media(): HasMany
|
||||
{
|
||||
return $this->hasMany(Media::class);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function articles()
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function codes()
|
||||
public function codes(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserCode::class);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function logins()
|
||||
public function logins(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserLogins::class);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ class User extends Authenticatable implements Auditable
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function events()
|
||||
public function events(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Event::class, 'event_user', 'user_id', 'event_id');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
@@ -49,7 +49,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function regenerate()
|
||||
public function regenerate(): void
|
||||
{
|
||||
while (true) {
|
||||
$code = random_int(100000, 999999);
|
||||
@@ -65,7 +65,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearExpired()
|
||||
public static function clearExpired(): void
|
||||
{
|
||||
UserCode::where('updated_at', '<=', now()->subDays(5))->delete();
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class UserCode extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class UserLogins extends Model
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user