From b8c10d07d2ba741824a2093189ac376885e8ec48 Mon Sep 17 00:00:00 2001 From: Phan An Date: Wed, 24 Apr 2024 23:58:19 +0200 Subject: [PATCH] chore: remove unnecessary type hints --- app/Console/Commands/ScanCommand.php | 1 - .../Storage/SetupDropboxStorageCommand.php | 4 +--- .../Storage/SetupS3StorageCommand.php | 4 +--- .../API/FetchOverviewController.php | 1 - .../PlaylistCollaboratorController.php | 2 -- .../Controllers/API/PlaylistController.php | 3 --- .../API/RegisterPlayController.php | 1 - .../API/ToggleLikeSongController.php | 2 -- app/Http/Resources/PlaylistResource.php | 2 -- app/Providers/AuthServiceProvider.php | 5 +---- app/Repositories/AlbumRepository.php | 4 +++- app/Repositories/ArtistRepository.php | 4 ++-- app/Repositories/PlaylistFolderRepository.php | 5 +++++ app/Repositories/PlaylistRepository.php | 1 + app/Repositories/Repository.php | 21 +++++++++---------- app/Repositories/SettingRepository.php | 1 + app/Repositories/SongRepository.php | 19 ++--------------- app/Repositories/UserRepository.php | 3 +++ app/Services/AuthenticationService.php | 6 +----- app/Services/DownloadService.php | 3 --- app/Services/LicenseService.php | 1 - app/Services/PlaylistCollaborationService.php | 1 - app/Services/PlaylistService.php | 1 - app/Services/QueueService.php | 1 - app/Services/SongStorages/S3LambdaStorage.php | 5 +---- app/Services/UserInvitationService.php | 1 - ...16_04_16_082627_create_various_artists.php | 2 -- ...159_copy_artist_to_contributing_artist.php | 2 -- ...2024_01_03_104241_support_multi_tenant.php | 1 - phpstan.neon.dist | 1 + tests/Feature/AlbumCoverTest.php | 2 -- tests/Feature/AlbumInformationTest.php | 6 +----- tests/Feature/AlbumSongTest.php | 1 - tests/Feature/AlbumTest.php | 5 +---- tests/Feature/AlbumThumbnailTest.php | 1 - tests/Feature/ArtistAlbumTest.php | 1 - tests/Feature/ArtistImageTest.php | 1 - tests/Feature/ArtistInformationTest.php | 6 +----- tests/Feature/ArtistSongTest.php | 1 - tests/Feature/ArtistTest.php | 5 +---- tests/Feature/DownloadTest.php | 14 ++----------- tests/Feature/InteractionTest.php | 9 ++------ tests/Feature/LastfmTest.php | 2 -- tests/Feature/PlayCountTest.php | 4 ---- tests/Feature/PlaylistCoverTest.php | 2 -- tests/Feature/PlaylistFolderTest.php | 3 --- 46 files changed, 41 insertions(+), 130 deletions(-) diff --git a/app/Console/Commands/ScanCommand.php b/app/Console/Commands/ScanCommand.php index 3818edad..807044d4 100644 --- a/app/Console/Commands/ScanCommand.php +++ b/app/Console/Commands/ScanCommand.php @@ -168,7 +168,6 @@ class ScanCommand extends Command $specifiedOwner = $this->option('owner'); if ($specifiedOwner) { - /** @var User $user */ $user = User::findOr($specifiedOwner, function () use ($specifiedOwner): void { $this->components->error("User with ID $specifiedOwner does not exist."); exit(self::INVALID); diff --git a/app/Console/Commands/Storage/SetupDropboxStorageCommand.php b/app/Console/Commands/Storage/SetupDropboxStorageCommand.php index 4f70e1a3..e1031dd9 100644 --- a/app/Console/Commands/Storage/SetupDropboxStorageCommand.php +++ b/app/Console/Commands/Storage/SetupDropboxStorageCommand.php @@ -78,9 +78,7 @@ class SetupDropboxStorageCommand extends Command $this->comment('Uploading a test file to make sure everything is working...'); try { - /** @var DropboxStorage $storage */ - $storage = app(DropboxStorage::class); - $storage->testSetup(); + app(DropboxStorage::class)->testSetup(); } catch (Throwable $e) { $this->error('Failed to upload test file: ' . $e->getMessage() . '.'); $this->comment('Please make sure the app has the correct permissions and try again.'); diff --git a/app/Console/Commands/Storage/SetupS3StorageCommand.php b/app/Console/Commands/Storage/SetupS3StorageCommand.php index b948dfa5..d64b6088 100644 --- a/app/Console/Commands/Storage/SetupS3StorageCommand.php +++ b/app/Console/Commands/Storage/SetupS3StorageCommand.php @@ -45,9 +45,7 @@ class SetupS3StorageCommand extends Command $this->comment('Uploading a test file to make sure everything is working...'); try { - /** @var S3CompatibleStorage $storage */ - $storage = app(S3CompatibleStorage::class); - $storage->testSetup(); + app(S3CompatibleStorage::class)->testSetup(); } catch (Throwable $e) { $this->error('Failed to upload test file: ' . $e->getMessage() . '.'); $this->comment('Please check your configuration and try again.'); diff --git a/app/Http/Controllers/API/FetchOverviewController.php b/app/Http/Controllers/API/FetchOverviewController.php index 6c5d26b1..84eda69f 100644 --- a/app/Http/Controllers/API/FetchOverviewController.php +++ b/app/Http/Controllers/API/FetchOverviewController.php @@ -17,7 +17,6 @@ class FetchOverviewController extends Controller AlbumRepository $albumRepository, ArtistRepository $artistRepository ) { - return response()->json([ 'most_played_songs' => SongResource::collection($songRepository->getMostPlayed()), 'recently_played_songs' => SongResource::collection($songRepository->getRecentlyPlayed()), diff --git a/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php b/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php index 478a9e4d..c1b996c8 100644 --- a/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php +++ b/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php @@ -8,7 +8,6 @@ use App\Exceptions\NotAPlaylistCollaboratorException; use App\Http\Controllers\Controller; use App\Http\Requests\API\PlaylistCollaboration\PlaylistCollaboratorDestroyRequest; use App\Models\Playlist; -use App\Models\User; use App\Repositories\UserRepository; use App\Services\PlaylistCollaborationService; use Illuminate\Http\Response; @@ -32,7 +31,6 @@ class PlaylistCollaboratorController extends Controller { $this->authorize('own', $playlist); - /** @var User $collaborator */ $collaborator = $this->userRepository->getOne($request->collaborator); try { diff --git a/app/Http/Controllers/API/PlaylistController.php b/app/Http/Controllers/API/PlaylistController.php index 433cffdb..99a2bae0 100644 --- a/app/Http/Controllers/API/PlaylistController.php +++ b/app/Http/Controllers/API/PlaylistController.php @@ -9,7 +9,6 @@ use App\Http\Requests\API\PlaylistStoreRequest; use App\Http\Requests\API\PlaylistUpdateRequest; use App\Http\Resources\PlaylistResource; use App\Models\Playlist; -use App\Models\PlaylistFolder; use App\Models\User; use App\Repositories\PlaylistFolderRepository; use App\Repositories\PlaylistRepository; @@ -40,7 +39,6 @@ class PlaylistController extends Controller $folder = null; if ($request->folder_id) { - /** @var PlaylistFolder $folder */ $folder = $this->folderRepository->getOne($request->folder_id); $this->authorize('own', $folder); } @@ -68,7 +66,6 @@ class PlaylistController extends Controller $folder = null; if ($request->folder_id) { - /** @var PlaylistFolder $folder */ $folder = $this->folderRepository->getOne($request->folder_id); $this->authorize('own', $folder); } diff --git a/app/Http/Controllers/API/RegisterPlayController.php b/app/Http/Controllers/API/RegisterPlayController.php index 5b07a915..31921e02 100644 --- a/app/Http/Controllers/API/RegisterPlayController.php +++ b/app/Http/Controllers/API/RegisterPlayController.php @@ -19,7 +19,6 @@ class RegisterPlayController extends Controller InteractionService $interactionService, ?Authenticatable $user ) { - /** @var Song $song */ $song = Song::query()->findOrFail($request->song); $this->authorize('access', $song); diff --git a/app/Http/Controllers/API/ToggleLikeSongController.php b/app/Http/Controllers/API/ToggleLikeSongController.php index e45cd304..dbe95242 100644 --- a/app/Http/Controllers/API/ToggleLikeSongController.php +++ b/app/Http/Controllers/API/ToggleLikeSongController.php @@ -7,7 +7,6 @@ use App\Http\Requests\API\ToggleLikeSongRequest; use App\Http\Resources\InteractionResource; use App\Models\Song; use App\Models\User; -use App\Repositories\SongRepository; use App\Services\InteractionService; use Illuminate\Contracts\Auth\Authenticatable; @@ -16,7 +15,6 @@ class ToggleLikeSongController extends Controller /** @param User $user */ public function __invoke( ToggleLikeSongRequest $request, - SongRepository $songRepository, InteractionService $interactionService, ?Authenticatable $user ) { diff --git a/app/Http/Resources/PlaylistResource.php b/app/Http/Resources/PlaylistResource.php index ca0667e9..359fea88 100644 --- a/app/Http/Resources/PlaylistResource.php +++ b/app/Http/Resources/PlaylistResource.php @@ -3,7 +3,6 @@ namespace App\Http\Resources; use App\Models\Playlist; -use App\Models\User; use Illuminate\Http\Resources\Json\JsonResource; class PlaylistResource extends JsonResource @@ -28,7 +27,6 @@ class PlaylistResource extends JsonResource /** @return array */ public function toArray($request): array { - /** @var User $user */ $user = $request->user() ?? $this->playlist->user; return [ diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 6f063777..edbd2ee2 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -17,12 +17,9 @@ class AuthServiceProvider extends ServiceProvider $this->registerPolicies(); Auth::viaRequest('token-via-query-parameter', static function (Request $request): ?User { - /** @var TokenManager $tokenManager */ - $tokenManager = app(TokenManager::class); - $token = $request->get('api_token') ?: $request->get('t'); - return $tokenManager->getUserFromPlainTextToken($token ?: ''); + return app(TokenManager::class)->getUserFromPlainTextToken($token ?: ''); }); $this->setPasswordDefaultRules(); diff --git a/app/Repositories/AlbumRepository.php b/app/Repositories/AlbumRepository.php index 31028f99..156c2180 100644 --- a/app/Repositories/AlbumRepository.php +++ b/app/Repositories/AlbumRepository.php @@ -11,6 +11,9 @@ use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; +/** + * @extends Repository + */ class AlbumRepository extends Repository { /** @return Collection|array */ @@ -29,7 +32,6 @@ class AlbumRepository extends Repository /** @return Collection|array */ public function getMostPlayed(int $count = 6, ?User $user = null): Collection { - /** @var ?User $user */ $user ??= $this->auth->user(); return Album::query() diff --git a/app/Repositories/ArtistRepository.php b/app/Repositories/ArtistRepository.php index 792a292e..8806e3d3 100644 --- a/app/Repositories/ArtistRepository.php +++ b/app/Repositories/ArtistRepository.php @@ -11,12 +11,12 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection as BaseCollection; +/** @extends Repository */ class ArtistRepository extends Repository { /** @return Collection|array */ public function getMostPlayed(int $count = 6, ?User $user = null): Collection { - /** @var ?User $user */ $user ??= auth()->user(); return Artist::query() @@ -44,7 +44,7 @@ class ArtistRepository extends Repository } /** @return Collection|array */ - public function getMany(array $ids, bool $inThatOrder = false, ?User $user = null): Collection | BaseCollection + public function getMany(array $ids, bool $inThatOrder = false, ?User $user = null): Collection|BaseCollection { $artists = Artist::query() ->isStandard() diff --git a/app/Repositories/PlaylistFolderRepository.php b/app/Repositories/PlaylistFolderRepository.php index 1b206ce9..acc9c0a9 100644 --- a/app/Repositories/PlaylistFolderRepository.php +++ b/app/Repositories/PlaylistFolderRepository.php @@ -2,6 +2,11 @@ namespace App\Repositories; +use App\Models\PlaylistFolder; + +/** + * @extends Repository + */ class PlaylistFolderRepository extends Repository { } diff --git a/app/Repositories/PlaylistRepository.php b/app/Repositories/PlaylistRepository.php index d4b6fd34..5d0ebc91 100644 --- a/app/Repositories/PlaylistRepository.php +++ b/app/Repositories/PlaylistRepository.php @@ -7,6 +7,7 @@ use App\Models\Playlist; use App\Models\User; use Illuminate\Support\Collection; +/** @extends Repository */ class PlaylistRepository extends Repository { /** @return Collection */ diff --git a/app/Repositories/Repository.php b/app/Repositories/Repository.php index 07575c98..034d5604 100644 --- a/app/Repositories/Repository.php +++ b/app/Repositories/Repository.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; +/** @template T of Model */ abstract class Repository implements RepositoryInterface { private string $modelClass; @@ -28,17 +29,19 @@ abstract class Repository implements RepositoryInterface return preg_replace('/(.+)\\\\Repositories\\\\(.+)Repository$/m', '$1\Models\\\$2', static::class); } + /** @return T */ public function getOne($id): Model { - return $this->model->findOrFail($id); + return $this->model::query()->findOrFail($id); } + /** @return T|null */ public function findOne($id): ?Model { - return $this->model->find($id); + return $this->model::query()->find($id); } - /** @return Collection */ + /** @return array|Collection */ public function getMany(array $ids, bool $inThatOrder = false): Collection { $models = $this->model::query()->find($ids); @@ -46,19 +49,15 @@ abstract class Repository implements RepositoryInterface return $inThatOrder ? $models->orderByArray($ids) : $models; } - /** @return Collection */ + /** @return array|Collection */ public function getAll(): Collection { - return $this->model->all(); + return $this->model::all(); } + /** @return T|null */ public function getFirstWhere(...$params): ?Model { - return $this->model->firstWhere(...$params); - } - - public function getModelClass(): string - { - return $this->modelClass; + return $this->model::query()->firstWhere(...$params); } } diff --git a/app/Repositories/SettingRepository.php b/app/Repositories/SettingRepository.php index 0ba93e14..75535355 100644 --- a/app/Repositories/SettingRepository.php +++ b/app/Repositories/SettingRepository.php @@ -4,6 +4,7 @@ namespace App\Repositories; use App\Models\Setting; +/** @extends Repository */ class SettingRepository extends Repository { /** @return array */ diff --git a/app/Repositories/SongRepository.php b/app/Repositories/SongRepository.php index 0f8201c5..b69febff 100644 --- a/app/Repositories/SongRepository.php +++ b/app/Repositories/SongRepository.php @@ -13,6 +13,7 @@ use App\Values\Genre; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Support\Collection; +/** @extends Repository */ class SongRepository extends Repository { private const DEFAULT_QUEUE_LIMIT = 500; @@ -22,7 +23,7 @@ class SongRepository extends Repository return Song::query()->where('path', $path)->first(); } - /** @return Collection|array */ + /** @return Collection|array */ public function getAllStoredOnCloud(): Collection { return Song::query()->storedOnCloud()->get(); @@ -31,7 +32,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getRecentlyAdded(int $count = 10, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -45,7 +45,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getMostPlayed(int $count = 7, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -60,7 +59,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getRecentlyPlayed(int $count = 7, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -78,7 +76,6 @@ class SongRepository extends Repository ?User $scopedUser = null, int $perPage = 50 ): Paginator { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -96,7 +93,6 @@ class SongRepository extends Repository ?User $scopedUser = null, int $perPage = 50 ): Paginator { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -114,7 +110,6 @@ class SongRepository extends Repository int $limit = self::DEFAULT_QUEUE_LIMIT, ?User $scopedUser = null, ): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -128,7 +123,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getFavorites(?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -141,7 +135,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getByAlbum(Album $album, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -157,7 +150,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getByArtist(Artist $artist, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -175,7 +167,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getByStandardPlaylist(Playlist $playlist, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -202,7 +193,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getRandom(int $limit, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -216,7 +206,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getMany(array $ids, bool $inThatOrder = false, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); $songs = Song::query() @@ -235,7 +224,6 @@ class SongRepository extends Repository */ public function getManyInCollaborativeContext(array $ids, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -260,7 +248,6 @@ class SongRepository extends Repository /** @param string $id */ public function getOne($id, ?User $scopedUser = null): Song { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -272,7 +259,6 @@ class SongRepository extends Repository /** @param string $id */ public function findOne($id, ?User $scopedUser = null): ?Song { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() @@ -294,7 +280,6 @@ class SongRepository extends Repository /** @return Collection|array */ public function getRandomByGenre(string $genre, int $limit, ?User $scopedUser = null): Collection { - /** @var ?User $scopedUser */ $scopedUser ??= $this->auth->user(); return Song::query() diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 1ef84659..5311cdb7 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -7,6 +7,9 @@ namespace App\Repositories; use App\Models\User; use App\Values\SSOUser; +/** + * @extends Repository + */ class UserRepository extends Repository { public function getDefaultAdminUser(): User diff --git a/app/Services/AuthenticationService.php b/app/Services/AuthenticationService.php index c0fe567c..6ccc62e6 100644 --- a/app/Services/AuthenticationService.php +++ b/app/Services/AuthenticationService.php @@ -24,7 +24,6 @@ class AuthenticationService public function login(string $email, string $password): CompositeToken { - /** @var User|null $user */ $user = $this->userRepository->getFirstWhere('email', $email); if (!$user || !$this->hash->check($password, $user->password)) { @@ -82,9 +81,6 @@ class AuthenticationService public function loginViaOneTimeToken(string $token): CompositeToken { - /** @var User $user */ - $user = $this->userRepository->getOne(decrypt(Cache::get("one-time-token.$token"))); - - return $this->logUserIn($user); + return $this->logUserIn($this->userRepository->getOne(decrypt(Cache::get("one-time-token.$token")))); } } diff --git a/app/Services/DownloadService.php b/app/Services/DownloadService.php index bf65e68f..c0dc1557 100644 --- a/app/Services/DownloadService.php +++ b/app/Services/DownloadService.php @@ -5,7 +5,6 @@ namespace App\Services; use App\Enums\SongStorageType; use App\Models\Song; use App\Models\SongZipArchive; -use App\Services\SongStorages\CloudStorage; use App\Services\SongStorages\DropboxStorage; use App\Services\SongStorages\S3CompatibleStorage; use Illuminate\Support\Collection; @@ -37,13 +36,11 @@ class DownloadService switch ($song->storage) { case SongStorageType::DROPBOX: - /** @var CloudStorage $cloudStorage */ $cloudStorage = app(DropboxStorage::class); break; case SongStorageType::S3: case SongStorageType::S3_LAMBDA: - /** @var CloudStorage $cloudStorage */ $cloudStorage = app(S3CompatibleStorage::class); break; diff --git a/app/Services/LicenseService.php b/app/Services/LicenseService.php index 75a05938..95e71ae7 100644 --- a/app/Services/LicenseService.php +++ b/app/Services/LicenseService.php @@ -75,7 +75,6 @@ class LicenseService implements LicenseServiceInterface return Cache::get('license_status'); } - /** @var ?License $license */ $license = License::query()->latest()->first(); if (!$license) { diff --git a/app/Services/PlaylistCollaborationService.php b/app/Services/PlaylistCollaborationService.php index 36bea5de..3e719d4e 100644 --- a/app/Services/PlaylistCollaborationService.php +++ b/app/Services/PlaylistCollaborationService.php @@ -31,7 +31,6 @@ class PlaylistCollaborationService public function acceptUsingToken(string $token, User $user): Playlist { - /** @var PlaylistCollaborationToken $collaborationToken */ $collaborationToken = PlaylistCollaborationToken::query()->where('token', $token)->firstOrFail(); throw_if($collaborationToken->expired, PlaylistCollaborationTokenExpiredException::class); diff --git a/app/Services/PlaylistService.php b/app/Services/PlaylistService.php index de470d96..d666352b 100644 --- a/app/Services/PlaylistService.php +++ b/app/Services/PlaylistService.php @@ -42,7 +42,6 @@ class PlaylistService return DB::transaction( static function () use ($name, $user, $songs, $folder, $ruleGroups, $ownSongsOnly): Playlist { - /** @var Playlist $playlist */ $playlist = $user->playlists()->create([ 'name' => $name, 'rules' => $ruleGroups, diff --git a/app/Services/QueueService.php b/app/Services/QueueService.php index 684c05af..8249fb5b 100644 --- a/app/Services/QueueService.php +++ b/app/Services/QueueService.php @@ -15,7 +15,6 @@ class QueueService public function getQueueState(User $user): QueueStateDTO { - /** @var QueueState $state */ $state = QueueState::query()->where('user_id', $user->id)->firstOrCreate([ 'user_id' => $user->id, ], [ diff --git a/app/Services/SongStorages/S3LambdaStorage.php b/app/Services/SongStorages/S3LambdaStorage.php index 3e1c99e4..a3e197e8 100644 --- a/app/Services/SongStorages/S3LambdaStorage.php +++ b/app/Services/SongStorages/S3LambdaStorage.php @@ -60,8 +60,7 @@ final class S3LambdaStorage extends S3CompatibleStorage $this->mediaMetadataService->writeAlbumCover($album, base64_decode($cover['data'], true)); } - /** @var Song $song */ - $song = Song::query()->updateOrCreate(['path' => $path], [ + return Song::query()->updateOrCreate(['path' => $path], [ 'album_id' => $album->id, 'artist_id' => $artist->id, 'title' => $title, @@ -73,8 +72,6 @@ final class S3LambdaStorage extends S3CompatibleStorage 'is_public' => true, 'storage' => SongStorageType::S3_LAMBDA, ]); - - return $song; } public function deleteSongEntry(string $bucket, string $key): void diff --git a/app/Services/UserInvitationService.php b/app/Services/UserInvitationService.php index 1cde0bff..3c927dd3 100644 --- a/app/Services/UserInvitationService.php +++ b/app/Services/UserInvitationService.php @@ -44,7 +44,6 @@ class UserInvitationService private function inviteOne(string $email, bool $isAdmin, User $invitor): User { - /** @var User $invitee */ $invitee = User::query()->create([ 'name' => '', 'email' => $email, diff --git a/database/migrations/2016_04_16_082627_create_various_artists.php b/database/migrations/2016_04_16_082627_create_various_artists.php index 606ba54a..1bf73110 100644 --- a/database/migrations/2016_04_16_082627_create_various_artists.php +++ b/database/migrations/2016_04_16_082627_create_various_artists.php @@ -25,7 +25,6 @@ class CreateVariousArtists extends Migration Artist::unguard(); - /** @var Artist|null $existingArtist */ $existingArtist = Artist::query()->find(Artist::VARIOUS_ID); if ($existingArtist) { @@ -35,7 +34,6 @@ class CreateVariousArtists extends Migration // There's an existing artist with that special ID, but it's not our Various Artist // We move it to the end of the table. - /** @var Artist $latestArtist */ $latestArtist = Artist::query()->orderByDesc('id')->first(); $existingArtist->id = $latestArtist->id + 1; $existingArtist->save(); diff --git a/database/migrations/2017_04_21_092159_copy_artist_to_contributing_artist.php b/database/migrations/2017_04_21_092159_copy_artist_to_contributing_artist.php index da90a461..33bd6f62 100644 --- a/database/migrations/2017_04_21_092159_copy_artist_to_contributing_artist.php +++ b/database/migrations/2017_04_21_092159_copy_artist_to_contributing_artist.php @@ -1,14 +1,12 @@ $songs */ $songs = Song::with('album', 'album.artist')->get(); $songs->each(static function (Song $song): void { diff --git a/database/migrations/2024_01_03_104241_support_multi_tenant.php b/database/migrations/2024_01_03_104241_support_multi_tenant.php index cf6b103d..d56c40aa 100644 --- a/database/migrations/2024_01_03_104241_support_multi_tenant.php +++ b/database/migrations/2024_01_03_104241_support_multi_tenant.php @@ -16,7 +16,6 @@ return new class extends Migration { }); Schema::table('songs', static function (Blueprint $table): void { - /** @var ?User $firstAdmin */ $firstAdmin = User::query()->where('is_admin', true)->oldest()->first(); if ($firstAdmin === null) { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 147b901f..75df91b1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -28,6 +28,7 @@ parameters: - '#expects App\\Models\\User\|null, Illuminate\\Database\\Eloquent\\Collection\|Illuminate\\Database\\Eloquent\\Model given#' - '#Method App\\Models\\.*::query\(\) should return App\\Builders\\.*Builder but returns Illuminate\\Database\\Eloquent\\Builder#' - '#Parameter \#1 \$callback of method Illuminate\\Support\\Collection::each\(\) expects callable\(Illuminate\\Database\\Eloquent\\Model, int\)#' + - '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::#' excludePaths: diff --git a/tests/Feature/AlbumCoverTest.php b/tests/Feature/AlbumCoverTest.php index 5866c05f..8b73d2d4 100644 --- a/tests/Feature/AlbumCoverTest.php +++ b/tests/Feature/AlbumCoverTest.php @@ -24,7 +24,6 @@ class AlbumCoverTest extends TestCase public function testUpdate(): void { - /** @var Album $album */ $album = Album::factory()->create(); $this->mediaMetadataService @@ -38,7 +37,6 @@ class AlbumCoverTest extends TestCase public function testUpdateNotAllowedForNormalUsers(): void { - /** @var Album $album */ $album = Album::factory()->create(); $this->mediaMetadataService->shouldNotReceive('writeAlbumCover'); diff --git a/tests/Feature/AlbumInformationTest.php b/tests/Feature/AlbumInformationTest.php index c95a61ea..3d90cf50 100644 --- a/tests/Feature/AlbumInformationTest.php +++ b/tests/Feature/AlbumInformationTest.php @@ -15,7 +15,6 @@ class AlbumInformationTest extends TestCase config(['koel.lastfm.key' => 'foo']); config(['koel.lastfm.secret' => 'geheim']); - /** @var Album $album */ $album = Album::factory()->create(); $lastfm = self::mock(MediaInformationService::class); @@ -51,10 +50,7 @@ class AlbumInformationTest extends TestCase config(['koel.lastfm.key' => null]); config(['koel.lastfm.secret' => null]); - /** @var Album $album */ - $album = Album::factory()->create(); - - $this->getAs('api/albums/' . $album->id . '/information') + $this->getAs('api/albums/' . Album::factory()->create()->id . '/information') ->assertJsonStructure(AlbumInformation::JSON_STRUCTURE); } } diff --git a/tests/Feature/AlbumSongTest.php b/tests/Feature/AlbumSongTest.php index ea74f012..7d47c2bf 100644 --- a/tests/Feature/AlbumSongTest.php +++ b/tests/Feature/AlbumSongTest.php @@ -11,7 +11,6 @@ class AlbumSongTest extends TestCase { public function testIndex(): void { - /** @var Album $album */ $album = Album::factory()->create(); Song::factory(5)->for($album)->create(); diff --git a/tests/Feature/AlbumTest.php b/tests/Feature/AlbumTest.php index 0f9290dd..1a3c178d 100644 --- a/tests/Feature/AlbumTest.php +++ b/tests/Feature/AlbumTest.php @@ -18,10 +18,7 @@ class AlbumTest extends TestCase public function testShow(): void { - /** @var Album $album */ - $album = Album::factory()->create(); - - $this->getAs('api/albums/' . $album->id) + $this->getAs('api/albums/' . Album::factory()->create()->id) ->assertJsonStructure(AlbumResource::JSON_STRUCTURE); } } diff --git a/tests/Feature/AlbumThumbnailTest.php b/tests/Feature/AlbumThumbnailTest.php index 9003a856..269e9e98 100644 --- a/tests/Feature/AlbumThumbnailTest.php +++ b/tests/Feature/AlbumThumbnailTest.php @@ -28,7 +28,6 @@ class AlbumThumbnailTest extends TestCase /** @dataProvider provideAlbumThumbnailData */ public function testGetAlbumThumbnail(?string $thumbnailUrl): void { - /** @var Album $createdAlbum */ $createdAlbum = Album::factory()->create(); $this->mediaMetadataService diff --git a/tests/Feature/ArtistAlbumTest.php b/tests/Feature/ArtistAlbumTest.php index 7b006b2c..d72bf562 100644 --- a/tests/Feature/ArtistAlbumTest.php +++ b/tests/Feature/ArtistAlbumTest.php @@ -11,7 +11,6 @@ class ArtistAlbumTest extends TestCase { public function testIndex(): void { - /** @var Artist $artist */ $artist = Artist::factory()->create(); Album::factory(5)->for($artist)->create(); diff --git a/tests/Feature/ArtistImageTest.php b/tests/Feature/ArtistImageTest.php index 53b9b035..62f38ba5 100644 --- a/tests/Feature/ArtistImageTest.php +++ b/tests/Feature/ArtistImageTest.php @@ -23,7 +23,6 @@ class ArtistImageTest extends TestCase public function testUpdate(): void { - /** @var Artist $artist */ $artist = Artist::factory()->create(); $this->mediaMetadataService diff --git a/tests/Feature/ArtistInformationTest.php b/tests/Feature/ArtistInformationTest.php index c2e2f6f4..461b59e1 100644 --- a/tests/Feature/ArtistInformationTest.php +++ b/tests/Feature/ArtistInformationTest.php @@ -15,7 +15,6 @@ class ArtistInformationTest extends TestCase config(['koel.lastfm.key' => 'foo']); config(['koel.lastfm.secret' => 'geheim']); - /** @var Artist $artist */ $artist = Artist::factory()->create(); $lastfm = self::mock(MediaInformationService::class); @@ -39,10 +38,7 @@ class ArtistInformationTest extends TestCase config(['koel.lastfm.key' => null]); config(['koel.lastfm.secret' => null]); - /** @var Artist $artist */ - $artist = Artist::factory()->create(); - - $this->getAs('api/artists/' . $artist->id . '/information') + $this->getAs('api/artists/' . Artist::factory()->create()->id . '/information') ->assertJsonStructure(ArtistInformation::JSON_STRUCTURE); } } diff --git a/tests/Feature/ArtistSongTest.php b/tests/Feature/ArtistSongTest.php index 551ac471..9b3317d1 100644 --- a/tests/Feature/ArtistSongTest.php +++ b/tests/Feature/ArtistSongTest.php @@ -11,7 +11,6 @@ class ArtistSongTest extends TestCase { public function testIndex(): void { - /** @var Artist $artist */ $artist = Artist::factory()->create(); Song::factory(5)->for($artist)->create(); diff --git a/tests/Feature/ArtistTest.php b/tests/Feature/ArtistTest.php index 215acb74..59e8e758 100644 --- a/tests/Feature/ArtistTest.php +++ b/tests/Feature/ArtistTest.php @@ -18,10 +18,7 @@ class ArtistTest extends TestCase public function testShow(): void { - /** @var Artist $artist */ - $artist = Artist::factory()->create(); - - $this->getAs('api/artists/' . $artist->id) + $this->getAs('api/artists/' . Artist::factory()->create()->id) ->assertJsonStructure(ArtistResource::JSON_STRUCTURE); } } diff --git a/tests/Feature/DownloadTest.php b/tests/Feature/DownloadTest.php index 576ed415..29078e70 100644 --- a/tests/Feature/DownloadTest.php +++ b/tests/Feature/DownloadTest.php @@ -29,18 +29,14 @@ class DownloadTest extends TestCase public function testNonLoggedInUserCannotDownload(): void { - /** @var Song $song */ - $song = Song::factory()->create(); - $this->downloadService->shouldNotReceive('getDownloadablePath'); - $this->get("download/songs?songs[]=$song->id") + $this->get('download/songs?songs[]=' . Song::factory()->create()->id) ->assertUnauthorized(); } public function testDownloadOneSong(): void { - /** @var Song $song */ $song = Song::factory()->create(); $user = create_user(); @@ -58,7 +54,6 @@ class DownloadTest extends TestCase public function testDownloadMultipleSongs(): void { - /** @var array|Collection $songs */ $songs = Song::factory(2)->create(); $user = create_user(); @@ -81,7 +76,6 @@ class DownloadTest extends TestCase public function testDownloadAlbum(): void { - /** @var Album $album */ $album = Album::factory()->create(); $songs = Song::factory(3)->for($album)->create(); $user = create_user(); @@ -102,7 +96,6 @@ class DownloadTest extends TestCase public function testDownloadArtist(): void { - /** @var Artist $artist */ $artist = Artist::factory()->create(); $songs = Song::factory(3)->for($artist)->create(); $user = create_user(); @@ -128,7 +121,6 @@ class DownloadTest extends TestCase /** @var Playlist $playlist */ $playlist = Playlist::factory()->for($user)->create(); - $playlist->addSongs($songs); $this->downloadService @@ -147,11 +139,9 @@ class DownloadTest extends TestCase public function testNonOwnerCannotDownloadPlaylist(): void { - /** @var Playlist $playlist */ $playlist = Playlist::factory()->create(); - $user = create_user(); - $this->get("download/playlist/{$playlist->id}?api_token=" . $user->createToken('Koel')->plainTextToken) + $this->get("download/playlist/{$playlist->id}?api_token=" . create_user()->createToken('Koel')->plainTextToken) ->assertForbidden(); } diff --git a/tests/Feature/InteractionTest.php b/tests/Feature/InteractionTest.php index 95419c18..9e27edfd 100644 --- a/tests/Feature/InteractionTest.php +++ b/tests/Feature/InteractionTest.php @@ -7,7 +7,6 @@ use App\Events\PlaybackStarted; use App\Events\SongLikeToggled; use App\Models\Interaction; use App\Models\Song; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\Event; use Tests\TestCase; @@ -20,9 +19,8 @@ class InteractionTest extends TestCase Event::fake(PlaybackStarted::class); $user = create_user(); - - /** @var Song $song */ $song = Song::factory()->create(); + $this->postAs('api/interaction/play', ['song' => $song->id], $user); self::assertDatabaseHas(Interaction::class, [ @@ -46,9 +44,8 @@ class InteractionTest extends TestCase Event::fake(SongLikeToggled::class); $user = create_user(); - - /** @var Song $song */ $song = Song::factory()->create(); + $this->postAs('api/interaction/like', ['song' => $song->id], $user); self::assertDatabaseHas(Interaction::class, [ @@ -74,8 +71,6 @@ class InteractionTest extends TestCase Event::fake(MultipleSongsLiked::class); $user = create_user(); - - /** @var Collection $songs */ $songs = Song::factory(2)->create(); $songIds = $songs->pluck('id')->all(); diff --git a/tests/Feature/LastfmTest.php b/tests/Feature/LastfmTest.php index 77a348e5..75845ad3 100644 --- a/tests/Feature/LastfmTest.php +++ b/tests/Feature/LastfmTest.php @@ -7,7 +7,6 @@ use App\Services\TokenManager; use Laravel\Sanctum\NewAccessToken; use Laravel\Sanctum\PersonalAccessToken; use Mockery; -use Mockery\MockInterface; use Tests\TestCase; use function Tests\create_user; @@ -28,7 +27,6 @@ class LastfmTest extends TestCase $user = create_user(); $token = $user->createToken('Koel')->plainTextToken; - /** @var NewAccessToken|MockInterface $temporaryToken */ $temporaryToken = Mockery::mock(NewAccessToken::class); $temporaryToken->plainTextToken = 'tmp-token'; diff --git a/tests/Feature/PlayCountTest.php b/tests/Feature/PlayCountTest.php index 06e5958a..41011fa0 100644 --- a/tests/Feature/PlayCountTest.php +++ b/tests/Feature/PlayCountTest.php @@ -16,7 +16,6 @@ class PlayCountTest extends TestCase { Event::fake(PlaybackStarted::class); - /** @var Interaction $interaction */ $interaction = Interaction::factory()->create([ 'play_count' => 10, ]); @@ -38,9 +37,7 @@ class PlayCountTest extends TestCase { Event::fake(PlaybackStarted::class); - /** @var Song $song */ $song = Song::factory()->create(); - $user = create_user(); $this->postAs('/api/interaction/play', ['song' => $song->id], $user) @@ -52,7 +49,6 @@ class PlayCountTest extends TestCase 'play_count', ]); - /** @var Interaction $interaction */ $interaction = Interaction::query() ->where('song_id', $song->id) ->where('user_id', $user->id) diff --git a/tests/Feature/PlaylistCoverTest.php b/tests/Feature/PlaylistCoverTest.php index 6e3c7ce4..c71e235d 100644 --- a/tests/Feature/PlaylistCoverTest.php +++ b/tests/Feature/PlaylistCoverTest.php @@ -23,7 +23,6 @@ class PlaylistCoverTest extends TestCase public function testUploadCover(): void { - /** @var Playlist $playlist */ $playlist = Playlist::factory()->create(); self::assertNull($playlist->cover); @@ -38,7 +37,6 @@ class PlaylistCoverTest extends TestCase public function testUploadCoverNotAllowedForNonOwner(): void { - /** @var Playlist $playlist */ $playlist = Playlist::factory()->create(); $this->mediaMetadataService->shouldNotReceive('writePlaylistCover'); diff --git a/tests/Feature/PlaylistFolderTest.php b/tests/Feature/PlaylistFolderTest.php index 83ba39a0..e1b394eb 100644 --- a/tests/Feature/PlaylistFolderTest.php +++ b/tests/Feature/PlaylistFolderTest.php @@ -33,7 +33,6 @@ class PlaylistFolderTest extends TestCase public function testUpdate(): void { - /** @var PlaylistFolder $folder */ $folder = PlaylistFolder::factory()->create(['name' => 'Metal']); $this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user) @@ -44,7 +43,6 @@ class PlaylistFolderTest extends TestCase public function testUnauthorizedUpdate(): void { - /** @var PlaylistFolder $folder */ $folder = PlaylistFolder::factory()->create(['name' => 'Metal']); $this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical']) @@ -55,7 +53,6 @@ class PlaylistFolderTest extends TestCase public function testDelete(): void { - /** @var PlaylistFolder $folder */ $folder = PlaylistFolder::factory()->create(); $this->deleteAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user)