chore: remove unnecessary type hints

This commit is contained in:
Phan An 2024-04-24 23:58:19 +02:00
parent 2de785fc43
commit b8c10d07d2
46 changed files with 41 additions and 130 deletions

View file

@ -168,7 +168,6 @@ class ScanCommand extends Command
$specifiedOwner = $this->option('owner');
if ($specifiedOwner) {
/** @var User $user */
$user = User::findOr($specifiedOwner, function () use ($specifiedOwner): void {
$this->components->error("User with ID $specifiedOwner does not exist.");
exit(self::INVALID);

View file

@ -78,9 +78,7 @@ class SetupDropboxStorageCommand extends Command
$this->comment('Uploading a test file to make sure everything is working...');
try {
/** @var DropboxStorage $storage */
$storage = app(DropboxStorage::class);
$storage->testSetup();
app(DropboxStorage::class)->testSetup();
} catch (Throwable $e) {
$this->error('Failed to upload test file: ' . $e->getMessage() . '.');
$this->comment('Please make sure the app has the correct permissions and try again.');

View file

@ -45,9 +45,7 @@ class SetupS3StorageCommand extends Command
$this->comment('Uploading a test file to make sure everything is working...');
try {
/** @var S3CompatibleStorage $storage */
$storage = app(S3CompatibleStorage::class);
$storage->testSetup();
app(S3CompatibleStorage::class)->testSetup();
} catch (Throwable $e) {
$this->error('Failed to upload test file: ' . $e->getMessage() . '.');
$this->comment('Please check your configuration and try again.');

View file

@ -17,7 +17,6 @@ class FetchOverviewController extends Controller
AlbumRepository $albumRepository,
ArtistRepository $artistRepository
) {
return response()->json([
'most_played_songs' => SongResource::collection($songRepository->getMostPlayed()),
'recently_played_songs' => SongResource::collection($songRepository->getRecentlyPlayed()),

View file

@ -8,7 +8,6 @@ use App\Exceptions\NotAPlaylistCollaboratorException;
use App\Http\Controllers\Controller;
use App\Http\Requests\API\PlaylistCollaboration\PlaylistCollaboratorDestroyRequest;
use App\Models\Playlist;
use App\Models\User;
use App\Repositories\UserRepository;
use App\Services\PlaylistCollaborationService;
use Illuminate\Http\Response;
@ -32,7 +31,6 @@ class PlaylistCollaboratorController extends Controller
{
$this->authorize('own', $playlist);
/** @var User $collaborator */
$collaborator = $this->userRepository->getOne($request->collaborator);
try {

View file

@ -9,7 +9,6 @@ use App\Http\Requests\API\PlaylistStoreRequest;
use App\Http\Requests\API\PlaylistUpdateRequest;
use App\Http\Resources\PlaylistResource;
use App\Models\Playlist;
use App\Models\PlaylistFolder;
use App\Models\User;
use App\Repositories\PlaylistFolderRepository;
use App\Repositories\PlaylistRepository;
@ -40,7 +39,6 @@ class PlaylistController extends Controller
$folder = null;
if ($request->folder_id) {
/** @var PlaylistFolder $folder */
$folder = $this->folderRepository->getOne($request->folder_id);
$this->authorize('own', $folder);
}
@ -68,7 +66,6 @@ class PlaylistController extends Controller
$folder = null;
if ($request->folder_id) {
/** @var PlaylistFolder $folder */
$folder = $this->folderRepository->getOne($request->folder_id);
$this->authorize('own', $folder);
}

View file

@ -19,7 +19,6 @@ class RegisterPlayController extends Controller
InteractionService $interactionService,
?Authenticatable $user
) {
/** @var Song $song */
$song = Song::query()->findOrFail($request->song);
$this->authorize('access', $song);

View file

@ -7,7 +7,6 @@ use App\Http\Requests\API\ToggleLikeSongRequest;
use App\Http\Resources\InteractionResource;
use App\Models\Song;
use App\Models\User;
use App\Repositories\SongRepository;
use App\Services\InteractionService;
use Illuminate\Contracts\Auth\Authenticatable;
@ -16,7 +15,6 @@ class ToggleLikeSongController extends Controller
/** @param User $user */
public function __invoke(
ToggleLikeSongRequest $request,
SongRepository $songRepository,
InteractionService $interactionService,
?Authenticatable $user
) {

View file

@ -3,7 +3,6 @@
namespace App\Http\Resources;
use App\Models\Playlist;
use App\Models\User;
use Illuminate\Http\Resources\Json\JsonResource;
class PlaylistResource extends JsonResource
@ -28,7 +27,6 @@ class PlaylistResource extends JsonResource
/** @return array<mixed> */
public function toArray($request): array
{
/** @var User $user */
$user = $request->user() ?? $this->playlist->user;
return [

View file

@ -17,12 +17,9 @@ class AuthServiceProvider extends ServiceProvider
$this->registerPolicies();
Auth::viaRequest('token-via-query-parameter', static function (Request $request): ?User {
/** @var TokenManager $tokenManager */
$tokenManager = app(TokenManager::class);
$token = $request->get('api_token') ?: $request->get('t');
return $tokenManager->getUserFromPlainTextToken($token ?: '');
return app(TokenManager::class)->getUserFromPlainTextToken($token ?: '');
});
$this->setPasswordDefaultRules();

View file

@ -11,6 +11,9 @@ use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
/**
* @extends Repository<Album>
*/
class AlbumRepository extends Repository
{
/** @return Collection|array<array-key, Album> */
@ -29,7 +32,6 @@ class AlbumRepository extends Repository
/** @return Collection|array<array-key, Album> */
public function getMostPlayed(int $count = 6, ?User $user = null): Collection
{
/** @var ?User $user */
$user ??= $this->auth->user();
return Album::query()

View file

@ -11,12 +11,12 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection as BaseCollection;
/** @extends Repository<Artist> */
class ArtistRepository extends Repository
{
/** @return Collection|array<array-key, Artist> */
public function getMostPlayed(int $count = 6, ?User $user = null): Collection
{
/** @var ?User $user */
$user ??= auth()->user();
return Artist::query()
@ -44,7 +44,7 @@ class ArtistRepository extends Repository
}
/** @return Collection|array<array-key, Artist> */
public function getMany(array $ids, bool $inThatOrder = false, ?User $user = null): Collection | BaseCollection
public function getMany(array $ids, bool $inThatOrder = false, ?User $user = null): Collection|BaseCollection
{
$artists = Artist::query()
->isStandard()

View file

@ -2,6 +2,11 @@
namespace App\Repositories;
use App\Models\PlaylistFolder;
/**
* @extends Repository<PlaylistFolder>
*/
class PlaylistFolderRepository extends Repository
{
}

View file

@ -7,6 +7,7 @@ use App\Models\Playlist;
use App\Models\User;
use Illuminate\Support\Collection;
/** @extends Repository<Playlist> */
class PlaylistRepository extends Repository
{
/** @return Collection<array-key, Playlist> */

View file

@ -7,6 +7,7 @@ use Illuminate\Contracts\Auth\Guard;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
/** @template T of Model */
abstract class Repository implements RepositoryInterface
{
private string $modelClass;
@ -28,17 +29,19 @@ abstract class Repository implements RepositoryInterface
return preg_replace('/(.+)\\\\Repositories\\\\(.+)Repository$/m', '$1\Models\\\$2', static::class);
}
/** @return T */
public function getOne($id): Model
{
return $this->model->findOrFail($id);
return $this->model::query()->findOrFail($id);
}
/** @return T|null */
public function findOne($id): ?Model
{
return $this->model->find($id);
return $this->model::query()->find($id);
}
/** @return Collection<array-key, Model> */
/** @return array<array-key, T>|Collection<array-key, T> */
public function getMany(array $ids, bool $inThatOrder = false): Collection
{
$models = $this->model::query()->find($ids);
@ -46,19 +49,15 @@ abstract class Repository implements RepositoryInterface
return $inThatOrder ? $models->orderByArray($ids) : $models;
}
/** @return Collection<array-key, Model> */
/** @return array<array-key, T>|Collection<array-key, T> */
public function getAll(): Collection
{
return $this->model->all();
return $this->model::all();
}
/** @return T|null */
public function getFirstWhere(...$params): ?Model
{
return $this->model->firstWhere(...$params);
}
public function getModelClass(): string
{
return $this->modelClass;
return $this->model::query()->firstWhere(...$params);
}
}

View file

@ -4,6 +4,7 @@ namespace App\Repositories;
use App\Models\Setting;
/** @extends Repository<Setting> */
class SettingRepository extends Repository
{
/** @return array<mixed> */

View file

@ -13,6 +13,7 @@ use App\Values\Genre;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Support\Collection;
/** @extends Repository<Song> */
class SongRepository extends Repository
{
private const DEFAULT_QUEUE_LIMIT = 500;
@ -22,7 +23,7 @@ class SongRepository extends Repository
return Song::query()->where('path', $path)->first();
}
/** @return Collection|array<Song> */
/** @return Collection|array<array-key, Song> */
public function getAllStoredOnCloud(): Collection
{
return Song::query()->storedOnCloud()->get();
@ -31,7 +32,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getRecentlyAdded(int $count = 10, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -45,7 +45,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getMostPlayed(int $count = 7, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -60,7 +59,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getRecentlyPlayed(int $count = 7, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -78,7 +76,6 @@ class SongRepository extends Repository
?User $scopedUser = null,
int $perPage = 50
): Paginator {
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -96,7 +93,6 @@ class SongRepository extends Repository
?User $scopedUser = null,
int $perPage = 50
): Paginator {
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -114,7 +110,6 @@ class SongRepository extends Repository
int $limit = self::DEFAULT_QUEUE_LIMIT,
?User $scopedUser = null,
): Collection {
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -128,7 +123,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getFavorites(?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -141,7 +135,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getByAlbum(Album $album, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -157,7 +150,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getByArtist(Artist $artist, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -175,7 +167,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getByStandardPlaylist(Playlist $playlist, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -202,7 +193,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getRandom(int $limit, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -216,7 +206,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getMany(array $ids, bool $inThatOrder = false, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
$songs = Song::query()
@ -235,7 +224,6 @@ class SongRepository extends Repository
*/
public function getManyInCollaborativeContext(array $ids, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -260,7 +248,6 @@ class SongRepository extends Repository
/** @param string $id */
public function getOne($id, ?User $scopedUser = null): Song
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -272,7 +259,6 @@ class SongRepository extends Repository
/** @param string $id */
public function findOne($id, ?User $scopedUser = null): ?Song
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()
@ -294,7 +280,6 @@ class SongRepository extends Repository
/** @return Collection|array<array-key, Song> */
public function getRandomByGenre(string $genre, int $limit, ?User $scopedUser = null): Collection
{
/** @var ?User $scopedUser */
$scopedUser ??= $this->auth->user();
return Song::query()

View file

@ -7,6 +7,9 @@ namespace App\Repositories;
use App\Models\User;
use App\Values\SSOUser;
/**
* @extends Repository<User>
*/
class UserRepository extends Repository
{
public function getDefaultAdminUser(): User

View file

@ -24,7 +24,6 @@ class AuthenticationService
public function login(string $email, string $password): CompositeToken
{
/** @var User|null $user */
$user = $this->userRepository->getFirstWhere('email', $email);
if (!$user || !$this->hash->check($password, $user->password)) {
@ -82,9 +81,6 @@ class AuthenticationService
public function loginViaOneTimeToken(string $token): CompositeToken
{
/** @var User $user */
$user = $this->userRepository->getOne(decrypt(Cache::get("one-time-token.$token")));
return $this->logUserIn($user);
return $this->logUserIn($this->userRepository->getOne(decrypt(Cache::get("one-time-token.$token"))));
}
}

View file

@ -5,7 +5,6 @@ namespace App\Services;
use App\Enums\SongStorageType;
use App\Models\Song;
use App\Models\SongZipArchive;
use App\Services\SongStorages\CloudStorage;
use App\Services\SongStorages\DropboxStorage;
use App\Services\SongStorages\S3CompatibleStorage;
use Illuminate\Support\Collection;
@ -37,13 +36,11 @@ class DownloadService
switch ($song->storage) {
case SongStorageType::DROPBOX:
/** @var CloudStorage $cloudStorage */
$cloudStorage = app(DropboxStorage::class);
break;
case SongStorageType::S3:
case SongStorageType::S3_LAMBDA:
/** @var CloudStorage $cloudStorage */
$cloudStorage = app(S3CompatibleStorage::class);
break;

View file

@ -75,7 +75,6 @@ class LicenseService implements LicenseServiceInterface
return Cache::get('license_status');
}
/** @var ?License $license */
$license = License::query()->latest()->first();
if (!$license) {

View file

@ -31,7 +31,6 @@ class PlaylistCollaborationService
public function acceptUsingToken(string $token, User $user): Playlist
{
/** @var PlaylistCollaborationToken $collaborationToken */
$collaborationToken = PlaylistCollaborationToken::query()->where('token', $token)->firstOrFail();
throw_if($collaborationToken->expired, PlaylistCollaborationTokenExpiredException::class);

View file

@ -42,7 +42,6 @@ class PlaylistService
return DB::transaction(
static function () use ($name, $user, $songs, $folder, $ruleGroups, $ownSongsOnly): Playlist {
/** @var Playlist $playlist */
$playlist = $user->playlists()->create([
'name' => $name,
'rules' => $ruleGroups,

View file

@ -15,7 +15,6 @@ class QueueService
public function getQueueState(User $user): QueueStateDTO
{
/** @var QueueState $state */
$state = QueueState::query()->where('user_id', $user->id)->firstOrCreate([
'user_id' => $user->id,
], [

View file

@ -60,8 +60,7 @@ final class S3LambdaStorage extends S3CompatibleStorage
$this->mediaMetadataService->writeAlbumCover($album, base64_decode($cover['data'], true));
}
/** @var Song $song */
$song = Song::query()->updateOrCreate(['path' => $path], [
return Song::query()->updateOrCreate(['path' => $path], [
'album_id' => $album->id,
'artist_id' => $artist->id,
'title' => $title,
@ -73,8 +72,6 @@ final class S3LambdaStorage extends S3CompatibleStorage
'is_public' => true,
'storage' => SongStorageType::S3_LAMBDA,
]);
return $song;
}
public function deleteSongEntry(string $bucket, string $key): void

View file

@ -44,7 +44,6 @@ class UserInvitationService
private function inviteOne(string $email, bool $isAdmin, User $invitor): User
{
/** @var User $invitee */
$invitee = User::query()->create([
'name' => '',
'email' => $email,

View file

@ -25,7 +25,6 @@ class CreateVariousArtists extends Migration
Artist::unguard();
/** @var Artist|null $existingArtist */
$existingArtist = Artist::query()->find(Artist::VARIOUS_ID);
if ($existingArtist) {
@ -35,7 +34,6 @@ class CreateVariousArtists extends Migration
// There's an existing artist with that special ID, but it's not our Various Artist
// We move it to the end of the table.
/** @var Artist $latestArtist */
$latestArtist = Artist::query()->orderByDesc('id')->first();
$existingArtist->id = $latestArtist->id + 1;
$existingArtist->save();

View file

@ -1,14 +1,12 @@
<?php
use App\Models\Song;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Migrations\Migration;
class CopyArtistToContributingArtist extends Migration
{
public function up(): void
{
/** @var Collection<array-key, Song> $songs */
$songs = Song::with('album', 'album.artist')->get();
$songs->each(static function (Song $song): void {

View file

@ -16,7 +16,6 @@ return new class extends Migration {
});
Schema::table('songs', static function (Blueprint $table): void {
/** @var ?User $firstAdmin */
$firstAdmin = User::query()->where('is_admin', true)->oldest()->first();
if ($firstAdmin === null) {

View file

@ -28,6 +28,7 @@ parameters:
- '#expects App\\Models\\User\|null, Illuminate\\Database\\Eloquent\\Collection\|Illuminate\\Database\\Eloquent\\Model given#'
- '#Method App\\Models\\.*::query\(\) should return App\\Builders\\.*Builder but returns Illuminate\\Database\\Eloquent\\Builder<Illuminate\\Database\\Eloquent\\Model>#'
- '#Parameter \#1 \$callback of method Illuminate\\Support\\Collection<int,Illuminate\\Database\\Eloquent\\Model>::each\(\) expects callable\(Illuminate\\Database\\Eloquent\\Model, int\)#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::#'
excludePaths:

View file

@ -24,7 +24,6 @@ class AlbumCoverTest extends TestCase
public function testUpdate(): void
{
/** @var Album $album */
$album = Album::factory()->create();
$this->mediaMetadataService
@ -38,7 +37,6 @@ class AlbumCoverTest extends TestCase
public function testUpdateNotAllowedForNormalUsers(): void
{
/** @var Album $album */
$album = Album::factory()->create();
$this->mediaMetadataService->shouldNotReceive('writeAlbumCover');

View file

@ -15,7 +15,6 @@ class AlbumInformationTest extends TestCase
config(['koel.lastfm.key' => 'foo']);
config(['koel.lastfm.secret' => 'geheim']);
/** @var Album $album */
$album = Album::factory()->create();
$lastfm = self::mock(MediaInformationService::class);
@ -51,10 +50,7 @@ class AlbumInformationTest extends TestCase
config(['koel.lastfm.key' => null]);
config(['koel.lastfm.secret' => null]);
/** @var Album $album */
$album = Album::factory()->create();
$this->getAs('api/albums/' . $album->id . '/information')
$this->getAs('api/albums/' . Album::factory()->create()->id . '/information')
->assertJsonStructure(AlbumInformation::JSON_STRUCTURE);
}
}

View file

@ -11,7 +11,6 @@ class AlbumSongTest extends TestCase
{
public function testIndex(): void
{
/** @var Album $album */
$album = Album::factory()->create();
Song::factory(5)->for($album)->create();

View file

@ -18,10 +18,7 @@ class AlbumTest extends TestCase
public function testShow(): void
{
/** @var Album $album */
$album = Album::factory()->create();
$this->getAs('api/albums/' . $album->id)
$this->getAs('api/albums/' . Album::factory()->create()->id)
->assertJsonStructure(AlbumResource::JSON_STRUCTURE);
}
}

View file

@ -28,7 +28,6 @@ class AlbumThumbnailTest extends TestCase
/** @dataProvider provideAlbumThumbnailData */
public function testGetAlbumThumbnail(?string $thumbnailUrl): void
{
/** @var Album $createdAlbum */
$createdAlbum = Album::factory()->create();
$this->mediaMetadataService

View file

@ -11,7 +11,6 @@ class ArtistAlbumTest extends TestCase
{
public function testIndex(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
Album::factory(5)->for($artist)->create();

View file

@ -23,7 +23,6 @@ class ArtistImageTest extends TestCase
public function testUpdate(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
$this->mediaMetadataService

View file

@ -15,7 +15,6 @@ class ArtistInformationTest extends TestCase
config(['koel.lastfm.key' => 'foo']);
config(['koel.lastfm.secret' => 'geheim']);
/** @var Artist $artist */
$artist = Artist::factory()->create();
$lastfm = self::mock(MediaInformationService::class);
@ -39,10 +38,7 @@ class ArtistInformationTest extends TestCase
config(['koel.lastfm.key' => null]);
config(['koel.lastfm.secret' => null]);
/** @var Artist $artist */
$artist = Artist::factory()->create();
$this->getAs('api/artists/' . $artist->id . '/information')
$this->getAs('api/artists/' . Artist::factory()->create()->id . '/information')
->assertJsonStructure(ArtistInformation::JSON_STRUCTURE);
}
}

View file

@ -11,7 +11,6 @@ class ArtistSongTest extends TestCase
{
public function testIndex(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
Song::factory(5)->for($artist)->create();

View file

@ -18,10 +18,7 @@ class ArtistTest extends TestCase
public function testShow(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
$this->getAs('api/artists/' . $artist->id)
$this->getAs('api/artists/' . Artist::factory()->create()->id)
->assertJsonStructure(ArtistResource::JSON_STRUCTURE);
}
}

View file

@ -29,18 +29,14 @@ class DownloadTest extends TestCase
public function testNonLoggedInUserCannotDownload(): void
{
/** @var Song $song */
$song = Song::factory()->create();
$this->downloadService->shouldNotReceive('getDownloadablePath');
$this->get("download/songs?songs[]=$song->id")
$this->get('download/songs?songs[]=' . Song::factory()->create()->id)
->assertUnauthorized();
}
public function testDownloadOneSong(): void
{
/** @var Song $song */
$song = Song::factory()->create();
$user = create_user();
@ -58,7 +54,6 @@ class DownloadTest extends TestCase
public function testDownloadMultipleSongs(): void
{
/** @var array<Song>|Collection $songs */
$songs = Song::factory(2)->create();
$user = create_user();
@ -81,7 +76,6 @@ class DownloadTest extends TestCase
public function testDownloadAlbum(): void
{
/** @var Album $album */
$album = Album::factory()->create();
$songs = Song::factory(3)->for($album)->create();
$user = create_user();
@ -102,7 +96,6 @@ class DownloadTest extends TestCase
public function testDownloadArtist(): void
{
/** @var Artist $artist */
$artist = Artist::factory()->create();
$songs = Song::factory(3)->for($artist)->create();
$user = create_user();
@ -128,7 +121,6 @@ class DownloadTest extends TestCase
/** @var Playlist $playlist */
$playlist = Playlist::factory()->for($user)->create();
$playlist->addSongs($songs);
$this->downloadService
@ -147,11 +139,9 @@ class DownloadTest extends TestCase
public function testNonOwnerCannotDownloadPlaylist(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$user = create_user();
$this->get("download/playlist/{$playlist->id}?api_token=" . $user->createToken('Koel')->plainTextToken)
$this->get("download/playlist/{$playlist->id}?api_token=" . create_user()->createToken('Koel')->plainTextToken)
->assertForbidden();
}

View file

@ -7,7 +7,6 @@ use App\Events\PlaybackStarted;
use App\Events\SongLikeToggled;
use App\Models\Interaction;
use App\Models\Song;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
@ -20,9 +19,8 @@ class InteractionTest extends TestCase
Event::fake(PlaybackStarted::class);
$user = create_user();
/** @var Song $song */
$song = Song::factory()->create();
$this->postAs('api/interaction/play', ['song' => $song->id], $user);
self::assertDatabaseHas(Interaction::class, [
@ -46,9 +44,8 @@ class InteractionTest extends TestCase
Event::fake(SongLikeToggled::class);
$user = create_user();
/** @var Song $song */
$song = Song::factory()->create();
$this->postAs('api/interaction/like', ['song' => $song->id], $user);
self::assertDatabaseHas(Interaction::class, [
@ -74,8 +71,6 @@ class InteractionTest extends TestCase
Event::fake(MultipleSongsLiked::class);
$user = create_user();
/** @var Collection<Song> $songs */
$songs = Song::factory(2)->create();
$songIds = $songs->pluck('id')->all();

View file

@ -7,7 +7,6 @@ use App\Services\TokenManager;
use Laravel\Sanctum\NewAccessToken;
use Laravel\Sanctum\PersonalAccessToken;
use Mockery;
use Mockery\MockInterface;
use Tests\TestCase;
use function Tests\create_user;
@ -28,7 +27,6 @@ class LastfmTest extends TestCase
$user = create_user();
$token = $user->createToken('Koel')->plainTextToken;
/** @var NewAccessToken|MockInterface $temporaryToken */
$temporaryToken = Mockery::mock(NewAccessToken::class);
$temporaryToken->plainTextToken = 'tmp-token';

View file

@ -16,7 +16,6 @@ class PlayCountTest extends TestCase
{
Event::fake(PlaybackStarted::class);
/** @var Interaction $interaction */
$interaction = Interaction::factory()->create([
'play_count' => 10,
]);
@ -38,9 +37,7 @@ class PlayCountTest extends TestCase
{
Event::fake(PlaybackStarted::class);
/** @var Song $song */
$song = Song::factory()->create();
$user = create_user();
$this->postAs('/api/interaction/play', ['song' => $song->id], $user)
@ -52,7 +49,6 @@ class PlayCountTest extends TestCase
'play_count',
]);
/** @var Interaction $interaction */
$interaction = Interaction::query()
->where('song_id', $song->id)
->where('user_id', $user->id)

View file

@ -23,7 +23,6 @@ class PlaylistCoverTest extends TestCase
public function testUploadCover(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
self::assertNull($playlist->cover);
@ -38,7 +37,6 @@ class PlaylistCoverTest extends TestCase
public function testUploadCoverNotAllowedForNonOwner(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$this->mediaMetadataService->shouldNotReceive('writePlaylistCover');

View file

@ -33,7 +33,6 @@ class PlaylistFolderTest extends TestCase
public function testUpdate(): void
{
/** @var PlaylistFolder $folder */
$folder = PlaylistFolder::factory()->create(['name' => 'Metal']);
$this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user)
@ -44,7 +43,6 @@ class PlaylistFolderTest extends TestCase
public function testUnauthorizedUpdate(): void
{
/** @var PlaylistFolder $folder */
$folder = PlaylistFolder::factory()->create(['name' => 'Metal']);
$this->patchAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'])
@ -55,7 +53,6 @@ class PlaylistFolderTest extends TestCase
public function testDelete(): void
{
/** @var PlaylistFolder $folder */
$folder = PlaylistFolder::factory()->create();
$this->deleteAs('api/playlist-folders/' . $folder->id, ['name' => 'Classical'], $folder->user)