diff --git a/app/Console/Commands/Admin/ChangePasswordCommand.php b/app/Console/Commands/Admin/ChangePasswordCommand.php index 2a023af6..d1cfc072 100644 --- a/app/Console/Commands/Admin/ChangePasswordCommand.php +++ b/app/Console/Commands/Admin/ChangePasswordCommand.php @@ -11,20 +11,16 @@ class ChangePasswordCommand extends Command { use AskForPassword; - protected $signature = "koel:admin:change-password + protected $signature = "koel:admin:change-password {email? : The user's email. If empty, will get the default admin user.}"; protected $description = "Change a user's password"; - private Hash $hash; - - public function __construct(Hash $hash) + public function __construct(private Hash $hash) { parent::__construct(); - - $this->hash = $hash; } - public function handle(): void + public function handle(): int { $email = $this->argument('email'); @@ -34,7 +30,7 @@ class ChangePasswordCommand extends Command if (!$user) { $this->error('The user account cannot be found.'); - return; + return self::FAILURE; } $this->comment("Changing the user's password (ID: $user->id, email: $user->email)"); @@ -43,5 +39,7 @@ class ChangePasswordCommand extends Command $user->save(); $this->comment('Alrighty, the new password has been saved. Enjoy! 👌'); + + return self::SUCCESS; } } diff --git a/app/Console/Commands/ImportSearchableEntitiesCommand.php b/app/Console/Commands/ImportSearchableEntitiesCommand.php index 22bfeb53..b6a24694 100644 --- a/app/Console/Commands/ImportSearchableEntitiesCommand.php +++ b/app/Console/Commands/ImportSearchableEntitiesCommand.php @@ -30,6 +30,6 @@ class ImportSearchableEntitiesCommand extends Command $this->call('scout:import', ['model' => $entity]); } - return 0; + return self::SUCCESS; } } diff --git a/app/Console/Commands/InitCommand.php b/app/Console/Commands/InitCommand.php index 1c94b0b3..2dad223b 100644 --- a/app/Console/Commands/InitCommand.php +++ b/app/Console/Commands/InitCommand.php @@ -38,7 +38,7 @@ class InitCommand extends Command parent::__construct(); } - public function handle(): void + public function handle(): int { $this->comment('Attempting to install or upgrade Koel.'); $this->comment('Remember, you can always install/upgrade manually following the guide here:'); @@ -60,7 +60,7 @@ class InitCommand extends Command $this->error('Please try again, or visit ' . config('koel.misc.docs_url') . ' for manual installation.'); $this->error('😥 Sorry for this. You deserve better.'); - return; + return self::FAILURE; } $this->comment(PHP_EOL . '🎆 Success! Koel can now be run from localhost with `php artisan serve`.'); @@ -76,12 +76,16 @@ class InitCommand extends Command } $this->comment('Again, visit 📙 ' . config('koel.misc.docs_url') . ' for the official documentation.'); + $this->comment( "Feeling generous and want to support Koel's development? Check out " . config('koel.misc.sponsor_github_url') . ' 🤗' ); + $this->comment('Thanks for using Koel. You rock! 🤘'); + + return self::SUCCESS; } /** diff --git a/app/Console/Commands/PruneLibraryCommand.php b/app/Console/Commands/PruneLibraryCommand.php index 302a3434..1c844589 100644 --- a/app/Console/Commands/PruneLibraryCommand.php +++ b/app/Console/Commands/PruneLibraryCommand.php @@ -21,6 +21,6 @@ class PruneLibraryCommand extends Command $this->info('Empty artists and albums removed.'); - return Command::SUCCESS; + return self::SUCCESS; } } diff --git a/app/Console/Commands/SyncCommand.php b/app/Console/Commands/SyncCommand.php index a7185c29..5729d8f0 100644 --- a/app/Console/Commands/SyncCommand.php +++ b/app/Console/Commands/SyncCommand.php @@ -40,7 +40,7 @@ class SyncCommand extends Command $this->syncAll(); } - return Command::SUCCESS; + return self::SUCCESS; } /** diff --git a/app/Console/Commands/TidyLibraryCommand.php b/app/Console/Commands/TidyLibraryCommand.php index b854d190..85be3cd1 100644 --- a/app/Console/Commands/TidyLibraryCommand.php +++ b/app/Console/Commands/TidyLibraryCommand.php @@ -9,8 +9,10 @@ class TidyLibraryCommand extends Command protected $signature = 'koel:tidy'; protected $hidden = true; - public function handle(): void + public function handle(): int { $this->warn('koel:tidy has been renamed. Use koel:prune instead.'); + + return self::SUCCESS; } } diff --git a/app/Events/MediaSyncCompleted.php b/app/Events/MediaSyncCompleted.php index ccc2edd9..a4c51e95 100644 --- a/app/Events/MediaSyncCompleted.php +++ b/app/Events/MediaSyncCompleted.php @@ -9,10 +9,7 @@ class MediaSyncCompleted extends Event { use SerializesModels; - public SyncResult $result; - - public function __construct(SyncResult $result) + public function __construct(public SyncResult $result) { - $this->result = $result; } } diff --git a/app/Events/SongLikeToggled.php b/app/Events/SongLikeToggled.php index a1a69ec2..de9a02a6 100644 --- a/app/Events/SongLikeToggled.php +++ b/app/Events/SongLikeToggled.php @@ -3,19 +3,13 @@ namespace App\Events; use App\Models\Interaction; -use App\Models\User; use Illuminate\Queue\SerializesModels; class SongLikeToggled extends Event { use SerializesModels; - public Interaction $interaction; - public ?User $user = null; - - public function __construct(Interaction $interaction, ?User $user = null) + public function __construct(public Interaction $interaction) { - $this->interaction = $interaction; - $this->user = $user ?: auth()->user(); } } diff --git a/app/Events/SongStartedPlaying.php b/app/Events/SongStartedPlaying.php index d9ada059..a5172c09 100644 --- a/app/Events/SongStartedPlaying.php +++ b/app/Events/SongStartedPlaying.php @@ -10,12 +10,7 @@ class SongStartedPlaying extends Event { use SerializesModels; - public Song $song; - public User $user; - - public function __construct(Song $song, User $user) + public function __construct(public Song $song, public User $user) { - $this->song = $song; - $this->user = $user; } } diff --git a/app/Events/SongsBatchLiked.php b/app/Events/SongsBatchLiked.php index 2b666e3c..007c55cf 100644 --- a/app/Events/SongsBatchLiked.php +++ b/app/Events/SongsBatchLiked.php @@ -10,12 +10,7 @@ class SongsBatchLiked extends Event { use SerializesModels; - public Collection $songs; - public User $user; - - public function __construct(Collection $songs, User $user) + public function __construct(public Collection $songs, public User $user) { - $this->songs = $songs; - $this->user = $user; } } diff --git a/app/Events/SongsBatchUnliked.php b/app/Events/SongsBatchUnliked.php index 5db145ea..51883a6a 100644 --- a/app/Events/SongsBatchUnliked.php +++ b/app/Events/SongsBatchUnliked.php @@ -10,12 +10,7 @@ class SongsBatchUnliked extends Event { use SerializesModels; - public Collection $songs; - public User $user; - - public function __construct(Collection $songs, User $user) + public function __construct(public Collection $songs, public User $user) { - $this->songs = $songs; - $this->user = $user; } } diff --git a/app/Factories/StreamerFactory.php b/app/Factories/StreamerFactory.php index 53f7141f..ec41f005 100644 --- a/app/Factories/StreamerFactory.php +++ b/app/Factories/StreamerFactory.php @@ -11,21 +11,12 @@ use App\Services\TranscodingService; class StreamerFactory { - private DirectStreamerInterface $directStreamer; - private TranscodingStreamerInterface $transcodingStreamer; - private ObjectStorageStreamerInterface $objectStorageStreamer; - private TranscodingService $transcodingService; - public function __construct( - DirectStreamerInterface $directStreamer, - TranscodingStreamerInterface $transcodingStreamer, - ObjectStorageStreamerInterface $objectStorageStreamer, - TranscodingService $transcodingService + private DirectStreamerInterface $directStreamer, + private TranscodingStreamerInterface $transcodingStreamer, + private ObjectStorageStreamerInterface $objectStorageStreamer, + private TranscodingService $transcodingService ) { - $this->directStreamer = $directStreamer; - $this->transcodingStreamer = $transcodingStreamer; - $this->objectStorageStreamer = $objectStorageStreamer; - $this->transcodingService = $transcodingService; } public function createStreamer( diff --git a/app/Http/Controllers/API/AlbumCoverController.php b/app/Http/Controllers/API/AlbumCoverController.php index 8152bcd1..a4806338 100644 --- a/app/Http/Controllers/API/AlbumCoverController.php +++ b/app/Http/Controllers/API/AlbumCoverController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\API; use App\Events\LibraryChanged; +use App\Http\Controllers\Controller; use App\Http\Requests\API\AlbumCoverUpdateRequest; use App\Models\Album; use App\Services\MediaMetadataService; @@ -10,11 +11,8 @@ use Illuminate\Http\JsonResponse; class AlbumCoverController extends Controller { - private MediaMetadataService $mediaMetadataService; - - public function __construct(MediaMetadataService $mediaMetadataService) + public function __construct(private MediaMetadataService $mediaMetadataService) { - $this->mediaMetadataService = $mediaMetadataService; } public function update(AlbumCoverUpdateRequest $request, Album $album) diff --git a/app/Http/Controllers/API/AlbumThumbnailController.php b/app/Http/Controllers/API/AlbumThumbnailController.php index 3577b5bb..b7931db5 100644 --- a/app/Http/Controllers/API/AlbumThumbnailController.php +++ b/app/Http/Controllers/API/AlbumThumbnailController.php @@ -2,17 +2,15 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Models\Album; use App\Services\MediaMetadataService; use Illuminate\Http\JsonResponse; class AlbumThumbnailController extends Controller { - private MediaMetadataService $mediaMetadataService; - - public function __construct(MediaMetadataService $mediaMetadataService) + public function __construct(private MediaMetadataService $mediaMetadataService) { - $this->mediaMetadataService = $mediaMetadataService; } public function show(Album $album): JsonResponse diff --git a/app/Http/Controllers/API/ArtistImageController.php b/app/Http/Controllers/API/ArtistImageController.php index a7cedc6d..25af7b4a 100644 --- a/app/Http/Controllers/API/ArtistImageController.php +++ b/app/Http/Controllers/API/ArtistImageController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\API; use App\Events\LibraryChanged; +use App\Http\Controllers\Controller; use App\Http\Requests\API\ArtistImageUpdateRequest; use App\Models\Artist; use App\Services\MediaMetadataService; @@ -10,11 +11,8 @@ use Illuminate\Http\JsonResponse; class ArtistImageController extends Controller { - private MediaMetadataService $mediaMetadataService; - - public function __construct(MediaMetadataService $mediaMetadataService) + public function __construct(private MediaMetadataService $mediaMetadataService) { - $this->mediaMetadataService = $mediaMetadataService; } public function update(ArtistImageUpdateRequest $request, Artist $artist) diff --git a/app/Http/Controllers/API/AuthController.php b/app/Http/Controllers/API/AuthController.php index a9d5aa1a..d35a9972 100644 --- a/app/Http/Controllers/API/AuthController.php +++ b/app/Http/Controllers/API/AuthController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\UserLoginRequest; use App\Models\User; use App\Repositories\UserRepository; @@ -15,23 +16,13 @@ class AuthController extends Controller { use ThrottlesLogins; - private UserRepository $userRepository; - private HashManager $hash; - private TokenManager $tokenManager; - - /** @var User */ - private ?Authenticatable $currentUser; - + /** @param User $user */ public function __construct( - UserRepository $userRepository, - HashManager $hash, - TokenManager $tokenManager, - ?Authenticatable $currentUser + private UserRepository $userRepository, + private HashManager $hash, + private TokenManager $tokenManager, + private ?Authenticatable $user ) { - $this->userRepository = $userRepository; - $this->hash = $hash; - $this->tokenManager = $tokenManager; - $this->currentUser = $currentUser; } public function login(UserLoginRequest $request) @@ -50,8 +41,8 @@ class AuthController extends Controller public function logout() { - if ($this->currentUser) { - $this->tokenManager->destroyTokens($this->currentUser); + if ($this->user) { + $this->tokenManager->destroyTokens($this->user); } return response()->noContent(); diff --git a/app/Http/Controllers/API/Controller.php b/app/Http/Controllers/API/Controller.php deleted file mode 100644 index d4773ded..00000000 --- a/app/Http/Controllers/API/Controller.php +++ /dev/null @@ -1,9 +0,0 @@ -lastfmService = $lastfmService; - $this->youTubeService = $youTubeService; - $this->iTunesService = $iTunesService; - $this->mediaCacheService = $mediaCacheService; - $this->settingRepository = $settingRepository; - $this->playlistRepository = $playlistRepository; - $this->interactionRepository = $interactionRepository; - $this->userRepository = $userRepository; - $this->applicationInformationService = $applicationInformationService; - $this->currentUser = $currentUser; } public function index() diff --git a/app/Http/Controllers/API/Interaction/BatchLikeController.php b/app/Http/Controllers/API/Interaction/BatchLikeController.php index be189bef..e589cad9 100644 --- a/app/Http/Controllers/API/Interaction/BatchLikeController.php +++ b/app/Http/Controllers/API/Interaction/BatchLikeController.php @@ -2,10 +2,19 @@ namespace App\Http\Controllers\API\Interaction; +use App\Http\Controllers\Controller; use App\Http\Requests\API\BatchInteractionRequest; +use App\Models\User; +use App\Services\InteractionService; +use Illuminate\Contracts\Auth\Authenticatable; class BatchLikeController extends Controller { + /** @param User $user */ + public function __construct(private InteractionService $interactionService, protected ?Authenticatable $user) + { + } + public function store(BatchInteractionRequest $request) { $interactions = $this->interactionService->batchLike((array) $request->songs, $this->user); diff --git a/app/Http/Controllers/API/Interaction/Controller.php b/app/Http/Controllers/API/Interaction/Controller.php deleted file mode 100644 index 2899e536..00000000 --- a/app/Http/Controllers/API/Interaction/Controller.php +++ /dev/null @@ -1,22 +0,0 @@ -interactionService = $interactionService; - $this->user = $currentUser; - } -} diff --git a/app/Http/Controllers/API/Interaction/LikeController.php b/app/Http/Controllers/API/Interaction/LikeController.php index f154e97a..813fa15e 100644 --- a/app/Http/Controllers/API/Interaction/LikeController.php +++ b/app/Http/Controllers/API/Interaction/LikeController.php @@ -2,10 +2,19 @@ namespace App\Http\Controllers\API\Interaction; +use App\Http\Controllers\Controller; use App\Http\Requests\API\SongLikeRequest; +use App\Models\User; +use App\Services\InteractionService; +use Illuminate\Contracts\Auth\Authenticatable; class LikeController extends Controller { + /** @param User $user */ + public function __construct(private InteractionService $interactionService, private ?Authenticatable $user) + { + } + public function store(SongLikeRequest $request) { return response()->json($this->interactionService->toggleLike($request->song, $this->user)); diff --git a/app/Http/Controllers/API/Interaction/PlayCountController.php b/app/Http/Controllers/API/Interaction/PlayCountController.php index 17a854f6..ccf428ca 100644 --- a/app/Http/Controllers/API/Interaction/PlayCountController.php +++ b/app/Http/Controllers/API/Interaction/PlayCountController.php @@ -3,10 +3,19 @@ namespace App\Http\Controllers\API\Interaction; use App\Events\SongStartedPlaying; +use App\Http\Controllers\Controller; use App\Http\Requests\API\Interaction\StorePlayCountRequest; +use App\Models\User; +use App\Services\InteractionService; +use Illuminate\Contracts\Auth\Authenticatable; class PlayCountController extends Controller { + /** @param User $user */ + public function __construct(private InteractionService $interactionService, private ?Authenticatable $user) + { + } + public function store(StorePlayCountRequest $request) { $interaction = $this->interactionService->increasePlayCount($request->song, $this->user); diff --git a/app/Http/Controllers/API/Interaction/RecentlyPlayedController.php b/app/Http/Controllers/API/Interaction/RecentlyPlayedController.php index 57051a37..e39d36bf 100644 --- a/app/Http/Controllers/API/Interaction/RecentlyPlayedController.php +++ b/app/Http/Controllers/API/Interaction/RecentlyPlayedController.php @@ -2,20 +2,16 @@ namespace App\Http\Controllers\API\Interaction; +use App\Http\Controllers\Controller; use App\Models\User; use App\Repositories\InteractionRepository; -use App\Services\InteractionService; use Illuminate\Contracts\Auth\Authenticatable; class RecentlyPlayedController extends Controller { /** @param User $user */ - public function __construct( - protected InteractionService $interactionService, - protected InteractionRepository $interactionRepository, - protected ?Authenticatable $user - ) { - parent::__construct($interactionService, $user); + public function __construct(private InteractionRepository $interactionRepository, private ?Authenticatable $user) + { } public function index(?int $count = null) diff --git a/app/Http/Controllers/API/LastfmController.php b/app/Http/Controllers/API/LastfmController.php index 5bbfcb24..7a83ad0e 100644 --- a/app/Http/Controllers/API/LastfmController.php +++ b/app/Http/Controllers/API/LastfmController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\LastfmSetSessionKeyRequest; use App\Models\User; use App\Services\LastfmService; @@ -9,20 +10,14 @@ use Illuminate\Contracts\Auth\Authenticatable; class LastfmController extends Controller { - private LastfmService $lastfm; - - /** @var User */ - private ?Authenticatable $currentUser; - - public function __construct(LastfmService $lastfm, ?Authenticatable $currentUser) + /** @param User $currentUser */ + public function __construct(private LastfmService $lastfm, private ?Authenticatable $currentUser) { - $this->lastfm = $lastfm; - $this->currentUser = $currentUser; } public function setSessionKey(LastfmSetSessionKeyRequest $request) { - $this->lastfm->setUserSessionKey($this->currentUser, trim($request->key)); + $this->lastfm->setUserSessionKey($this->currentUser, $request->key); return response()->noContent(); } diff --git a/app/Http/Controllers/API/MediaInformation/AlbumController.php b/app/Http/Controllers/API/MediaInformation/AlbumController.php index 55d77eda..e7b4eacf 100644 --- a/app/Http/Controllers/API/MediaInformation/AlbumController.php +++ b/app/Http/Controllers/API/MediaInformation/AlbumController.php @@ -2,10 +2,16 @@ namespace App\Http\Controllers\API\MediaInformation; +use App\Http\Controllers\Controller; use App\Models\Album; +use App\Services\MediaInformationService; class AlbumController extends Controller { + public function __construct(private MediaInformationService $mediaInformationService) + { + } + public function show(Album $album) { return response()->json($this->mediaInformationService->getAlbumInformation($album)?->toArray() ?: []); diff --git a/app/Http/Controllers/API/MediaInformation/ArtistController.php b/app/Http/Controllers/API/MediaInformation/ArtistController.php index cc088ae9..26126728 100644 --- a/app/Http/Controllers/API/MediaInformation/ArtistController.php +++ b/app/Http/Controllers/API/MediaInformation/ArtistController.php @@ -2,10 +2,16 @@ namespace App\Http\Controllers\API\MediaInformation; +use App\Http\Controllers\Controller; use App\Models\Artist; +use App\Services\MediaInformationService; class ArtistController extends Controller { + public function __construct(private MediaInformationService $mediaInformationService) + { + } + public function show(Artist $artist) { return response()->json($this->mediaInformationService->getArtistInformation($artist)?->toArray() ?: []); diff --git a/app/Http/Controllers/API/MediaInformation/Controller.php b/app/Http/Controllers/API/MediaInformation/Controller.php deleted file mode 100644 index 669bb51a..00000000 --- a/app/Http/Controllers/API/MediaInformation/Controller.php +++ /dev/null @@ -1,16 +0,0 @@ -mediaInformationService = $mediaInformationService; - } -} diff --git a/app/Http/Controllers/API/MediaInformation/SongController.php b/app/Http/Controllers/API/MediaInformation/SongController.php index 50ef6bcb..a8406845 100644 --- a/app/Http/Controllers/API/MediaInformation/SongController.php +++ b/app/Http/Controllers/API/MediaInformation/SongController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API\MediaInformation; +use App\Http\Controllers\Controller; use App\Models\Song; use App\Services\MediaInformationService; use App\Services\YouTubeService; @@ -9,10 +10,9 @@ use App\Services\YouTubeService; class SongController extends Controller { public function __construct( - protected MediaInformationService $mediaInformationService, + private MediaInformationService $mediaInformationService, private YouTubeService $youTubeService ) { - parent::__construct($mediaInformationService); } public function show(Song $song) diff --git a/app/Http/Controllers/API/ObjectStorage/Controller.php b/app/Http/Controllers/API/ObjectStorage/Controller.php deleted file mode 100644 index cccb8f0e..00000000 --- a/app/Http/Controllers/API/ObjectStorage/Controller.php +++ /dev/null @@ -1,9 +0,0 @@ -s3Service = $s3Service; } public function put(PutSongRequest $request) diff --git a/app/Http/Controllers/API/PlaylistController.php b/app/Http/Controllers/API/PlaylistController.php index bbca28a4..c62de6c4 100644 --- a/app/Http/Controllers/API/PlaylistController.php +++ b/app/Http/Controllers/API/PlaylistController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\PlaylistStoreRequest; use App\Http\Requests\API\PlaylistUpdateRequest; use App\Models\Playlist; @@ -12,20 +13,12 @@ use Illuminate\Contracts\Auth\Authenticatable; class PlaylistController extends Controller { - private PlaylistRepository $playlistRepository; - private PlaylistService $playlistService; - - /** @var User */ - private ?Authenticatable $currentUser; - + /** @param User $user */ public function __construct( - PlaylistRepository $playlistRepository, - PlaylistService $playlistService, - ?Authenticatable $currentUser + private PlaylistRepository $playlistRepository, + private PlaylistService $playlistService, + private ?Authenticatable $user ) { - $this->playlistRepository = $playlistRepository; - $this->playlistService = $playlistService; - $this->currentUser = $currentUser; } public function index() @@ -37,7 +30,7 @@ class PlaylistController extends Controller { $playlist = $this->playlistService->createPlaylist( $request->name, - $this->currentUser, + $this->user, (array) $request->songs, $request->rules ); @@ -62,6 +55,6 @@ class PlaylistController extends Controller $playlist->delete(); - return response()->json(); + return response()->noContent(); } } diff --git a/app/Http/Controllers/API/PlaylistSongController.php b/app/Http/Controllers/API/PlaylistSongController.php index 1542dce9..f7274b0a 100644 --- a/app/Http/Controllers/API/PlaylistSongController.php +++ b/app/Http/Controllers/API/PlaylistSongController.php @@ -2,17 +2,18 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\PlaylistSongUpdateRequest; use App\Models\Playlist; +use App\Services\PlaylistService; use App\Services\SmartPlaylistService; class PlaylistSongController extends Controller { - private SmartPlaylistService $smartPlaylistService; - - public function __construct(SmartPlaylistService $smartPlaylistService) - { - $this->smartPlaylistService = $smartPlaylistService; + public function __construct( + private SmartPlaylistService $smartPlaylistService, + private PlaylistService $playlistService + ) { } public function index(Playlist $playlist) @@ -26,14 +27,15 @@ class PlaylistSongController extends Controller ); } + /** @deprecated */ public function update(PlaylistSongUpdateRequest $request, Playlist $playlist) { $this->authorize('owner', $playlist); - abort_if($playlist->is_smart, 403, 'A smart playlist\'s content cannot be updated manually.'); + abort_if($playlist->is_smart, 403, 'A smart playlist cannot be populated manually.'); - $playlist->songs()->sync((array) $request->songs); + $this->playlistService->populatePlaylist($playlist, (array) $request->songs); - return response()->json(); + return response()->noContent(); } } diff --git a/app/Http/Controllers/API/ProfileController.php b/app/Http/Controllers/API/ProfileController.php index f6683d6a..faba321d 100644 --- a/app/Http/Controllers/API/ProfileController.php +++ b/app/Http/Controllers/API/ProfileController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\ProfileUpdateRequest; use App\Http\Resources\UserResource; use App\Models\User; diff --git a/app/Http/Controllers/API/ScrobbleController.php b/app/Http/Controllers/API/ScrobbleController.php index 0c35dc41..c77a3e33 100644 --- a/app/Http/Controllers/API/ScrobbleController.php +++ b/app/Http/Controllers/API/ScrobbleController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\ScrobbleStoreRequest; use App\Jobs\ScrobbleJob; use App\Models\Song; @@ -10,12 +11,9 @@ use Illuminate\Contracts\Auth\Authenticatable; class ScrobbleController extends Controller { - /** @var User */ - private ?Authenticatable $currentUser; - - public function __construct(?Authenticatable $currentUser) + /** @param User $currentUser */ + public function __construct(private ?Authenticatable $currentUser) { - $this->currentUser = $currentUser; } public function store(ScrobbleStoreRequest $request, Song $song) diff --git a/app/Http/Controllers/API/Search/ExcerptSearchController.php b/app/Http/Controllers/API/Search/ExcerptSearchController.php index b894efa3..5d5d9f6e 100644 --- a/app/Http/Controllers/API/Search/ExcerptSearchController.php +++ b/app/Http/Controllers/API/Search/ExcerptSearchController.php @@ -2,31 +2,23 @@ namespace App\Http\Controllers\API\Search; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Services\SearchService; use Illuminate\Http\Request; use InvalidArgumentException; class ExcerptSearchController extends Controller { - private SearchService $searchService; - - public function __construct(SearchService $searchService) + public function __construct(private SearchService $searchService) { - $this->searchService = $searchService; } public function index(Request $request) { - if (!$request->get('q')) { - throw new InvalidArgumentException('A search query is required.'); - } + throw_unless((bool) $request->get('q'), new InvalidArgumentException('A search query is required.')); $count = (int) $request->get('count', SearchService::DEFAULT_EXCERPT_RESULT_COUNT); - - if ($count < 0) { - throw new InvalidArgumentException('Invalid count parameter.'); - } + throw_if($count < 0, new InvalidArgumentException('Invalid count parameter.')); return [ 'results' => $this->searchService->excerptSearch($request->get('q'), $count), diff --git a/app/Http/Controllers/API/Search/SongSearchController.php b/app/Http/Controllers/API/Search/SongSearchController.php index 8157e623..0c7f767b 100644 --- a/app/Http/Controllers/API/Search/SongSearchController.php +++ b/app/Http/Controllers/API/Search/SongSearchController.php @@ -2,25 +2,20 @@ namespace App\Http\Controllers\API\Search; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Services\SearchService; use Illuminate\Http\Request; use InvalidArgumentException; class SongSearchController extends Controller { - private SearchService $searchService; - - public function __construct(SearchService $searchService) + public function __construct(private SearchService $searchService) { - $this->searchService = $searchService; } public function index(Request $request) { - if (!$request->get('q')) { - throw new InvalidArgumentException('A search query is required.'); - } + throw_unless((bool) $request->get('q'), new InvalidArgumentException('A search query is required.')); return [ 'songs' => $this->searchService->searchSongs($request->get('q')), diff --git a/app/Http/Controllers/API/SettingController.php b/app/Http/Controllers/API/SettingController.php index 8a0ed5cf..0b0750e4 100644 --- a/app/Http/Controllers/API/SettingController.php +++ b/app/Http/Controllers/API/SettingController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\SettingRequest; use App\Models\Setting; use App\Models\User; diff --git a/app/Http/Controllers/API/SongController.php b/app/Http/Controllers/API/SongController.php index 7da40ccb..c8a5e8c5 100644 --- a/app/Http/Controllers/API/SongController.php +++ b/app/Http/Controllers/API/SongController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\SongUpdateRequest; use App\Http\Resources\AlbumResource; use App\Http\Resources\ArtistResource; diff --git a/app/Http/Controllers/API/UploadController.php b/app/Http/Controllers/API/UploadController.php index 77a90f00..55bd9a8c 100644 --- a/app/Http/Controllers/API/UploadController.php +++ b/app/Http/Controllers/API/UploadController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\API; use App\Exceptions\MediaPathNotSetException; use App\Exceptions\SongUploadFailedException; +use App\Http\Controllers\Controller; use App\Http\Requests\API\UploadRequest; use App\Http\Resources\AlbumResource; use App\Http\Resources\SongResource; diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index e6ee8255..9aa99268 100644 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\UserStoreRequest; use App\Http\Requests\API\UserUpdateRequest; use App\Http\Resources\UserResource; diff --git a/app/Http/Controllers/API/YouTubeController.php b/app/Http/Controllers/API/YouTubeController.php index cb2f2f11..b507e081 100644 --- a/app/Http/Controllers/API/YouTubeController.php +++ b/app/Http/Controllers/API/YouTubeController.php @@ -2,17 +2,15 @@ namespace App\Http\Controllers\API; +use App\Http\Controllers\Controller; use App\Http\Requests\API\YouTubeSearchRequest; use App\Models\Song; use App\Services\YouTubeService; class YouTubeController extends Controller { - private YouTubeService $youTubeService; - - public function __construct(YouTubeService $youTubeService) + public function __construct(private YouTubeService $youTubeService) { - $this->youTubeService = $youTubeService; } public function searchVideosRelatedToSong(YouTubeSearchRequest $request, Song $song) diff --git a/app/Http/Controllers/Download/AlbumController.php b/app/Http/Controllers/Download/AlbumController.php index ce3792fc..0ba68a40 100644 --- a/app/Http/Controllers/Download/AlbumController.php +++ b/app/Http/Controllers/Download/AlbumController.php @@ -2,10 +2,16 @@ namespace App\Http\Controllers\Download; +use App\Http\Controllers\Controller; use App\Models\Album; +use App\Services\DownloadService; class AlbumController extends Controller { + public function __construct(private DownloadService $downloadService) + { + } + public function show(Album $album) { return response()->download($this->downloadService->from($album)); diff --git a/app/Http/Controllers/Download/ArtistController.php b/app/Http/Controllers/Download/ArtistController.php index c903d252..c2939ae0 100644 --- a/app/Http/Controllers/Download/ArtistController.php +++ b/app/Http/Controllers/Download/ArtistController.php @@ -2,10 +2,16 @@ namespace App\Http\Controllers\Download; +use App\Http\Controllers\Controller; use App\Models\Artist; +use App\Services\DownloadService; class ArtistController extends Controller { + public function __construct(private DownloadService $downloadService) + { + } + public function show(Artist $artist) { return response()->download($this->downloadService->from($artist)); diff --git a/app/Http/Controllers/Download/Controller.php b/app/Http/Controllers/Download/Controller.php deleted file mode 100644 index 7908f3cc..00000000 --- a/app/Http/Controllers/Download/Controller.php +++ /dev/null @@ -1,16 +0,0 @@ -downloadService = $downloadService; - } -} diff --git a/app/Http/Controllers/Download/FavoritesController.php b/app/Http/Controllers/Download/FavoritesController.php index 2a33d0b6..e8b5e768 100644 --- a/app/Http/Controllers/Download/FavoritesController.php +++ b/app/Http/Controllers/Download/FavoritesController.php @@ -2,24 +2,25 @@ namespace App\Http\Controllers\Download; -use App\Http\Requests\Download\Request; +use App\Http\Controllers\Controller; +use App\Models\User; use App\Repositories\InteractionRepository; use App\Services\DownloadService; +use Illuminate\Contracts\Auth\Authenticatable; class FavoritesController extends Controller { - private InteractionRepository $interactionRepository; - - public function __construct(DownloadService $downloadService, InteractionRepository $interactionRepository) - { - parent::__construct($downloadService); - - $this->interactionRepository = $interactionRepository; + /** @param User $user */ + public function __construct( + private DownloadService $downloadService, + private InteractionRepository $interactionRepository, + private ?Authenticatable $user + ) { } - public function show(Request $request) + public function show() { - $songs = $this->interactionRepository->getUserFavorites($request->user()); + $songs = $this->interactionRepository->getUserFavorites($this->user); return response()->download($this->downloadService->from($songs)); } diff --git a/app/Http/Controllers/Download/PlaylistController.php b/app/Http/Controllers/Download/PlaylistController.php index d32b9b7b..8d6b84ad 100644 --- a/app/Http/Controllers/Download/PlaylistController.php +++ b/app/Http/Controllers/Download/PlaylistController.php @@ -2,10 +2,16 @@ namespace App\Http\Controllers\Download; +use App\Http\Controllers\Controller; use App\Models\Playlist; +use App\Services\DownloadService; class PlaylistController extends Controller { + public function __construct(private DownloadService $downloadService) + { + } + public function show(Playlist $playlist) { $this->authorize('owner', $playlist); diff --git a/app/Http/Controllers/Download/SongController.php b/app/Http/Controllers/Download/SongController.php index 5cd8e913..c583d12d 100644 --- a/app/Http/Controllers/Download/SongController.php +++ b/app/Http/Controllers/Download/SongController.php @@ -2,19 +2,15 @@ namespace App\Http\Controllers\Download; +use App\Http\Controllers\Controller; use App\Http\Requests\Download\SongRequest; use App\Repositories\SongRepository; use App\Services\DownloadService; class SongController extends Controller { - private SongRepository $songRepository; - - public function __construct(DownloadService $downloadService, SongRepository $songRepository) + public function __construct(private DownloadService $downloadService, private SongRepository $songRepository) { - parent::__construct($downloadService); - - $this->songRepository = $songRepository; } public function show(SongRequest $request) diff --git a/app/Http/Controllers/ITunesController.php b/app/Http/Controllers/ITunesController.php index b7c768aa..0b218483 100644 --- a/app/Http/Controllers/ITunesController.php +++ b/app/Http/Controllers/ITunesController.php @@ -10,13 +10,8 @@ use Illuminate\Http\Response; class ITunesController extends Controller { - private ITunesService $iTunesService; - private TokenManager $tokenManager; - - public function __construct(ITunesService $iTunesService, TokenManager $tokenManager) + public function __construct(private ITunesService $iTunesService, private TokenManager $tokenManager) { - $this->iTunesService = $iTunesService; - $this->tokenManager = $tokenManager; } public function viewSong(ViewSongOnITunesRequest $request, Album $album) diff --git a/app/Http/Controllers/LastfmController.php b/app/Http/Controllers/LastfmController.php index 14e73921..9b1fd251 100644 --- a/app/Http/Controllers/LastfmController.php +++ b/app/Http/Controllers/LastfmController.php @@ -11,17 +11,12 @@ use Illuminate\Http\Response; class LastfmController extends Controller { - private LastfmService $lastfm; - private TokenManager $tokenManager; - - /** @var User */ - private ?Authenticatable $currentUser; - - public function __construct(LastfmService $lastfm, TokenManager $tokenManager, ?Authenticatable $currentUser) - { - $this->lastfm = $lastfm; - $this->tokenManager = $tokenManager; - $this->currentUser = $currentUser; + /** @param User $currentUser */ + public function __construct( + private LastfmService $lastfm, + private TokenManager $tokenManager, + private ?Authenticatable $currentUser + ) { } public function connect() diff --git a/app/Http/Controllers/PlayController.php b/app/Http/Controllers/PlayController.php index a78187b0..be7bd676 100644 --- a/app/Http/Controllers/PlayController.php +++ b/app/Http/Controllers/PlayController.php @@ -8,17 +8,14 @@ use App\Models\Song; class PlayController extends Controller { - private StreamerFactory $streamerFactory; - - public function __construct(StreamerFactory $streamerFactory) + public function __construct(private StreamerFactory $streamerFactory) { - $this->streamerFactory = $streamerFactory; } public function show(SongPlayRequest $request, Song $song, ?bool $transcode = null, ?int $bitRate = null) { return $this->streamerFactory - ->createStreamer($song, $transcode, $bitRate, floatval($request->time)) + ->createStreamer($song, $transcode, $bitRate, (float) $request->time) ->stream(); } } diff --git a/app/Http/Controllers/V6/API/AlbumController.php b/app/Http/Controllers/V6/API/AlbumController.php index 9018d685..a870775f 100644 --- a/app/Http/Controllers/V6/API/AlbumController.php +++ b/app/Http/Controllers/V6/API/AlbumController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\AlbumResource; use App\Models\Album; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/AlbumSongController.php b/app/Http/Controllers/V6/API/AlbumSongController.php index 057bb593..bf71be0b 100644 --- a/app/Http/Controllers/V6/API/AlbumSongController.php +++ b/app/Http/Controllers/V6/API/AlbumSongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\SongResource; use App\Models\Album; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/ArtistController.php b/app/Http/Controllers/V6/API/ArtistController.php index 0bdd17eb..60dfe81e 100644 --- a/app/Http/Controllers/V6/API/ArtistController.php +++ b/app/Http/Controllers/V6/API/ArtistController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\ArtistResource; use App\Models\Artist; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/ArtistSongController.php b/app/Http/Controllers/V6/API/ArtistSongController.php index 9904e044..72f0196d 100644 --- a/app/Http/Controllers/V6/API/ArtistSongController.php +++ b/app/Http/Controllers/V6/API/ArtistSongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\SongResource; use App\Models\Artist; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/DataController.php b/app/Http/Controllers/V6/API/DataController.php index bb56bdb2..65f6be4e 100644 --- a/app/Http/Controllers/V6/API/DataController.php +++ b/app/Http/Controllers/V6/API/DataController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\UserResource; use App\Models\User; use App\Repositories\PlaylistRepository; diff --git a/app/Http/Controllers/V6/API/ExcerptSearchController.php b/app/Http/Controllers/V6/API/ExcerptSearchController.php index 3ca23aed..74ab5bd3 100644 --- a/app/Http/Controllers/V6/API/ExcerptSearchController.php +++ b/app/Http/Controllers/V6/API/ExcerptSearchController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Controllers\V6\Requests\SearchRequest; use App\Http\Resources\ExcerptSearchResource; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/FavoriteSongController.php b/app/Http/Controllers/V6/API/FavoriteSongController.php index 3ea99d00..a3cf96ce 100644 --- a/app/Http/Controllers/V6/API/FavoriteSongController.php +++ b/app/Http/Controllers/V6/API/FavoriteSongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\SongResource; use App\Models\User; use App\Repositories\SongRepository; diff --git a/app/Http/Controllers/V6/API/FetchAlbumInformationController.php b/app/Http/Controllers/V6/API/FetchAlbumInformationController.php index 139d7d7c..41675a88 100644 --- a/app/Http/Controllers/V6/API/FetchAlbumInformationController.php +++ b/app/Http/Controllers/V6/API/FetchAlbumInformationController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Models\Album; use App\Services\MediaInformationService; diff --git a/app/Http/Controllers/V6/API/FetchArtistInformationController.php b/app/Http/Controllers/V6/API/FetchArtistInformationController.php index 704a28fe..12939917 100644 --- a/app/Http/Controllers/V6/API/FetchArtistInformationController.php +++ b/app/Http/Controllers/V6/API/FetchArtistInformationController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Models\Artist; use App\Services\MediaInformationService; diff --git a/app/Http/Controllers/V6/API/OverviewController.php b/app/Http/Controllers/V6/API/OverviewController.php index d33d10d3..09967660 100644 --- a/app/Http/Controllers/V6/API/OverviewController.php +++ b/app/Http/Controllers/V6/API/OverviewController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\AlbumResource; use App\Http\Resources\ArtistResource; use App\Http\Resources\SongResource; diff --git a/app/Http/Controllers/V6/API/PlayCountController.php b/app/Http/Controllers/V6/API/PlayCountController.php index d8ebc64b..d05900a9 100644 --- a/app/Http/Controllers/V6/API/PlayCountController.php +++ b/app/Http/Controllers/V6/API/PlayCountController.php @@ -3,12 +3,20 @@ namespace App\Http\Controllers\V6\API; use App\Events\SongStartedPlaying; -use App\Http\Controllers\API\Interaction\Controller; +use App\Http\Controllers\Controller; use App\Http\Requests\API\Interaction\StorePlayCountRequest; use App\Http\Resources\InteractionResource; +use App\Models\User; +use App\Services\InteractionService; +use Illuminate\Contracts\Auth\Authenticatable; class PlayCountController extends Controller { + /** @param User $user */ + public function __construct(private InteractionService $interactionService, private ?Authenticatable $user) + { + } + public function store(StorePlayCountRequest $request) { $interaction = $this->interactionService->increasePlayCount($request->song, $this->user); diff --git a/app/Http/Controllers/V6/API/PlaylistSongController.php b/app/Http/Controllers/V6/API/PlaylistSongController.php index 3e5c3014..720bba9f 100644 --- a/app/Http/Controllers/V6/API/PlaylistSongController.php +++ b/app/Http/Controllers/V6/API/PlaylistSongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Controllers\V6\Requests\AddSongsToPlaylistRequest; use App\Http\Controllers\V6\Requests\RemoveSongsFromPlaylistRequest; use App\Http\Resources\SongResource; diff --git a/app/Http/Controllers/V6/API/QueueController.php b/app/Http/Controllers/V6/API/QueueController.php index 32c49690..12a60749 100644 --- a/app/Http/Controllers/V6/API/QueueController.php +++ b/app/Http/Controllers/V6/API/QueueController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Controllers\V6\Requests\QueueFetchSongRequest; use App\Http\Resources\SongResource; use App\Models\User; diff --git a/app/Http/Controllers/V6/API/RecentlyPlayedSongController.php b/app/Http/Controllers/V6/API/RecentlyPlayedSongController.php index 9e51a08e..d2c4e189 100644 --- a/app/Http/Controllers/V6/API/RecentlyPlayedSongController.php +++ b/app/Http/Controllers/V6/API/RecentlyPlayedSongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Resources\SongResource; use App\Models\User; use App\Repositories\SongRepository; diff --git a/app/Http/Controllers/V6/API/SongController.php b/app/Http/Controllers/V6/API/SongController.php index 97d15683..c91c1928 100644 --- a/app/Http/Controllers/V6/API/SongController.php +++ b/app/Http/Controllers/V6/API/SongController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Controllers\V6\Requests\SongListRequest; use App\Http\Resources\SongResource; use App\Models\Song; diff --git a/app/Http/Controllers/V6/API/SongSearchController.php b/app/Http/Controllers/V6/API/SongSearchController.php index 754d4f0e..343f55da 100644 --- a/app/Http/Controllers/V6/API/SongSearchController.php +++ b/app/Http/Controllers/V6/API/SongSearchController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\V6\API; -use App\Http\Controllers\API\Controller; +use App\Http\Controllers\Controller; use App\Http\Controllers\V6\Requests\SearchRequest; use App\Http\Resources\SongResource; use App\Models\User; diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 5e400e68..d1b495e4 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -8,11 +8,8 @@ use Illuminate\Http\Request; class Authenticate { - protected Guard $auth; - - public function __construct(Guard $auth) + public function __construct(protected Guard $auth) { - $this->auth = $auth; } public function handle(Request $request, Closure $next) // @phpcs:ignore diff --git a/app/Http/Middleware/ForceHttps.php b/app/Http/Middleware/ForceHttps.php index ff6e3638..eab93658 100644 --- a/app/Http/Middleware/ForceHttps.php +++ b/app/Http/Middleware/ForceHttps.php @@ -8,11 +8,8 @@ use Illuminate\Routing\UrlGenerator; class ForceHttps { - private UrlGenerator $url; - - public function __construct(UrlGenerator $url) + public function __construct(private UrlGenerator $url) { - $this->url = $url; } public function handle(Request $request, Closure $next) // @phpcs:ignore diff --git a/app/Http/Middleware/ObjectStorageAuthenticate.php b/app/Http/Middleware/ObjectStorageAuthenticate.php index 9ebc1caf..2ea5c1f2 100644 --- a/app/Http/Middleware/ObjectStorageAuthenticate.php +++ b/app/Http/Middleware/ObjectStorageAuthenticate.php @@ -4,6 +4,7 @@ namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; +use Illuminate\Http\Response; /** * Authenticate requests from Object Storage services (like S3). @@ -13,9 +14,7 @@ class ObjectStorageAuthenticate { public function handle(Request $request, Closure $next) // @phpcs:ignore { - if ($request->appKey !== config('app.key')) { - return response('Unauthorized.', 401); - } + abort_unless($request->get('appKey') === config('app.key'), Response::HTTP_UNAUTHORIZED); return $next($request); } diff --git a/app/Http/Requests/API/AlbumCoverUpdateRequest.php b/app/Http/Requests/API/AlbumCoverUpdateRequest.php index bef6fff4..af6bfe49 100644 --- a/app/Http/Requests/API/AlbumCoverUpdateRequest.php +++ b/app/Http/Requests/API/AlbumCoverUpdateRequest.php @@ -3,7 +3,7 @@ namespace App\Http\Requests\API; /** @property string $cover */ -class AlbumCoverUpdateRequest extends AbstractMediaImageUpdateRequest +class AlbumCoverUpdateRequest extends MediaImageUpdateRequest { protected function getImageFieldName(): string { diff --git a/app/Http/Requests/API/ArtistImageUpdateRequest.php b/app/Http/Requests/API/ArtistImageUpdateRequest.php index fb9778bb..3a9f8cdb 100644 --- a/app/Http/Requests/API/ArtistImageUpdateRequest.php +++ b/app/Http/Requests/API/ArtistImageUpdateRequest.php @@ -3,7 +3,7 @@ namespace App\Http\Requests\API; /** @property string $image */ -class ArtistImageUpdateRequest extends AbstractMediaImageUpdateRequest +class ArtistImageUpdateRequest extends MediaImageUpdateRequest { protected function getImageFieldName(): string { diff --git a/app/Http/Requests/API/Interaction/Request.php b/app/Http/Requests/API/Interaction/Request.php index b3e59c93..128094b4 100644 --- a/app/Http/Requests/API/Interaction/Request.php +++ b/app/Http/Requests/API/Interaction/Request.php @@ -4,6 +4,6 @@ namespace App\Http\Requests\API\Interaction; use App\Http\Requests\API\Request as BaseRequest; -class Request extends BaseRequest +abstract class Request extends BaseRequest { } diff --git a/app/Http/Requests/API/AbstractMediaImageUpdateRequest.php b/app/Http/Requests/API/MediaImageUpdateRequest.php similarity index 92% rename from app/Http/Requests/API/AbstractMediaImageUpdateRequest.php rename to app/Http/Requests/API/MediaImageUpdateRequest.php index 9d2b98ac..389d73ba 100644 --- a/app/Http/Requests/API/AbstractMediaImageUpdateRequest.php +++ b/app/Http/Requests/API/MediaImageUpdateRequest.php @@ -4,7 +4,7 @@ namespace App\Http\Requests\API; use App\Rules\ImageData; -abstract class AbstractMediaImageUpdateRequest extends Request +abstract class MediaImageUpdateRequest extends Request { public function authorize(): bool { diff --git a/app/Http/Requests/API/Request.php b/app/Http/Requests/API/Request.php index 72a024b5..be9c8926 100644 --- a/app/Http/Requests/API/Request.php +++ b/app/Http/Requests/API/Request.php @@ -2,8 +2,8 @@ namespace App\Http\Requests\API; -use App\Http\Requests\AbstractRequest; +use App\Http\Requests\Request as BaseRequest; -class Request extends AbstractRequest +abstract class Request extends BaseRequest { } diff --git a/app/Http/Requests/API/UploadRequest.php b/app/Http/Requests/API/UploadRequest.php index 34fea7c0..9bc0ede0 100644 --- a/app/Http/Requests/API/UploadRequest.php +++ b/app/Http/Requests/API/UploadRequest.php @@ -2,11 +2,11 @@ namespace App\Http\Requests\API; -use App\Http\Requests\AbstractRequest; +use App\Http\Requests\Request; use Illuminate\Http\UploadedFile; /** @property UploadedFile $file */ -class UploadRequest extends AbstractRequest +class UploadRequest extends Request { /** @return array */ public function rules(): array diff --git a/app/Http/Requests/Download/Request.php b/app/Http/Requests/Download/Request.php index d2f9d1b1..b656d471 100644 --- a/app/Http/Requests/Download/Request.php +++ b/app/Http/Requests/Download/Request.php @@ -4,7 +4,7 @@ namespace App\Http\Requests\Download; use App\Http\Requests\API\Request as BaseRequest; -class Request extends BaseRequest +abstract class Request extends BaseRequest { public function authorize(): bool { diff --git a/app/Http/Requests/AbstractRequest.php b/app/Http/Requests/Request.php similarity index 83% rename from app/Http/Requests/AbstractRequest.php rename to app/Http/Requests/Request.php index 91a7ddb3..7e51f4ff 100644 --- a/app/Http/Requests/AbstractRequest.php +++ b/app/Http/Requests/Request.php @@ -4,7 +4,7 @@ namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; -abstract class AbstractRequest extends FormRequest +abstract class Request extends FormRequest { public function authorize(): bool { diff --git a/app/Http/Requests/SongPlayRequest.php b/app/Http/Requests/SongPlayRequest.php index 737f87c0..d571e49c 100644 --- a/app/Http/Requests/SongPlayRequest.php +++ b/app/Http/Requests/SongPlayRequest.php @@ -3,9 +3,9 @@ namespace App\Http\Requests; /** - * @property float $time + * @property float|string $time * @property string $api_token */ -class SongPlayRequest extends AbstractRequest +class SongPlayRequest extends Request { } diff --git a/app/Http/Requests/SpotifyCallbackRequest.php b/app/Http/Requests/SpotifyCallbackRequest.php index 1b4e912d..2478eebb 100644 --- a/app/Http/Requests/SpotifyCallbackRequest.php +++ b/app/Http/Requests/SpotifyCallbackRequest.php @@ -6,6 +6,6 @@ namespace App\Http\Requests; * @property-read string $state * @property-read string $code */ -class SpotifyCallbackRequest extends AbstractRequest +class SpotifyCallbackRequest extends Request { } diff --git a/app/Listeners/LoveTrackOnLastfm.php b/app/Listeners/LoveTrackOnLastfm.php index 7a074fe6..628a03b8 100644 --- a/app/Listeners/LoveTrackOnLastfm.php +++ b/app/Listeners/LoveTrackOnLastfm.php @@ -9,18 +9,15 @@ use Illuminate\Contracts\Queue\ShouldQueue; class LoveTrackOnLastfm implements ShouldQueue { - private LastfmService $lastfm; - - public function __construct(LastfmService $lastfm) + public function __construct(private LastfmService $lastfm) { - $this->lastfm = $lastfm; } public function handle(SongLikeToggled $event): void { if ( !$this->lastfm->enabled() || - !$event->user->lastfm_session_key || + !$event->interaction->user->lastfm_session_key || $event->interaction->song->artist->is_unknown ) { return; @@ -28,7 +25,7 @@ class LoveTrackOnLastfm implements ShouldQueue $this->lastfm->toggleLoveTrack( LastfmLoveTrackParameters::make($event->interaction->song->title, $event->interaction->song->artist->name), - $event->user->lastfm_session_key, + $event->interaction->user->lastfm_session_key, $event->interaction->liked ); } diff --git a/app/Providers/StreamerServiceProvider.php b/app/Providers/StreamerServiceProvider.php index 112e463c..9ab1a072 100644 --- a/app/Providers/StreamerServiceProvider.php +++ b/app/Providers/StreamerServiceProvider.php @@ -17,16 +17,11 @@ class StreamerServiceProvider extends ServiceProvider public function register(): void { $this->app->bind(DirectStreamerInterface::class, static function (): DirectStreamerInterface { - switch (config('koel.streaming.method')) { - case 'x-sendfile': - return new XSendFileStreamer(); - - case 'x-accel-redirect': - return new XAccelRedirectStreamer(); - - default: - return new PhpStreamer(); - } + return match (config('koel.streaming.method')) { + 'x-sendfile' => new XSendFileStreamer(), + 'x-accel-redirect' => new XAccelRedirectStreamer(), + default => new PhpStreamer(), + }; }); $this->app->bind(TranscodingStreamerInterface::class, TranscodingStreamer::class); diff --git a/app/Repositories/AlbumRepository.php b/app/Repositories/AlbumRepository.php index 737a2d9f..0f817a9c 100644 --- a/app/Repositories/AlbumRepository.php +++ b/app/Repositories/AlbumRepository.php @@ -7,7 +7,7 @@ use App\Models\User; use App\Repositories\Traits\Searchable; use Illuminate\Support\Collection; -class AlbumRepository extends AbstractRepository +class AlbumRepository extends Repository { use Searchable; diff --git a/app/Repositories/ArtistRepository.php b/app/Repositories/ArtistRepository.php index bc799994..08acd661 100644 --- a/app/Repositories/ArtistRepository.php +++ b/app/Repositories/ArtistRepository.php @@ -7,7 +7,7 @@ use App\Models\User; use App\Repositories\Traits\Searchable; use Illuminate\Database\Eloquent\Collection; -class ArtistRepository extends AbstractRepository +class ArtistRepository extends Repository { use Searchable; diff --git a/app/Repositories/InteractionRepository.php b/app/Repositories/InteractionRepository.php index ba1ec0d2..07d46dc1 100644 --- a/app/Repositories/InteractionRepository.php +++ b/app/Repositories/InteractionRepository.php @@ -8,7 +8,7 @@ use App\Repositories\Traits\ByCurrentUser; use Illuminate\Database\Query\Builder; use Illuminate\Support\Collection; -class InteractionRepository extends AbstractRepository +class InteractionRepository extends Repository { use ByCurrentUser; diff --git a/app/Repositories/PlaylistRepository.php b/app/Repositories/PlaylistRepository.php index 79f000c6..538205dc 100644 --- a/app/Repositories/PlaylistRepository.php +++ b/app/Repositories/PlaylistRepository.php @@ -6,7 +6,7 @@ use App\Models\Playlist; use App\Repositories\Traits\ByCurrentUser; use Illuminate\Support\Collection; -class PlaylistRepository extends AbstractRepository +class PlaylistRepository extends Repository { use ByCurrentUser; diff --git a/app/Repositories/AbstractRepository.php b/app/Repositories/Repository.php similarity index 95% rename from app/Repositories/AbstractRepository.php rename to app/Repositories/Repository.php index 0c372212..1faaa30c 100644 --- a/app/Repositories/AbstractRepository.php +++ b/app/Repositories/Repository.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Throwable; -abstract class AbstractRepository implements RepositoryInterface +abstract class Repository implements RepositoryInterface { private string $modelClass; protected Model $model; diff --git a/app/Repositories/SettingRepository.php b/app/Repositories/SettingRepository.php index dccf29c5..0ba93e14 100644 --- a/app/Repositories/SettingRepository.php +++ b/app/Repositories/SettingRepository.php @@ -4,7 +4,7 @@ namespace App\Repositories; use App\Models\Setting; -class SettingRepository extends AbstractRepository +class SettingRepository extends Repository { /** @return array */ public function getAllAsKeyValueArray(): array diff --git a/app/Repositories/SongRepository.php b/app/Repositories/SongRepository.php index ed015edb..af02a24c 100644 --- a/app/Repositories/SongRepository.php +++ b/app/Repositories/SongRepository.php @@ -14,7 +14,7 @@ use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Support\Collection; use Webmozart\Assert\Assert; -class SongRepository extends AbstractRepository +class SongRepository extends Repository { use Searchable; diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index f922cb43..0b1fc344 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -2,6 +2,6 @@ namespace App\Repositories; -class UserRepository extends AbstractRepository +class UserRepository extends Repository { } diff --git a/app/Services/AbstractApiClient.php b/app/Services/ApiClient.php similarity index 99% rename from app/Services/AbstractApiClient.php rename to app/Services/ApiClient.php index 1d54f63f..072cad01 100644 --- a/app/Services/AbstractApiClient.php +++ b/app/Services/ApiClient.php @@ -26,7 +26,7 @@ use Webmozart\Assert\Assert; * @method Promise headAsync($uri, array $data = [], bool $appendKey = true) * @method Promise deleteAsync($uri, array $data = [], bool $appendKey = true) */ -abstract class AbstractApiClient +abstract class ApiClient { private const MAGIC_METHODS = [ 'get', diff --git a/app/Services/ApplicationInformationService.php b/app/Services/ApplicationInformationService.php index 75067933..a9e53524 100644 --- a/app/Services/ApplicationInformationService.php +++ b/app/Services/ApplicationInformationService.php @@ -11,15 +11,8 @@ class ApplicationInformationService { private const CACHE_KEY = 'latestKoelVersion'; - private Client $client; - private Cache $cache; - private Logger $logger; - - public function __construct(Client $client, Cache $cache, Logger $logger) + public function __construct(private Client $client, private Cache $cache, private Logger $logger) { - $this->client = $client; - $this->cache = $cache; - $this->logger = $logger; } /** diff --git a/app/Services/DownloadService.php b/app/Services/DownloadService.php index 92fbb0fe..2341f88c 100644 --- a/app/Services/DownloadService.php +++ b/app/Services/DownloadService.php @@ -13,40 +13,33 @@ use InvalidArgumentException; class DownloadService { - private S3Service $s3Service; - - public function __construct(S3Service $s3Service) + public function __construct(private S3Service $s3Service) { - $this->s3Service = $s3Service; } /** * Generic method to generate a download archive from various source types. * - * @param Song|Collection|Album|Artist|Playlist $mixed - * - * @throws InvalidArgumentException - * * @return string Full path to the generated archive */ - public function from($mixed): string + public function from(Playlist|Song|Album|Artist|Collection $downloadable): string { - switch (get_class($mixed)) { + switch (get_class($downloadable)) { case Song::class: - return $this->fromSong($mixed); + return $this->fromSong($downloadable); case Collection::class: case EloquentCollection::class: - return $this->fromMultipleSongs($mixed); + return $this->fromMultipleSongs($downloadable); case Album::class: - return $this->fromAlbum($mixed); + return $this->fromAlbum($downloadable); case Artist::class: - return $this->fromArtist($mixed); + return $this->fromArtist($downloadable); case Playlist::class: - return $this->fromPlaylist($mixed); + return $this->fromPlaylist($downloadable); } throw new InvalidArgumentException('Unsupported download type.'); diff --git a/app/Services/ITunesService.php b/app/Services/ITunesService.php index aa0a597f..80bb3bc4 100644 --- a/app/Services/ITunesService.php +++ b/app/Services/ITunesService.php @@ -4,7 +4,7 @@ namespace App\Services; use Throwable; -class ITunesService extends AbstractApiClient implements ApiConsumerInterface +class ITunesService extends ApiClient implements ApiConsumerInterface { /** * Determines whether to use iTunes services. diff --git a/app/Services/InteractionService.php b/app/Services/InteractionService.php index 3e63deef..100b6747 100644 --- a/app/Services/InteractionService.php +++ b/app/Services/InteractionService.php @@ -33,7 +33,7 @@ class InteractionService } /** - * Like or unlike a song on behalf of a user. + * Like or unlike a song as a user. * * @return Interaction the affected Interaction object */ diff --git a/app/Services/LastfmService.php b/app/Services/LastfmService.php index 2e1ef4d6..10d5abe7 100644 --- a/app/Services/LastfmService.php +++ b/app/Services/LastfmService.php @@ -13,7 +13,7 @@ use GuzzleHttp\Promise\Utils; use Illuminate\Support\Collection; use Throwable; -class LastfmService extends AbstractApiClient implements ApiConsumerInterface +class LastfmService extends ApiClient implements ApiConsumerInterface { /** * Override the key param, since, again, Last.fm wants to be different. @@ -143,8 +143,8 @@ class LastfmService extends AbstractApiClient implements ApiConsumerInterface { try { $this->post('/', $this->buildAuthCallParams([ - 'track' => $params->getTrackName(), - 'artist' => $params->getArtistName(), + 'track' => $params->trackName, + 'artist' => $params->artistName, 'sk' => $sessionKey, 'method' => $love ? 'track.love' : 'track.unlove', ]), false); @@ -160,8 +160,8 @@ class LastfmService extends AbstractApiClient implements ApiConsumerInterface { $promises = $parameterCollection->map( fn (LastfmLoveTrackParameters $params): Promise => $this->postAsync('/', $this->buildAuthCallParams([ - 'track' => $params->getTrackName(), - 'artist' => $params->getArtistName(), + 'track' => $params->trackName, + 'artist' => $params->artistName, 'sk' => $sessionKey, 'method' => $love ? 'track.love' : 'track.unlove', ]), false) diff --git a/app/Services/MediaCacheService.php b/app/Services/MediaCacheService.php index 11aeb435..506a9163 100644 --- a/app/Services/MediaCacheService.php +++ b/app/Services/MediaCacheService.php @@ -11,11 +11,8 @@ class MediaCacheService { private const CACHE_KEY = 'media_cache'; - private Cache $cache; - - public function __construct(Cache $cache) + public function __construct(private Cache $cache) { - $this->cache = $cache; } /** diff --git a/app/Services/PlaylistService.php b/app/Services/PlaylistService.php index 220f6a91..d7eb09b1 100644 --- a/app/Services/PlaylistService.php +++ b/app/Services/PlaylistService.php @@ -31,4 +31,10 @@ class PlaylistService { $playlist->songs()->detach($songIds); } + + /** @deprecated */ + public function populatePlaylist(Playlist $playlist, array $songIds): void + { + $playlist->songs()->sync($songIds); + } } diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index 6873279b..58b321a5 100644 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -16,18 +16,11 @@ class SearchService { public const DEFAULT_EXCERPT_RESULT_COUNT = 6; - private SongRepository $songRepository; - private AlbumRepository $albumRepository; - private ArtistRepository $artistRepository; - public function __construct( - SongRepository $songRepository, - AlbumRepository $albumRepository, - ArtistRepository $artistRepository + private SongRepository $songRepository, + private AlbumRepository $albumRepository, + private ArtistRepository $artistRepository ) { - $this->songRepository = $songRepository; - $this->albumRepository = $albumRepository; - $this->artistRepository = $artistRepository; } /** @return array */ diff --git a/app/Services/SongService.php b/app/Services/SongService.php index 7d48b9cb..27bfd04a 100644 --- a/app/Services/SongService.php +++ b/app/Services/SongService.php @@ -26,11 +26,9 @@ class SongService /** @var Song|null $song */ $song = Song::with('album', 'album.artist', 'artist')->find($id); - if (!$song) { - continue; + if ($song) { + $updatedSongs->push($this->updateSong($song, $data)); } - - $updatedSongs->push($this->updateSong($song, $data)); } }); diff --git a/app/Services/Streamers/S3Streamer.php b/app/Services/Streamers/S3Streamer.php index 4872b0ba..89f92b79 100644 --- a/app/Services/Streamers/S3Streamer.php +++ b/app/Services/Streamers/S3Streamer.php @@ -8,13 +8,9 @@ use Illuminate\Routing\Redirector; class S3Streamer extends Streamer implements ObjectStorageStreamerInterface { - private S3Service $s3Service; - - public function __construct(S3Service $s3Service) + public function __construct(private S3Service $s3Service) { parent::__construct(); - - $this->s3Service = $s3Service; } /** diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 3ae71fd6..05c0dd9d 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -23,12 +23,17 @@ class UserService public function updateUser(User $user, string $name, string $email, string|null $password, bool $isAdmin): User { - $user->update([ + $data = [ 'name' => $name, 'email' => $email, - 'password' => $password ? $this->hash->make($password) : $user->password, 'is_admin' => $isAdmin, - ]); + ]; + + if ($password) { + $data['password'] = $this->hash->make($password); + } + + $user->update($data); return $user; } diff --git a/app/Services/YouTubeService.php b/app/Services/YouTubeService.php index c0d5c7e5..652c4875 100644 --- a/app/Services/YouTubeService.php +++ b/app/Services/YouTubeService.php @@ -5,7 +5,7 @@ namespace App\Services; use App\Models\Song; use Throwable; -class YouTubeService extends AbstractApiClient implements ApiConsumerInterface +class YouTubeService extends ApiClient implements ApiConsumerInterface { /** * Determine if our application is using YouTube. diff --git a/app/Values/LastfmLoveTrackParameters.php b/app/Values/LastfmLoveTrackParameters.php index 2395f0de..5dacf0d0 100644 --- a/app/Values/LastfmLoveTrackParameters.php +++ b/app/Values/LastfmLoveTrackParameters.php @@ -4,27 +4,12 @@ namespace App\Values; final class LastfmLoveTrackParameters { - private string $trackName; - private string $artistName; - - private function __construct(string $trackName, string $artistName) + private function __construct(public string $trackName, public string $artistName) { - $this->trackName = $trackName; - $this->artistName = $artistName; } public static function make(string $trackName, string $artistName): self { return new self($trackName, $artistName); } - - public function getTrackName(): string - { - return $this->trackName; - } - - public function getArtistName(): string - { - return $this->artistName; - } } diff --git a/app/Values/SmartPlaylistRuleGroup.php b/app/Values/SmartPlaylistRuleGroup.php index 6a521ce7..e5156268 100644 --- a/app/Values/SmartPlaylistRuleGroup.php +++ b/app/Values/SmartPlaylistRuleGroup.php @@ -3,6 +3,7 @@ namespace App\Values; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Throwable; @@ -23,13 +24,11 @@ final class SmartPlaylistRuleGroup implements Arrayable public static function create(array $jsonArray): self { - $id = $jsonArray['id'] ?? null; - $rules = collect(array_map(static function (array $rawRuleConfig) { return SmartPlaylistRule::create($rawRuleConfig); }, $jsonArray['rules'])); - return new self($id, $rules); + return new self(Arr::get($jsonArray, 'id'), $rules); } /** @return array */ diff --git a/app/Values/UserPreferences.php b/app/Values/UserPreferences.php index 1fd0676e..6c100a18 100644 --- a/app/Values/UserPreferences.php +++ b/app/Values/UserPreferences.php @@ -7,11 +7,8 @@ use JsonSerializable; final class UserPreferences implements Arrayable, JsonSerializable { - public ?string $lastFmSessionKey = null; - - private function __construct(?string $lastFmSessionKey) + private function __construct(public ?string $lastFmSessionKey = null) { - $this->lastFmSessionKey = $lastFmSessionKey; } public static function make(?string $lastFmSessionKey = null): self diff --git a/tests/Feature/AlbumThumbnailTest.php b/tests/Feature/AlbumThumbnailTest.php index 8fc973f5..06b7ea64 100644 --- a/tests/Feature/AlbumThumbnailTest.php +++ b/tests/Feature/AlbumThumbnailTest.php @@ -5,10 +5,11 @@ namespace Tests\Feature; use App\Models\Album; use App\Services\MediaMetadataService; use Mockery; +use Mockery\MockInterface; class AlbumThumbnailTest extends TestCase { - private $mediaMetadataService; + private MockInterface $mediaMetadataService; public function setUp(): void { diff --git a/tests/Feature/PlaylistSongTest.php b/tests/Feature/PlaylistSongTest.php index f2cfa6e5..4380b09b 100644 --- a/tests/Feature/PlaylistSongTest.php +++ b/tests/Feature/PlaylistSongTest.php @@ -8,13 +8,6 @@ use App\Models\User; class PlaylistSongTest extends TestCase { - public function setUp(): void - { - parent::setUp(); - - static::createSampleMediaSet(); - } - public function testUpdatePlaylistSongs(): void { $this->doTestUpdatePlaylistSongs(); @@ -40,7 +33,7 @@ class PlaylistSongTest extends TestCase $path = $useDeprecatedRoute ? "api/playlist/$playlist->id/sync" : "api/playlist/$playlist->id/songs"; - $this->putAs($path, ['songs' => $toRemainSongs->pluck('id')->all()], $user)->assertOk(); + $this->putAs($path, ['songs' => $toRemainSongs->pluck('id')->all()], $user)->assertNoContent(); self::assertEqualsCanonicalizing( $toRemainSongs->pluck('id')->all(), diff --git a/tests/Feature/YouTubeTest.php b/tests/Feature/YouTubeTest.php index 346a7668..e8d1bdbd 100644 --- a/tests/Feature/YouTubeTest.php +++ b/tests/Feature/YouTubeTest.php @@ -5,10 +5,11 @@ namespace Tests\Feature; use App\Models\Song; use App\Services\YouTubeService; use Mockery; +use Mockery\MockInterface; class YouTubeTest extends TestCase { - private $youTubeService; + private MockInterface $youTubeService; public function setUp(): void { diff --git a/tests/Unit/Http/Middleware/ForceHttpsTest.php b/tests/Unit/Http/Middleware/ForceHttpsTest.php index 13b92ef4..04293c2f 100644 --- a/tests/Unit/Http/Middleware/ForceHttpsTest.php +++ b/tests/Unit/Http/Middleware/ForceHttpsTest.php @@ -6,12 +6,14 @@ use App\Http\Middleware\ForceHttps; use Illuminate\Http\Request; use Illuminate\Routing\UrlGenerator; use Mockery; +use Mockery\LegacyMockInterface; +use Mockery\MockInterface; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; class ForceHttpsTest extends TestCase { - private $url; + private LegacyMockInterface|UrlGenerator|MockInterface $url; private ForceHttps $middleware; public function setUp(): void @@ -40,10 +42,7 @@ class ForceHttpsTest extends TestCase ); $response = Mockery::mock(Response::class); - - $next = static function () use ($response) { - return $response; - }; + $next = static fn () => $response; self::assertSame($response, $this->middleware->handle($request, $next)); } @@ -58,10 +57,7 @@ class ForceHttpsTest extends TestCase $request->shouldReceive('setTrustedProxies')->never(); $response = Mockery::mock(Response::class); - - $next = static function () use ($response) { - return $response; - }; + $next = static fn () => $response; self::assertSame($response, $this->middleware->handle($request, $next)); } diff --git a/tests/Unit/Listeners/LoveTrackOnLastFmTest.php b/tests/Unit/Listeners/LoveTrackOnLastFmTest.php index 26a21e74..cc7d60f3 100644 --- a/tests/Unit/Listeners/LoveTrackOnLastFmTest.php +++ b/tests/Unit/Listeners/LoveTrackOnLastFmTest.php @@ -5,7 +5,6 @@ namespace Tests\Unit\Listeners; use App\Events\SongLikeToggled; use App\Listeners\LoveTrackOnLastfm; use App\Models\Interaction; -use App\Models\User; use App\Services\LastfmService; use App\Values\LastfmLoveTrackParameters; use Mockery; @@ -15,9 +14,6 @@ class LoveTrackOnLastFmTest extends TestCase { public function testHandle(): void { - /** @var User $user */ - $user = User::factory()->create(); - /** @var Interaction $interaction */ $interaction = Interaction::factory()->create(); @@ -25,15 +21,15 @@ class LoveTrackOnLastFmTest extends TestCase $lastfm->shouldReceive('toggleLoveTrack') ->with( Mockery::on(static function (LastfmLoveTrackParameters $params) use ($interaction): bool { - self::assertSame($interaction->song->title, $params->getTrackName()); - self::assertSame($interaction->song->artist->name, $params->getArtistName()); + self::assertSame($interaction->song->title, $params->trackName); + self::assertSame($interaction->song->artist->name, $params->artistName); return true; }), - $user->lastfm_session_key, + $interaction->user->lastfm_session_key, $interaction->liked ); - (new LoveTrackOnLastfm($lastfm))->handle(new SongLikeToggled($interaction, $user)); + (new LoveTrackOnLastfm($lastfm))->handle(new SongLikeToggled($interaction)); } } diff --git a/tests/Integration/Models/AlbumTest.php b/tests/Unit/Models/AlbumTest.php similarity index 97% rename from tests/Integration/Models/AlbumTest.php rename to tests/Unit/Models/AlbumTest.php index 72baa578..887bd78c 100644 --- a/tests/Integration/Models/AlbumTest.php +++ b/tests/Unit/Models/AlbumTest.php @@ -1,6 +1,6 @@