From 13fa36768517d7f6691bc8956029410bc1baecd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Viguier?= Date: Fri, 5 Jul 2024 15:21:35 +0200 Subject: [PATCH] Simplify (#2493) --- app/Models/Album.php | 8 ----- app/Models/BaseAlbumImpl.php | 8 ----- .../ToArrayThrowsNotImplemented.php | 5 --- app/Models/Photo.php | 8 ----- app/Models/SizeVariant.php | 8 ----- app/Models/SymLink.php | 10 ++---- app/Models/TagAlbum.php | 11 ------ app/Models/User.php | 8 ----- app/SmartAlbums/BaseSmartAlbum.php | 34 ------------------- 9 files changed, 2 insertions(+), 98 deletions(-) diff --git a/app/Models/Album.php b/app/Models/Album.php index c3a0992f779..6d29c8670fa 100644 --- a/app/Models/Album.php +++ b/app/Models/Album.php @@ -175,14 +175,6 @@ class Album extends BaseAlbum implements Node */ protected $with = ['cover', 'cover.size_variants', 'thumb']; - /** - * @return array - */ - protected function _toArray(): array - { - return parent::toArray(); - } - /** * Return the relationship between this album and photos which are * direct children of this album. diff --git a/app/Models/BaseAlbumImpl.php b/app/Models/BaseAlbumImpl.php index 723943de2ea..5b9bbd5a0e4 100644 --- a/app/Models/BaseAlbumImpl.php +++ b/app/Models/BaseAlbumImpl.php @@ -197,14 +197,6 @@ class BaseAlbumImpl extends Model implements HasRandomID */ protected $with = ['owner', 'access_permissions']; - /** - * @return array - */ - protected function _toArray(): array - { - return parent::toArray(); - } - /** * @param $query * diff --git a/app/Models/Extensions/ToArrayThrowsNotImplemented.php b/app/Models/Extensions/ToArrayThrowsNotImplemented.php index 30327e87163..2407016be89 100644 --- a/app/Models/Extensions/ToArrayThrowsNotImplemented.php +++ b/app/Models/Extensions/ToArrayThrowsNotImplemented.php @@ -16,11 +16,6 @@ */ trait ToArrayThrowsNotImplemented { - /** - * @return array - */ - abstract protected function _toArray(): array; - /** * @return array * diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 0b9b2729289..51975d2fc38 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -180,14 +180,6 @@ public function newEloquentBuilder($query): PhotoBuilder return new PhotoBuilder($query); } - /** - * @return array - */ - protected function _toArray(): array - { - return parent::toArray(); - } - /** * Return the relationship between a Photo and its Album. * diff --git a/app/Models/SizeVariant.php b/app/Models/SizeVariant.php index d8782d8a03f..34bc4092da2 100644 --- a/app/Models/SizeVariant.php +++ b/app/Models/SizeVariant.php @@ -136,14 +136,6 @@ public function newEloquentBuilder($query): SizeVariantBuilder return new SizeVariantBuilder($query); } - /** - * @return array - */ - protected function _toArray(): array - { - return parent::toArray(); - } - /** * Returns the association to the photo which this size variant belongs * to. diff --git a/app/Models/SymLink.php b/app/Models/SymLink.php index efc22e5a704..b40a615530d 100644 --- a/app/Models/SymLink.php +++ b/app/Models/SymLink.php @@ -79,14 +79,6 @@ class SymLink extends Model 'size_variant_id', // see above ]; - /** - * @return array - */ - final protected function _toArray(): array - { - return parent::toArray(); - } - /** * @param $query * @@ -136,6 +128,7 @@ public function scopeExpired(Builder $query): Builder protected function getUrlAttribute(): string { try { + /** @disregard P1013 */ return Storage::disk(self::DISK_NAME)->url($this->short_path); } catch (\RuntimeException $e) { throw new FrameworkException('Laravel\'s storage component', $e); @@ -161,6 +154,7 @@ protected function performInsert(Builder $query): bool $origRealPath = $file->getRealPath(); $extension = $file->getExtension(); $symShortPath = hash('sha256', random_bytes(32) . '|' . $origRealPath) . $extension; + /** @disregard P1013 */ $symAbsolutePath = Storage::disk(SymLink::DISK_NAME)->path($symShortPath); try { if (is_link($symAbsolutePath)) { diff --git a/app/Models/TagAlbum.php b/app/Models/TagAlbum.php index 0499f002750..dc7568a4bca 100644 --- a/app/Models/TagAlbum.php +++ b/app/Models/TagAlbum.php @@ -92,17 +92,6 @@ class TagAlbum extends BaseAlbum 'thumb', ]; - /** - * @return array - */ - protected function _toArray(): array - { - $result = parent::toArray(); - $result['is_tag_album'] = true; - - return $result; - } - public function photos(): HasManyPhotosByTag { return new HasManyPhotosByTag($this); diff --git a/app/Models/User.php b/app/Models/User.php index 734c5a7159c..d291b264980 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -108,14 +108,6 @@ class User extends Authenticatable implements WebAuthnAuthenticatable protected $hidden = []; - /** - * @return array - */ - protected function _toArray(): array - { - return parent::toArray(); - } - /** * Create a new Eloquent query builder for the model. * diff --git a/app/SmartAlbums/BaseSmartAlbum.php b/app/SmartAlbums/BaseSmartAlbum.php index d5af21b0184..7712ec0a007 100644 --- a/app/SmartAlbums/BaseSmartAlbum.php +++ b/app/SmartAlbums/BaseSmartAlbum.php @@ -4,7 +4,6 @@ use App\Contracts\Exceptions\InternalLycheeException; use App\Contracts\Models\AbstractAlbum; -use App\DTO\AlbumProtectionPolicy; use App\DTO\PhotoSortingCriterion; use App\Enum\SmartAlbumType; use App\Exceptions\ConfigurationKeyMissingException; @@ -68,39 +67,6 @@ protected function __construct(SmartAlbumType $id, \Closure $smartCondition) } } - /** - * @return array{id:string,title:string,thumb:?Thumb,policy:AlbumProtectionPolicy,photos:?array} - */ - protected function _toArray(): array - { - // The properties `thumb` and `photos` are intentionally treated - // differently. - // - // 1. The result always includes `thumb`, hence we call the - // getter method to ensure that the property is initialized, if it - // has not already been accessed before. - // 2. The result only includes the collection `photos`, if it has - // already explicitly been accessed earlier and thus is initialized. - // - // Rationale: - // - // 1. This resembles the behaviour of a real Eloquent model, if the - // attribute `thumb` was part of the `append`-property of model. - // 2. This resembles the behaviour of a real Eloquent model for - // one-to-many relations. - // A relation is only included in the array representation, if the - // relation has been loaded. - // This avoids unnecessary hydration of photos if the album is - // only used within a listing of sub-albums. - return [ - 'id' => $this->id, - 'title' => $this->title, - 'thumb' => $this->getThumbAttribute(), - 'policy' => AlbumProtectionPolicy::ofSmartAlbum($this), - 'photos' => $this->photos?->toArray(), - ]; - } - /** * @return \App\Eloquent\FixedQueryBuilder *