From 67186e8d3e5b4592787cb640468d9fcf09abd5d8 Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 18 Apr 2024 16:36:28 +0200 Subject: [PATCH] chore: make properties readonly --- .../Commands/ActivateLicenseCommand.php | 2 +- .../Commands/Admin/ChangePasswordCommand.php | 2 +- .../Commands/CheckLicenseStatusCommand.php | 2 +- .../Commands/DeactivateLicenseCommand.php | 6 +- app/Console/Commands/InitCommand.php | 8 +- app/Console/Commands/PruneLibraryCommand.php | 2 +- app/Console/Commands/ScanCommand.php | 16 +- .../Storage/SetupDropboxStorageCommand.php | 2 +- .../Storage/SetupLocalStorageCommand.php | 2 +- .../Storage/SetupS3StorageCommand.php | 2 +- app/Filesystems/DropboxFilesystem.php | 2 +- app/Http/Controllers/API/AlbumController.php | 2 +- .../Controllers/API/AlbumSongController.php | 6 +- .../Controllers/API/ArtistAlbumController.php | 2 +- app/Http/Controllers/API/ArtistController.php | 2 +- .../Controllers/API/ArtistSongController.php | 6 +- app/Http/Controllers/API/GenreController.php | 2 +- .../Controllers/API/LambdaSongController.php | 2 +- .../PlaylistCollaboratorController.php | 6 +- .../Controllers/API/PlaylistController.php | 8 +- .../API/PlaylistFolderController.php | 6 +- .../API/PlaylistFolderPlaylistController.php | 2 +- .../API/PlaylistSongController.php | 12 +- .../Controllers/API/ProfileController.php | 8 +- .../Controllers/API/QueueStateController.php | 2 +- .../Controllers/API/SettingController.php | 6 +- app/Http/Controllers/API/SongController.php | 12 +- app/Http/Controllers/API/UserController.php | 6 +- .../API/UserInvitationController.php | 10 +- app/Http/Controllers/LastfmController.php | 6 +- .../Lastfm/Auth/LastfmAuthenticator.php | 2 +- .../Lastfm/Requests/GetAlbumInfoRequest.php | 2 +- .../Lastfm/Requests/GetArtistInfoRequest.php | 2 +- .../Lastfm/Requests/GetSessionKeyRequest.php | 2 +- .../Lastfm/Requests/ScrobbleRequest.php | 7 +- .../Requests/ToggleLoveTrackRequest.php | 2 +- .../Requests/UpdateNowPlayingRequest.php | 2 +- .../Requests/ActivateLicenseRequest.php | 2 +- .../Requests/DeactivateLicenseRequest.php | 2 +- .../Requests/ValidateLicenseRequest.php | 2 +- .../Integrations/Spotify/SpotifyClient.php | 7 +- .../YouTube/Requests/SearchVideosRequest.php | 2 +- .../iTunes/Requests/GetTrackRequest.php | 2 +- app/Http/Resources/AlbumResource.php | 2 +- app/Http/Resources/ArtistResource.php | 2 +- app/Http/Resources/ExcerptSearchResource.php | 2 +- app/Http/Resources/GenreResource.php | 2 +- app/Http/Resources/InteractionResource.php | 2 +- .../PlaylistCollaborationTokenResource.php | 2 +- .../PlaylistCollaboratorResource.php | 2 +- app/Http/Resources/PlaylistFolderResource.php | 2 +- app/Http/Resources/PlaylistResource.php | 2 +- app/Http/Resources/QueueStateResource.php | 2 +- app/Http/Resources/UserProspectResource.php | 2 +- app/Http/Resources/UserResource.php | 2 +- .../DeleteNonExistingRecordsPostScan.php | 2 +- app/Listeners/LoveMultipleTracksOnLastfm.php | 2 +- app/Listeners/LoveTrackOnLastfm.php | 2 +- app/Listeners/MakePlaylistSongsPublic.php | 2 +- app/Listeners/PruneLibrary.php | 2 +- .../UnloveMultipleTracksOnLastfm.php | 2 +- app/Listeners/UpdateLastfmNowPlaying.php | 2 +- app/Mail/UserInvite.php | 2 +- app/Rules/AllPlaylistsAreAccessibleBy.php | 2 +- app/Services/ApiClients/ApiClient.php | 159 ------------------ app/Services/ApiClients/ITunesClient.php | 21 --- .../ApplicationInformationService.php | 2 +- app/Services/AuthenticationService.php | 8 +- app/Services/FileScanner.php | 12 +- app/Services/ITunesService.php | 2 +- app/Services/ImageWriter.php | 2 +- app/Services/LastfmService.php | 2 +- app/Services/LicenseService.php | 2 +- app/Services/MediaInformationService.php | 6 +- app/Services/MediaMetadataService.php | 6 +- app/Services/MediaScanner.php | 10 +- app/Services/PlaylistService.php | 2 +- app/Services/ProxyAuthService.php | 2 +- app/Services/QueueService.php | 2 +- app/Services/SearchService.php | 6 +- app/Services/SongService.php | 6 +- .../SongStorages/S3CompatibleStorage.php | 2 +- app/Services/SongStorages/S3LambdaStorage.php | 6 +- app/Services/SpotifyService.php | 2 +- .../Adapters/DropboxStreamerAdapter.php | 2 +- .../Adapters/S3CompatibleStreamerAdapter.php | 2 +- app/Services/Streamer/Streamer.php | 7 +- app/Services/TokenManager.php | 2 +- app/Services/UserInvitationService.php | 2 +- app/Services/UserService.php | 6 +- app/Services/YouTubeService.php | 2 +- app/Values/ScanResult.php | 2 +- 92 files changed, 180 insertions(+), 335 deletions(-) delete mode 100644 app/Services/ApiClients/ApiClient.php delete mode 100644 app/Services/ApiClients/ITunesClient.php diff --git a/app/Console/Commands/ActivateLicenseCommand.php b/app/Console/Commands/ActivateLicenseCommand.php index 6d6da566..c9dc6488 100644 --- a/app/Console/Commands/ActivateLicenseCommand.php +++ b/app/Console/Commands/ActivateLicenseCommand.php @@ -11,7 +11,7 @@ class ActivateLicenseCommand extends Command protected $signature = 'koel:license:activate {key : The license key to activate.}'; protected $description = 'Activate a Koel Plus license'; - public function __construct(private LicenseServiceInterface $licenseService) + public function __construct(private readonly LicenseServiceInterface $licenseService) { parent::__construct(); } diff --git a/app/Console/Commands/Admin/ChangePasswordCommand.php b/app/Console/Commands/Admin/ChangePasswordCommand.php index e70899fe..0e40e5e2 100644 --- a/app/Console/Commands/Admin/ChangePasswordCommand.php +++ b/app/Console/Commands/Admin/ChangePasswordCommand.php @@ -15,7 +15,7 @@ class ChangePasswordCommand extends Command {email? : The user's email. If empty, will get the default admin user.}"; protected $description = "Change a user's password"; - public function __construct(private Hash $hash, private UserRepository $userRepository) + public function __construct(private readonly Hash $hash, private readonly UserRepository $userRepository) { parent::__construct(); } diff --git a/app/Console/Commands/CheckLicenseStatusCommand.php b/app/Console/Commands/CheckLicenseStatusCommand.php index fd9c2d0d..01de0a53 100644 --- a/app/Console/Commands/CheckLicenseStatusCommand.php +++ b/app/Console/Commands/CheckLicenseStatusCommand.php @@ -12,7 +12,7 @@ class CheckLicenseStatusCommand extends Command protected $signature = 'koel:license:status'; protected $description = 'Check the current Koel Plus license status'; - public function __construct(private LicenseServiceInterface $licenseService) + public function __construct(private readonly LicenseServiceInterface $licenseService) { parent::__construct(); } diff --git a/app/Console/Commands/DeactivateLicenseCommand.php b/app/Console/Commands/DeactivateLicenseCommand.php index 1d2779e1..9145232f 100644 --- a/app/Console/Commands/DeactivateLicenseCommand.php +++ b/app/Console/Commands/DeactivateLicenseCommand.php @@ -11,14 +11,14 @@ class DeactivateLicenseCommand extends Command protected $signature = 'koel:license:deactivate'; protected $description = 'Deactivate the currently active Koel Plus license'; - public function __construct(private LicenseServiceInterface $plusService) + public function __construct(private readonly LicenseServiceInterface $licenseService) { parent::__construct(); } public function handle(): int { - $status = $this->plusService->getStatus(); + $status = $this->licenseService->getStatus(); if ($status->hasNoLicense()) { $this->components->warn('No active Plus license found.'); @@ -35,7 +35,7 @@ class DeactivateLicenseCommand extends Command $this->components->info('Deactivating your licenseā€¦'); try { - $this->plusService->deactivate($status->license); + $this->licenseService->deactivate($status->license); $this->components->info('Koel Plus has been deactivated. Plus features are now disabled.'); return self::SUCCESS; diff --git a/app/Console/Commands/InitCommand.php b/app/Console/Commands/InitCommand.php index cac3150c..b6b1d3b1 100644 --- a/app/Console/Commands/InitCommand.php +++ b/app/Console/Commands/InitCommand.php @@ -32,10 +32,10 @@ class InitCommand extends Command private bool $adminSeeded = false; public function __construct( - private Hash $hash, - private DotenvEditor $dotenvEditor, - private DB $db, - private LoggerInterface $logger + private readonly Hash $hash, + private readonly DotenvEditor $dotenvEditor, + private readonly DB $db, + private readonly LoggerInterface $logger ) { parent::__construct(); } diff --git a/app/Console/Commands/PruneLibraryCommand.php b/app/Console/Commands/PruneLibraryCommand.php index bf5f0488..d8410098 100644 --- a/app/Console/Commands/PruneLibraryCommand.php +++ b/app/Console/Commands/PruneLibraryCommand.php @@ -10,7 +10,7 @@ class PruneLibraryCommand extends Command protected $signature = 'koel:prune'; protected $description = 'Remove empty artists and albums'; - public function __construct(private LibraryManager $libraryManager) + public function __construct(private readonly LibraryManager $libraryManager) { parent::__construct(); } diff --git a/app/Console/Commands/ScanCommand.php b/app/Console/Commands/ScanCommand.php index 19d0f1ed..5aeb46fb 100644 --- a/app/Console/Commands/ScanCommand.php +++ b/app/Console/Commands/ScanCommand.php @@ -30,15 +30,17 @@ class ScanCommand extends Command private ?string $mediaPath; private ProgressBar $progressBar; - public function __construct(private MediaScanner $mediaScanner, private UserRepository $userRepository) - { + public function __construct( + private readonly MediaScanner $scanner, + private readonly UserRepository $userRepository + ) { parent::__construct(); - $this->mediaScanner->on('paths-gathered', function (array $paths): void { + $this->scanner->on('paths-gathered', function (array $paths): void { $this->progressBar = new ProgressBar($this->output, count($paths)); }); - $this->mediaScanner->on('progress', [$this, 'onScanProgress']); + $this->scanner->on('progress', [$this, 'onScanProgress']); } protected function configure(): void @@ -88,7 +90,7 @@ class ScanCommand extends Command $this->components->info('Ignoring tag(s): ' . implode(', ', $config->ignores)); } - $results = $this->mediaScanner->scan($config); + $results = $this->scanner->scan($config); $this->newLine(2); $this->components->info('Scanning completed!'); @@ -112,7 +114,7 @@ class ScanCommand extends Command */ private function scanSingleRecord(string $record, ScanConfiguration $config): void { - $this->mediaScanner->scanWatchRecord(new InotifyWatchRecord($record), $config); + $this->scanner->scanWatchRecord(new InotifyWatchRecord($record), $config); } public function onScanProgress(ScanResult $result): void @@ -129,7 +131,7 @@ class ScanCommand extends Command $result->isSuccess() => "OK", $result->isSkipped() => "SKIPPED", $result->isError() => "ERROR", - default => throw new RuntimeException("Unknown scan result type: {$result->type}") + default => throw new RuntimeException("Unknown scan result type: {$result->type->value}") }); if ($result->isError()) { diff --git a/app/Console/Commands/Storage/SetupDropboxStorageCommand.php b/app/Console/Commands/Storage/SetupDropboxStorageCommand.php index 929aa96c..4f70e1a3 100644 --- a/app/Console/Commands/Storage/SetupDropboxStorageCommand.php +++ b/app/Console/Commands/Storage/SetupDropboxStorageCommand.php @@ -17,7 +17,7 @@ class SetupDropboxStorageCommand extends Command protected $signature = 'koel:storage:dropbox'; protected $description = 'Set up Dropbox as the storage driver for Koel'; - public function __construct(private DotenvEditor $dotenvEditor) + public function __construct(private readonly DotenvEditor $dotenvEditor) { parent::__construct(); } diff --git a/app/Console/Commands/Storage/SetupLocalStorageCommand.php b/app/Console/Commands/Storage/SetupLocalStorageCommand.php index 5ce615e0..a8faabeb 100644 --- a/app/Console/Commands/Storage/SetupLocalStorageCommand.php +++ b/app/Console/Commands/Storage/SetupLocalStorageCommand.php @@ -13,7 +13,7 @@ class SetupLocalStorageCommand extends Command protected $signature = 'koel:storage:local'; protected $description = 'Set up the local storage for Koel'; - public function __construct(private DotenvEditor $dotenvEditor) + public function __construct(private readonly DotenvEditor $dotenvEditor) { parent::__construct(); } diff --git a/app/Console/Commands/Storage/SetupS3StorageCommand.php b/app/Console/Commands/Storage/SetupS3StorageCommand.php index bcebe47a..b948dfa5 100644 --- a/app/Console/Commands/Storage/SetupS3StorageCommand.php +++ b/app/Console/Commands/Storage/SetupS3StorageCommand.php @@ -14,7 +14,7 @@ class SetupS3StorageCommand extends Command protected $signature = 'koel:storage:s3'; protected $description = 'Set up Amazon S3 or a compatible service as the storage driver for Koel'; - public function __construct(private DotenvEditor $dotenvEditor) + public function __construct(private readonly DotenvEditor $dotenvEditor) { parent::__construct(); } diff --git a/app/Filesystems/DropboxFilesystem.php b/app/Filesystems/DropboxFilesystem.php index 76a8525c..5f0beb0f 100644 --- a/app/Filesystems/DropboxFilesystem.php +++ b/app/Filesystems/DropboxFilesystem.php @@ -8,7 +8,7 @@ use Spatie\FlysystemDropbox\DropboxAdapter; class DropboxFilesystem extends Filesystem { - public function __construct(private DropboxAdapter $adapter) + public function __construct(private readonly DropboxAdapter $adapter) { parent::__construct($adapter, ['case_sensitive' => false]); } diff --git a/app/Http/Controllers/API/AlbumController.php b/app/Http/Controllers/API/AlbumController.php index f725fce2..ef6aa686 100644 --- a/app/Http/Controllers/API/AlbumController.php +++ b/app/Http/Controllers/API/AlbumController.php @@ -9,7 +9,7 @@ use App\Repositories\AlbumRepository; class AlbumController extends Controller { - public function __construct(private AlbumRepository $repository) + public function __construct(private readonly AlbumRepository $repository) { } diff --git a/app/Http/Controllers/API/AlbumSongController.php b/app/Http/Controllers/API/AlbumSongController.php index 117d7446..01e9f801 100644 --- a/app/Http/Controllers/API/AlbumSongController.php +++ b/app/Http/Controllers/API/AlbumSongController.php @@ -12,8 +12,10 @@ use Illuminate\Contracts\Auth\Authenticatable; class AlbumSongController extends Controller { /** @param User $user */ - public function __construct(private SongRepository $songRepository, private ?Authenticatable $user) - { + public function __construct( + private readonly SongRepository $songRepository, + private readonly ?Authenticatable $user + ) { } public function index(Album $album) diff --git a/app/Http/Controllers/API/ArtistAlbumController.php b/app/Http/Controllers/API/ArtistAlbumController.php index 351e9a41..145708ab 100644 --- a/app/Http/Controllers/API/ArtistAlbumController.php +++ b/app/Http/Controllers/API/ArtistAlbumController.php @@ -9,7 +9,7 @@ use App\Repositories\AlbumRepository; class ArtistAlbumController extends Controller { - public function __construct(private AlbumRepository $albumRepository) + public function __construct(private readonly AlbumRepository $albumRepository) { } diff --git a/app/Http/Controllers/API/ArtistController.php b/app/Http/Controllers/API/ArtistController.php index be8d7144..7321a7fe 100644 --- a/app/Http/Controllers/API/ArtistController.php +++ b/app/Http/Controllers/API/ArtistController.php @@ -9,7 +9,7 @@ use App\Repositories\ArtistRepository; class ArtistController extends Controller { - public function __construct(private ArtistRepository $repository) + public function __construct(private readonly ArtistRepository $repository) { } diff --git a/app/Http/Controllers/API/ArtistSongController.php b/app/Http/Controllers/API/ArtistSongController.php index 90ee53c0..ef0131e8 100644 --- a/app/Http/Controllers/API/ArtistSongController.php +++ b/app/Http/Controllers/API/ArtistSongController.php @@ -12,8 +12,10 @@ use Illuminate\Contracts\Auth\Authenticatable; class ArtistSongController extends Controller { /** @param User $user */ - public function __construct(private SongRepository $songRepository, private ?Authenticatable $user) - { + public function __construct( + private readonly SongRepository $songRepository, + private readonly ?Authenticatable $user + ) { } public function index(Artist $artist) diff --git a/app/Http/Controllers/API/GenreController.php b/app/Http/Controllers/API/GenreController.php index b4bb03da..112138be 100644 --- a/app/Http/Controllers/API/GenreController.php +++ b/app/Http/Controllers/API/GenreController.php @@ -9,7 +9,7 @@ use Illuminate\Http\Response; class GenreController extends Controller { - public function __construct(private GenreRepository $repository) + public function __construct(private readonly GenreRepository $repository) { } diff --git a/app/Http/Controllers/API/LambdaSongController.php b/app/Http/Controllers/API/LambdaSongController.php index feaf59d1..997b476f 100644 --- a/app/Http/Controllers/API/LambdaSongController.php +++ b/app/Http/Controllers/API/LambdaSongController.php @@ -12,7 +12,7 @@ use Illuminate\Support\Arr; class LambdaSongController extends Controller { - public function __construct(private S3LambdaStorage $storage) + public function __construct(private readonly S3LambdaStorage $storage) { } diff --git a/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php b/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php index 65aa3320..478a9e4d 100644 --- a/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php +++ b/app/Http/Controllers/API/PlaylistCollaboration/PlaylistCollaboratorController.php @@ -15,8 +15,10 @@ use Illuminate\Http\Response; class PlaylistCollaboratorController extends Controller { - public function __construct(private PlaylistCollaborationService $service, private UserRepository $userRepository) - { + public function __construct( + private readonly PlaylistCollaborationService $service, + private readonly UserRepository $userRepository + ) { } public function index(Playlist $playlist) diff --git a/app/Http/Controllers/API/PlaylistController.php b/app/Http/Controllers/API/PlaylistController.php index 20b41363..433cffdb 100644 --- a/app/Http/Controllers/API/PlaylistController.php +++ b/app/Http/Controllers/API/PlaylistController.php @@ -23,10 +23,10 @@ class PlaylistController extends Controller { /** @param User $user */ public function __construct( - private PlaylistService $playlistService, - private PlaylistRepository $playlistRepository, - private PlaylistFolderRepository $folderRepository, - private ?Authenticatable $user + private readonly PlaylistService $playlistService, + private readonly PlaylistRepository $playlistRepository, + private readonly PlaylistFolderRepository $folderRepository, + private readonly ?Authenticatable $user ) { } diff --git a/app/Http/Controllers/API/PlaylistFolderController.php b/app/Http/Controllers/API/PlaylistFolderController.php index 9c63834c..e8872805 100644 --- a/app/Http/Controllers/API/PlaylistFolderController.php +++ b/app/Http/Controllers/API/PlaylistFolderController.php @@ -14,8 +14,10 @@ use Illuminate\Contracts\Auth\Authenticatable; class PlaylistFolderController extends Controller { /** @param User $user */ - public function __construct(private PlaylistFolderService $service, private ?Authenticatable $user) - { + public function __construct( + private readonly PlaylistFolderService $service, + private readonly ?Authenticatable $user + ) { } public function index() diff --git a/app/Http/Controllers/API/PlaylistFolderPlaylistController.php b/app/Http/Controllers/API/PlaylistFolderPlaylistController.php index 1359897c..2fdbafa8 100644 --- a/app/Http/Controllers/API/PlaylistFolderPlaylistController.php +++ b/app/Http/Controllers/API/PlaylistFolderPlaylistController.php @@ -11,7 +11,7 @@ use Illuminate\Support\Arr; class PlaylistFolderPlaylistController extends Controller { - public function __construct(private PlaylistFolderService $service) + public function __construct(private readonly PlaylistFolderService $service) { } diff --git a/app/Http/Controllers/API/PlaylistSongController.php b/app/Http/Controllers/API/PlaylistSongController.php index c01ebb09..aee9eb5c 100644 --- a/app/Http/Controllers/API/PlaylistSongController.php +++ b/app/Http/Controllers/API/PlaylistSongController.php @@ -22,10 +22,10 @@ class PlaylistSongController extends Controller { /** @param User $user */ public function __construct( - private SongRepository $songRepository, - private PlaylistService $playlistService, - private SmartPlaylistService $smartPlaylistService, - private ?Authenticatable $user + private readonly SongRepository $songRepository, + private readonly PlaylistService $playlistService, + private readonly SmartPlaylistService $smartPlaylistService, + private readonly ?Authenticatable $user ) { } @@ -49,7 +49,9 @@ class PlaylistSongController extends Controller $songs = $this->songRepository->getMany(ids: $request->songs, scopedUser: $this->user); - return self::createResourceCollection($this->playlistService->addSongsToPlaylist($playlist, $songs, $this->user)); + return self::createResourceCollection( + $this->playlistService->addSongsToPlaylist($playlist, $songs, $this->user) + ); } private static function createResourceCollection(Collection $songs): ResourceCollection diff --git a/app/Http/Controllers/API/ProfileController.php b/app/Http/Controllers/API/ProfileController.php index f4c4c50a..d26e97ae 100644 --- a/app/Http/Controllers/API/ProfileController.php +++ b/app/Http/Controllers/API/ProfileController.php @@ -18,10 +18,10 @@ class ProfileController extends Controller { /** @param User $user */ public function __construct( - private Hasher $hash, - private UserService $userService, - private TokenManager $tokenManager, - private ?Authenticatable $user + private readonly Hasher $hash, + private readonly UserService $userService, + private readonly TokenManager $tokenManager, + private readonly ?Authenticatable $user ) { } diff --git a/app/Http/Controllers/API/QueueStateController.php b/app/Http/Controllers/API/QueueStateController.php index 5ba3b713..2faba3dd 100644 --- a/app/Http/Controllers/API/QueueStateController.php +++ b/app/Http/Controllers/API/QueueStateController.php @@ -12,7 +12,7 @@ use Illuminate\Contracts\Auth\Authenticatable; class QueueStateController extends Controller { /** @param User $user */ - public function __construct(private QueueService $queueService, private ?Authenticatable $user) + public function __construct(private readonly QueueService $queueService, private readonly ?Authenticatable $user) { } diff --git a/app/Http/Controllers/API/SettingController.php b/app/Http/Controllers/API/SettingController.php index 3f020de0..95087d80 100644 --- a/app/Http/Controllers/API/SettingController.php +++ b/app/Http/Controllers/API/SettingController.php @@ -13,8 +13,10 @@ use Illuminate\Contracts\Auth\Authenticatable; class SettingController extends Controller { /** @param User $user */ - public function __construct(private MediaScanner $mediaSyncService, private ?Authenticatable $user) - { + public function __construct( + private readonly MediaScanner $mediaSyncService, + private readonly ?Authenticatable $user + ) { } public function update(SettingRequest $request) diff --git a/app/Http/Controllers/API/SongController.php b/app/Http/Controllers/API/SongController.php index ec8b2bf1..3e408502 100644 --- a/app/Http/Controllers/API/SongController.php +++ b/app/Http/Controllers/API/SongController.php @@ -23,12 +23,12 @@ class SongController extends Controller { /** @param User $user */ public function __construct( - private SongService $songService, - private SongRepository $songRepository, - private AlbumRepository $albumRepository, - private ArtistRepository $artistRepository, - private LibraryManager $libraryManager, - private ?Authenticatable $user + private readonly SongService $songService, + private readonly SongRepository $songRepository, + private readonly AlbumRepository $albumRepository, + private readonly ArtistRepository $artistRepository, + private readonly LibraryManager $libraryManager, + private readonly ?Authenticatable $user ) { } diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index 43b63639..0affa78e 100644 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -14,8 +14,10 @@ use Illuminate\Http\Response; class UserController extends Controller { - public function __construct(private UserRepository $userRepository, private UserService $userService) - { + public function __construct( + private readonly UserRepository $userRepository, + private readonly UserService $userService + ) { } public function index() diff --git a/app/Http/Controllers/API/UserInvitationController.php b/app/Http/Controllers/API/UserInvitationController.php index 1aaae20b..e66e872b 100644 --- a/app/Http/Controllers/API/UserInvitationController.php +++ b/app/Http/Controllers/API/UserInvitationController.php @@ -17,13 +17,11 @@ use Illuminate\Http\Response; class UserInvitationController extends Controller { - /** - * @param User $invitor - */ + /** @param User $invitor */ public function __construct( - private UserInvitationService $invitationService, - private AuthenticationService $auth, - private ?Authenticatable $invitor + private readonly UserInvitationService $invitationService, + private readonly AuthenticationService $auth, + private readonly ?Authenticatable $invitor ) { } diff --git a/app/Http/Controllers/LastfmController.php b/app/Http/Controllers/LastfmController.php index af58db23..a4a2a24d 100644 --- a/app/Http/Controllers/LastfmController.php +++ b/app/Http/Controllers/LastfmController.php @@ -13,9 +13,9 @@ class LastfmController extends Controller { /** @param User $currentUser */ public function __construct( - private LastfmService $lastfm, - private TokenManager $tokenManager, - private ?Authenticatable $currentUser + private readonly LastfmService $lastfm, + private readonly TokenManager $tokenManager, + private readonly ?Authenticatable $currentUser ) { } diff --git a/app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php b/app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php index 8246594f..437f424d 100644 --- a/app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php +++ b/app/Http/Integrations/Lastfm/Auth/LastfmAuthenticator.php @@ -9,7 +9,7 @@ use Saloon\Repositories\Body\FormBodyRepository; final class LastfmAuthenticator implements Authenticator { - public function __construct(private string $key, private string $secret) + public function __construct(private readonly string $key, private readonly string $secret) { } diff --git a/app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php b/app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php index d908f108..3abccc96 100644 --- a/app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/GetAlbumInfoRequest.php @@ -16,7 +16,7 @@ final class GetAlbumInfoRequest extends Request protected Method $method = Method::GET; - public function __construct(private Album $album) + public function __construct(private readonly Album $album) { } diff --git a/app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php b/app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php index 30b30951..417aee52 100644 --- a/app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/GetArtistInfoRequest.php @@ -15,7 +15,7 @@ final class GetArtistInfoRequest extends Request protected Method $method = Method::GET; - public function __construct(private Artist $artist) + public function __construct(private readonly Artist $artist) { } diff --git a/app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php b/app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php index 883f86fd..700e6f6f 100644 --- a/app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/GetSessionKeyRequest.php @@ -10,7 +10,7 @@ final class GetSessionKeyRequest extends Request implements RequiresSignature { protected Method $method = Method::GET; - public function __construct(private string $token) + public function __construct(private readonly string $token) { } diff --git a/app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php b/app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php index b5296d5e..74555b44 100644 --- a/app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/ScrobbleRequest.php @@ -17,8 +17,11 @@ final class ScrobbleRequest extends Request implements HasBody, RequiresSignatur protected Method $method = Method::POST; - public function __construct(private Song $song, private User $user, private int $timestamp) - { + public function __construct( + private readonly Song $song, + private readonly User $user, + private readonly int $timestamp + ) { } public function resolveEndpoint(): string diff --git a/app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php b/app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php index 4873221e..3539e8ee 100644 --- a/app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/ToggleLoveTrackRequest.php @@ -16,7 +16,7 @@ final class ToggleLoveTrackRequest extends Request implements HasBody, RequiresS protected Method $method = Method::POST; - public function __construct(private Song $song, private User $user, private bool $love) + public function __construct(private readonly Song $song, private readonly User $user, private readonly bool $love) { } diff --git a/app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php b/app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php index 2695ef4f..c03e5a0c 100644 --- a/app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php +++ b/app/Http/Integrations/Lastfm/Requests/UpdateNowPlayingRequest.php @@ -17,7 +17,7 @@ final class UpdateNowPlayingRequest extends Request implements HasBody, Requires protected Method $method = Method::POST; - public function __construct(private Song $song, private User $user) + public function __construct(private readonly Song $song, private readonly User $user) { } diff --git a/app/Http/Integrations/LemonSqueezy/Requests/ActivateLicenseRequest.php b/app/Http/Integrations/LemonSqueezy/Requests/ActivateLicenseRequest.php index 42ab2992..eea52f60 100644 --- a/app/Http/Integrations/LemonSqueezy/Requests/ActivateLicenseRequest.php +++ b/app/Http/Integrations/LemonSqueezy/Requests/ActivateLicenseRequest.php @@ -13,7 +13,7 @@ class ActivateLicenseRequest extends Request implements HasBody protected Method $method = Method::POST; - public function __construct(private string $key) + public function __construct(private readonly string $key) { } diff --git a/app/Http/Integrations/LemonSqueezy/Requests/DeactivateLicenseRequest.php b/app/Http/Integrations/LemonSqueezy/Requests/DeactivateLicenseRequest.php index 6e63cb53..ca06b661 100644 --- a/app/Http/Integrations/LemonSqueezy/Requests/DeactivateLicenseRequest.php +++ b/app/Http/Integrations/LemonSqueezy/Requests/DeactivateLicenseRequest.php @@ -14,7 +14,7 @@ class DeactivateLicenseRequest extends Request implements HasBody protected Method $method = Method::POST; - public function __construct(private License $license) + public function __construct(private readonly License $license) { } diff --git a/app/Http/Integrations/LemonSqueezy/Requests/ValidateLicenseRequest.php b/app/Http/Integrations/LemonSqueezy/Requests/ValidateLicenseRequest.php index 6dd491d9..0af3e218 100644 --- a/app/Http/Integrations/LemonSqueezy/Requests/ValidateLicenseRequest.php +++ b/app/Http/Integrations/LemonSqueezy/Requests/ValidateLicenseRequest.php @@ -14,7 +14,7 @@ class ValidateLicenseRequest extends Request implements HasBody protected Method $method = Method::POST; - public function __construct(private License $license) + public function __construct(private readonly License $license) { } diff --git a/app/Http/Integrations/Spotify/SpotifyClient.php b/app/Http/Integrations/Spotify/SpotifyClient.php index d5f35951..01c2df1b 100644 --- a/app/Http/Integrations/Spotify/SpotifyClient.php +++ b/app/Http/Integrations/Spotify/SpotifyClient.php @@ -13,8 +13,11 @@ use SpotifyWebAPI\SpotifyWebAPI; */ class SpotifyClient { - public function __construct(public SpotifyWebAPI $wrapped, private ?Session $session, private Cache $cache) - { + public function __construct( + public SpotifyWebAPI $wrapped, + private readonly ?Session $session, + private readonly Cache $cache + ) { if (SpotifyService::enabled()) { $this->wrapped->setOptions(['return_assoc' => true]); attempt(fn () => $this->setAccessToken()); diff --git a/app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php b/app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php index 1b52eda9..7836d66e 100644 --- a/app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php +++ b/app/Http/Integrations/YouTube/Requests/SearchVideosRequest.php @@ -10,7 +10,7 @@ class SearchVideosRequest extends Request { protected Method $method = Method::GET; - public function __construct(private Song $song, private string $pageToken = '') + public function __construct(private readonly Song $song, private readonly string $pageToken = '') { } diff --git a/app/Http/Integrations/iTunes/Requests/GetTrackRequest.php b/app/Http/Integrations/iTunes/Requests/GetTrackRequest.php index 14690be5..809adbb1 100644 --- a/app/Http/Integrations/iTunes/Requests/GetTrackRequest.php +++ b/app/Http/Integrations/iTunes/Requests/GetTrackRequest.php @@ -11,7 +11,7 @@ class GetTrackRequest extends Request { protected Method $method = Method::GET; - public function __construct(private string $trackName, private Album $album) + public function __construct(private readonly string $trackName, private readonly Album $album) { } diff --git a/app/Http/Resources/AlbumResource.php b/app/Http/Resources/AlbumResource.php index 229d52a2..46bcd099 100644 --- a/app/Http/Resources/AlbumResource.php +++ b/app/Http/Resources/AlbumResource.php @@ -36,7 +36,7 @@ class AlbumResource extends JsonResource ], ]; - public function __construct(private Album $album) + public function __construct(private readonly Album $album) { parent::__construct($album); } diff --git a/app/Http/Resources/ArtistResource.php b/app/Http/Resources/ArtistResource.php index 69bf12be..18687b03 100644 --- a/app/Http/Resources/ArtistResource.php +++ b/app/Http/Resources/ArtistResource.php @@ -34,7 +34,7 @@ class ArtistResource extends JsonResource ], ]; - public function __construct(private Artist $artist) + public function __construct(private readonly Artist $artist) { parent::__construct($artist); } diff --git a/app/Http/Resources/ExcerptSearchResource.php b/app/Http/Resources/ExcerptSearchResource.php index 897e6116..83670aca 100644 --- a/app/Http/Resources/ExcerptSearchResource.php +++ b/app/Http/Resources/ExcerptSearchResource.php @@ -19,7 +19,7 @@ class ExcerptSearchResource extends JsonResource ], ]; - public function __construct(private ExcerptSearchResult $result) + public function __construct(private readonly ExcerptSearchResult $result) { parent::__construct($result); } diff --git a/app/Http/Resources/GenreResource.php b/app/Http/Resources/GenreResource.php index 1c9128c2..bd5746eb 100644 --- a/app/Http/Resources/GenreResource.php +++ b/app/Http/Resources/GenreResource.php @@ -14,7 +14,7 @@ class GenreResource extends JsonResource 'length', ]; - public function __construct(private Genre $genre) + public function __construct(private readonly Genre $genre) { parent::__construct($genre); } diff --git a/app/Http/Resources/InteractionResource.php b/app/Http/Resources/InteractionResource.php index ccbcb225..e2fb86f1 100644 --- a/app/Http/Resources/InteractionResource.php +++ b/app/Http/Resources/InteractionResource.php @@ -17,7 +17,7 @@ class InteractionResource extends JsonResource 'play_count', ]; - public function __construct(private Interaction $interaction) + public function __construct(private readonly Interaction $interaction) { parent::__construct($interaction); } diff --git a/app/Http/Resources/PlaylistCollaborationTokenResource.php b/app/Http/Resources/PlaylistCollaborationTokenResource.php index e1d82fc5..591ac914 100644 --- a/app/Http/Resources/PlaylistCollaborationTokenResource.php +++ b/app/Http/Resources/PlaylistCollaborationTokenResource.php @@ -12,7 +12,7 @@ class PlaylistCollaborationTokenResource extends JsonResource 'token', ]; - public function __construct(private PlaylistCollaborationToken $token) + public function __construct(private readonly PlaylistCollaborationToken $token) { parent::__construct($token); } diff --git a/app/Http/Resources/PlaylistCollaboratorResource.php b/app/Http/Resources/PlaylistCollaboratorResource.php index dc96fd34..c26f8833 100644 --- a/app/Http/Resources/PlaylistCollaboratorResource.php +++ b/app/Http/Resources/PlaylistCollaboratorResource.php @@ -14,7 +14,7 @@ class PlaylistCollaboratorResource extends JsonResource 'avatar', ]; - public function __construct(private PlaylistCollaborator $collaborator) + public function __construct(private readonly PlaylistCollaborator $collaborator) { parent::__construct($collaborator); } diff --git a/app/Http/Resources/PlaylistFolderResource.php b/app/Http/Resources/PlaylistFolderResource.php index a59a61b6..0db64163 100644 --- a/app/Http/Resources/PlaylistFolderResource.php +++ b/app/Http/Resources/PlaylistFolderResource.php @@ -15,7 +15,7 @@ class PlaylistFolderResource extends JsonResource 'created_at', ]; - public function __construct(private PlaylistFolder $folder) + public function __construct(private readonly PlaylistFolder $folder) { parent::__construct($folder); } diff --git a/app/Http/Resources/PlaylistResource.php b/app/Http/Resources/PlaylistResource.php index 47561ce3..ca0667e9 100644 --- a/app/Http/Resources/PlaylistResource.php +++ b/app/Http/Resources/PlaylistResource.php @@ -20,7 +20,7 @@ class PlaylistResource extends JsonResource 'created_at', ]; - public function __construct(private Playlist $playlist) + public function __construct(private readonly Playlist $playlist) { parent::__construct($playlist); } diff --git a/app/Http/Resources/QueueStateResource.php b/app/Http/Resources/QueueStateResource.php index c615a8ae..a821b03d 100644 --- a/app/Http/Resources/QueueStateResource.php +++ b/app/Http/Resources/QueueStateResource.php @@ -15,7 +15,7 @@ class QueueStateResource extends JsonResource 'playback_position', ]; - public function __construct(private QueueState $state) + public function __construct(private readonly QueueState $state) { parent::__construct($state); } diff --git a/app/Http/Resources/UserProspectResource.php b/app/Http/Resources/UserProspectResource.php index a9018368..e607ffe3 100644 --- a/app/Http/Resources/UserProspectResource.php +++ b/app/Http/Resources/UserProspectResource.php @@ -17,7 +17,7 @@ class UserProspectResource extends JsonResource 'is_prospect', ]; - public function __construct(private User $user) + public function __construct(private readonly User $user) { parent::__construct($user); } diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index 8cd138c9..59203294 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -20,7 +20,7 @@ class UserResource extends JsonResource 'sso_id', ]; - public function __construct(private User $user) + public function __construct(private readonly User $user) { parent::__construct($user); } diff --git a/app/Listeners/DeleteNonExistingRecordsPostScan.php b/app/Listeners/DeleteNonExistingRecordsPostScan.php index b358f795..b2f90c45 100644 --- a/app/Listeners/DeleteNonExistingRecordsPostScan.php +++ b/app/Listeners/DeleteNonExistingRecordsPostScan.php @@ -9,7 +9,7 @@ use App\Values\ScanResult; class DeleteNonExistingRecordsPostScan { - public function __construct(private SongRepository $songRepository) + public function __construct(private readonly SongRepository $songRepository) { } diff --git a/app/Listeners/LoveMultipleTracksOnLastfm.php b/app/Listeners/LoveMultipleTracksOnLastfm.php index 1bbdfe9e..18d73b3d 100644 --- a/app/Listeners/LoveMultipleTracksOnLastfm.php +++ b/app/Listeners/LoveMultipleTracksOnLastfm.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; class LoveMultipleTracksOnLastfm implements ShouldQueue { - public function __construct(private LastfmService $lastfm) + public function __construct(private readonly LastfmService $lastfm) { } diff --git a/app/Listeners/LoveTrackOnLastfm.php b/app/Listeners/LoveTrackOnLastfm.php index af19b061..19d26964 100644 --- a/app/Listeners/LoveTrackOnLastfm.php +++ b/app/Listeners/LoveTrackOnLastfm.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; class LoveTrackOnLastfm implements ShouldQueue { - public function __construct(private LastfmService $lastfm) + public function __construct(private readonly LastfmService $lastfm) { } diff --git a/app/Listeners/MakePlaylistSongsPublic.php b/app/Listeners/MakePlaylistSongsPublic.php index 71e89e2c..c051e951 100644 --- a/app/Listeners/MakePlaylistSongsPublic.php +++ b/app/Listeners/MakePlaylistSongsPublic.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; class MakePlaylistSongsPublic implements ShouldQueue { - public function __construct(private PlaylistService $service) + public function __construct(private readonly PlaylistService $service) { } diff --git a/app/Listeners/PruneLibrary.php b/app/Listeners/PruneLibrary.php index 7bc05988..b2b035f8 100644 --- a/app/Listeners/PruneLibrary.php +++ b/app/Listeners/PruneLibrary.php @@ -6,7 +6,7 @@ use App\Services\LibraryManager; class PruneLibrary { - public function __construct(private LibraryManager $libraryManager) + public function __construct(private readonly LibraryManager $libraryManager) { } diff --git a/app/Listeners/UnloveMultipleTracksOnLastfm.php b/app/Listeners/UnloveMultipleTracksOnLastfm.php index bbe8fd14..acf8fb58 100644 --- a/app/Listeners/UnloveMultipleTracksOnLastfm.php +++ b/app/Listeners/UnloveMultipleTracksOnLastfm.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; class UnloveMultipleTracksOnLastfm implements ShouldQueue { - public function __construct(private LastfmService $lastfm) + public function __construct(private readonly LastfmService $lastfm) { } diff --git a/app/Listeners/UpdateLastfmNowPlaying.php b/app/Listeners/UpdateLastfmNowPlaying.php index 7b576d57..6f098e2b 100644 --- a/app/Listeners/UpdateLastfmNowPlaying.php +++ b/app/Listeners/UpdateLastfmNowPlaying.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; class UpdateLastfmNowPlaying implements ShouldQueue { - public function __construct(private LastfmService $lastfm) + public function __construct(private readonly LastfmService $lastfm) { } diff --git a/app/Mail/UserInvite.php b/app/Mail/UserInvite.php index 32b9706f..09b1b72a 100644 --- a/app/Mail/UserInvite.php +++ b/app/Mail/UserInvite.php @@ -14,7 +14,7 @@ class UserInvite extends Mailable use Queueable; use SerializesModels; - public function __construct(private User $invitee) + public function __construct(private readonly User $invitee) { } diff --git a/app/Rules/AllPlaylistsAreAccessibleBy.php b/app/Rules/AllPlaylistsAreAccessibleBy.php index 3b426605..a82cc65b 100644 --- a/app/Rules/AllPlaylistsAreAccessibleBy.php +++ b/app/Rules/AllPlaylistsAreAccessibleBy.php @@ -9,7 +9,7 @@ use Illuminate\Support\Arr; final class AllPlaylistsAreAccessibleBy implements Rule { - public function __construct(private User $user) + public function __construct(private readonly User $user) { } diff --git a/app/Services/ApiClients/ApiClient.php b/app/Services/ApiClients/ApiClient.php deleted file mode 100644 index 5faf6021..00000000 --- a/app/Services/ApiClients/ApiClient.php +++ /dev/null @@ -1,159 +0,0 @@ - array_merge($this->headers, $headers), - ]; - - $body = (string) $this->wrapped - ->$method($this->buildUrl($uri, $appendKey), ['form_params' => $params], $options) - ->getBody(); - - if ($this->responseFormat === 'json') { - return json_decode($body); - } - - if ($this->responseFormat === 'xml') { - return simplexml_load_string($body); - } - - return $body; - } - - public function requestAsync(string $method, string $uri, bool $appendKey = true, array $params = []): Promise - { - return $this->wrapped->$method($this->buildUrl($uri, $appendKey), ['form_params' => $params]); - } - - /** - * Make an HTTP call to the external resource. - * - * @param string $method The HTTP method - * @param array $args An array of parameters - * - * @return mixed|SimpleXMLElement|void - * @throws InvalidArgumentException - * - */ - public function __call(string $method, array $args) // @phpcs:ignore - { - Assert::inArray($method, self::MAGIC_METHODS); - - if (count($args) < 1) { - throw new InvalidArgumentException('Magic request methods require a URI and optional options array'); - } - - $uri = $args[0]; - $params = $args[1] ?? []; - $appendKey = $args[2] ?? true; - $headers = $args[3] ?? []; - - if (Str::endsWith($method, 'Async')) { - return $this->requestAsync($method, $uri, $appendKey, $params); - } else { - return $this->request($method, $uri, $appendKey, $params, $headers); - } - } - - /** - * Turn a URI segment into a full API URL. - * - * @param bool $appendKey whether to automatically append the API key into the URL - */ - public function buildUrl(string $uri, bool $appendKey = true): string - { - if (!starts_with($uri, ['http://', 'https://'])) { - if ($uri[0] !== '/') { - $uri = "/$uri"; - } - - $uri = rtrim($this->getEndpoint(), '/') . $uri; - } - - if ($appendKey && $this->getKey()) { - if (parse_url($uri, PHP_URL_QUERY)) { - $uri .= "&$this->keyParam=" . $this->getKey(); - } else { - $uri .= "?$this->keyParam=" . $this->getKey(); - } - } - - return $uri; - } - - abstract public function getKey(): ?string; - - abstract public function getSecret(): ?string; - - abstract public function getEndpoint(): ?string; -} diff --git a/app/Services/ApiClients/ITunesClient.php b/app/Services/ApiClients/ITunesClient.php deleted file mode 100644 index 4f8dcf82..00000000 --- a/app/Services/ApiClients/ITunesClient.php +++ /dev/null @@ -1,21 +0,0 @@ -