Skip to content

Commit

Permalink
Composer update (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Jun 10, 2024
1 parent d5988b1 commit c6a81d1
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 46 deletions.
6 changes: 3 additions & 3 deletions app/Actions/Albums/Top.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Illuminate\Support\Collection as BaseCollection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Kalnoy\Nestedset\QueryBuilder as NsQueryBuilder;

class Top
{
Expand Down Expand Up @@ -82,14 +81,14 @@ public function get(): TopAlbumsResource
->orderBy($this->sorting->column, $this->sorting->order)
->get();

/** @var NsQueryBuilder $query */
/** @return AlbumBuilder $query */
$query = $this->albumQueryPolicy
->applyVisibilityFilter(Album::query()->with(['access_permissions', 'owner'])->whereIsRoot());

$userID = Auth::id();
if ($userID !== null) {
// For authenticated users we group albums by ownership.
/** @var BaseCollection<int,Album> $albums */
/** @phpstan-ignore-next-line */
$albums = (new SortingDecorator($query))
->orderBy(ColumnSortingType::OWNER_ID, OrderSortingType::ASC)
->orderBy($this->sorting->column, $this->sorting->order)
Expand All @@ -106,6 +105,7 @@ public function get(): TopAlbumsResource
// For anonymous users we don't want to implicitly expose
// ownership via sorting.
/** @var BaseCollection<int,Album> */
/** @phpstan-ignore-next-line */
$albums = (new SortingDecorator($query))
->orderBy($this->sorting->column, $this->sorting->order)
->get();
Expand Down
8 changes: 4 additions & 4 deletions app/Actions/Albums/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function get(): AlbumForestResource
}
$query->orderBy($this->sorting->column, $this->sorting->order);

/** @var NsCollection<int,Album> $albums */
/** @var NsCollection<int,string,Album> $albums */
$albums = $query->get();
/** @var ?NsCollection<int,Album> $sharedAlbums */
/** @var ?NsCollection<int,string,Album> $sharedAlbums */
$sharedAlbums = null;
$userID = Auth::id();
if ($userID !== null) {
Expand All @@ -75,8 +75,8 @@ public function get(): AlbumForestResource
// (sub)-tree and then `toTree` will return garbage as it does
// not find connected paths within `$albums` or `$sharedAlbums`,
// resp.
/** @var NsCollection<int,Album> $albums */
/** @var ?NsCollection<int,Album> $sharedAlbums */
/** @var NsCollection<int,string,Album> $albums */
/** @var ?NsCollection<int,string,Album> $sharedAlbums */
list($albums, $sharedAlbums) = $albums->partition(fn (Album $album) => $album->owner_id === $userID);
}

Expand Down
1 change: 0 additions & 1 deletion app/Actions/Search/AlbumSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function queryAlbums(array $terms): Collection

$sorting = AlbumSortingCriterion::createDefault();

/** @phpstan-ignore-next-line */
return (new SortingDecorator($albumQuery))
->orderBy($sorting->column, $sorting->order)
->get();
Expand Down
2 changes: 0 additions & 2 deletions app/Factories/AlbumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public function findBaseAlbumOrFail(string $albumID, bool $withRelations = true)
}

try {
// PHPStan does not understand that `findOrFail` returns `BaseAlbum`, but assumes that it returns `Model`
// @phpstan-ignore-next-line
return $albumQuery->findOrFail($albumID);
} catch (ModelNotFoundException) {
try {
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Requests/Album/AddAlbumRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
/** @var string|null */
$parentAlbumID = $values[RequestAttribute::PARENT_ID_ATTRIBUTE];
$this->parentAlbum = $parentAlbumID === null ?
null :
Album::query()->findOrFail(
$values[RequestAttribute::PARENT_ID_ATTRIBUTE]
);
Album::query()->findOrFail($parentAlbumID);
$this->title = $values[RequestAttribute::TITLE_ATTRIBUTE];
}
}
4 changes: 3 additions & 1 deletion app/Http/Requests/Album/DeleteTrackRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = Album::query()->findOrFail($albumID);
}
}
1 change: 1 addition & 0 deletions app/Http/Requests/Album/MoveAlbumsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function processValidatedValues(array $values, array $files): void
$this->album = $id === null ?
null :
Album::findOrFail($id);
/** @phpstan-ignore-next-line */
$this->albums = Album::findOrFail($ids);
}
}
5 changes: 4 additions & 1 deletion app/Http/Requests/Album/SetAlbumCoverRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];

$this->album = Album::query()->findOrFail($albumID);
/** @var ?string $photoID */
$photoID = $values[RequestAttribute::PHOTO_ID_ATTRIBUTE];
$this->photo = $photoID === null ? null : Photo::query()->findOrFail($photoID);
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Requests/Album/SetAlbumHeaderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];

$this->album = Album::query()->findOrFail($albumID);
/** @var ?string $photoID */
$photoID = $values[RequestAttribute::PHOTO_ID_ATTRIBUTE];
$this->photo = $photoID === null ? null : Photo::query()->findOrFail($photoID);
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Requests/Album/SetAlbumLicenseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];

$this->album = Album::query()->findOrFail($albumID);
$this->license = LicenseType::tryFrom($values[RequestAttribute::LICENSE_ATTRIBUTE]);
}
}
4 changes: 3 additions & 1 deletion app/Http/Requests/Album/SetAlbumTrackRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = Album::query()->findOrFail($albumID);
$this->file = $files[self::FILE_ATTRIBUTE];
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Import/ImportFromUrlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = $albumID === null ?
null :
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Import/ImportServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
/** @var string|null */
$albumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = $albumID === null ?
null :
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Photo/DuplicatePhotosRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected function processValidatedValues(array $values, array $files): void
$this->photos = Photo::query()
->with(['size_variants'])
->findOrFail($photosIDs);
/** @var string|null */
$targetAlbumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = $targetAlbumID === null ?
null :
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Photo/MovePhotosRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function processValidatedValues(array $values, array $files): void
$photosIDs = $values[RequestAttribute::PHOTO_IDS_ATTRIBUTE];
$this->photos = Photo::query()
->findOrFail($photosIDs);
/** @var string|null */
$targetAlbumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = $targetAlbumID === null ? null : Album::query()->findOrFail($targetAlbumID);
}
Expand Down
8 changes: 4 additions & 4 deletions app/Livewire/Components/Forms/Album/SearchAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ private function getAlbumsListWithPath(?int $lft, ?int $rgt, ?string $parent_id)
$query = (new SortingDecorator($unfiltered))
->orderBy($sorting->column, $sorting->order);

/** @var NsCollection<int,Album> $albums */
/** @var NsCollection<int,string,Album> $albums */
$albums = $query->get();
/** @var NsCollection<int,Album> $tree */
/** @var NsCollection<int,string,Album> $tree */
$tree = $albums->toTree(null);

$flat_tree = $this->flatten($tree);
Expand All @@ -115,8 +115,8 @@ private function getAlbumsListWithPath(?int $lft, ?int $rgt, ?string $parent_id)
/**
* Flatten the tree and create bread crumb paths.
*
* @param NsCollection<int,Album>|Collection<int,Album> $collection
* @param string $prefix
* @param NsCollection<int,string,Album>|Collection<int,Album> $collection
* @param string $prefix
*
* @return TAlbumSaved[]
*/
Expand Down
6 changes: 5 additions & 1 deletion app/Models/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@
* @method static AlbumBuilder|Album withoutRoot()
*
* // * @mixin \Eloquent
*
* @implements Node<string,Album>
*/
class Album extends BaseAlbum implements Node
{
/** @phpstan-use NodeTrait<string,Album> */
use NodeTrait;
use ToArrayThrowsNotImplemented;
use HasFactory;
Expand Down Expand Up @@ -220,13 +223,14 @@ public function children(): HasManyChildAlbums
/**
* Get query for descendants of the node.
*
* @return DescendantsRelation
* @return DescendantsRelation<string,Album>
*
* @throws QueryBuilderException
*/
public function descendants(): DescendantsRelation
{
try {
/** @var DescendantsRelation<string,Album> */
return new DescendantsRelation($this->newQuery(), $this);
} catch (\Throwable $e) {
throw new QueryBuilderException($e);
Expand Down
17 changes: 15 additions & 2 deletions app/Models/Builders/AlbumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
* @method $this whereNotIn(string $column, mixed $values, string $boolean = 'and')
* @method $this whereNull(string|array $columns, string $boolean = 'and', bool $not = false)
* @method $this orderByDesc($column)
*
* @extends NSQueryBuilder<string,Album>
*/
class AlbumBuilder extends NSQueryBuilder
{
Expand Down Expand Up @@ -94,14 +96,13 @@ public function getModels($columns = ['*']): array
// The parent method returns a `Model[]`, but we must return
// `Album[]` and we know that this is indeed the case as we have
// queried for albums
// @phpstan-ignore-next-line
return parent::getModels($columns);
}

/**
* Get statistics of errors of the tree.
*
* @return array<string,int>
* @return array{oddness:int,duplicates:int,wrong_parent:int,missing_parent:int}
*
* @throws QueryBuilderException
*/
Expand Down Expand Up @@ -266,4 +267,16 @@ private function applyVisibilityConditioOnPhotos(Builder $countQuery, AlbumQuery

return $countQuery->where($visibilitySubQuery);
}

/**
* Scope limits query to select just root node.
*
* @return AlbumBuilder
*/
public function whereIsRoot(): AlbumBuilder
{
$this->query->whereNull($this->model->getParentIdName());

return $this;
}
}
1 change: 0 additions & 1 deletion app/Relations/HasManyChildAlbums.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function __construct(Album $owningAlbum)
$this->albumQueryPolicy = resolve(AlbumQueryPolicy::class);
$this->sorting = $owningAlbum->album_sorting ?? AlbumSortingCriterion::createDefault();
parent::__construct(
/** @phpstan-ignore-next-line */
$owningAlbum->newQuery(),
$owningAlbum,
'parent_id',
Expand Down
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function up(): void
$table->index([self::LEFT, self::RIGHT]);
});

NestedSetForAlbums_AlbumModel::query()->fixTree(); /** @phpstan-ignore-line */
NestedSetForAlbums_AlbumModel::query()->fixTree();
}

/**
Expand Down
Loading

0 comments on commit c6a81d1

Please sign in to comment.