Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Dec 21, 2023
1 parent 54bdb4c commit 4197ee9
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 510 deletions.
77 changes: 77 additions & 0 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/Actions/Album/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ private function compressAlbum(AbstractAlbum $album, array &$usedDirNames, ?stri
return;
}

$fullNameOfDirectory = $this->makeUnique(self::createValidTitle($album->title), $usedDirNames); // @phpstan-ignore-line
$fullNameOfDirectory = $this->makeUnique(self::createValidTitle($album->title), $usedDirNames);
if ($fullNameOfParent !== '') {
$fullNameOfDirectory = $fullNameOfParent . '/' . $fullNameOfDirectory;
}

$usedFileNames = [];
// TODO: Ensure that the size variant `original` for each photo is eagerly loaded as it is needed below. This must be solved in close coordination with `ArchiveAlbumRequest`.
$photos = $album->photos; // @phpstan-ignore-line
$photos = $album->photos;

/** @var Photo $photo */
foreach ($photos as $photo) {
Expand Down
6 changes: 2 additions & 4 deletions app/Actions/Diagnostics/Pipes/Checks/ForeignKeyListInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ private function sqlite(array &$data): void
$fks = DB::select("SELECT m.name , p.* FROM sqlite_master m JOIN pragma_foreign_key_list(m.name) p ON m.name != p.\"table\" WHERE m.type = 'table' ORDER BY m.name;");

foreach ($fks as $fk) {
/** @phpstan-ignore-next-line */
$data[] = sprintf('Foreign key: %-30s → %-20s : %s', $fk->name . '.' . $fk->from, $fk->table . '.' . $fk->to, $fk->on_update);
$data[] = sprintf('Foreign key: %-30s → %-20s : %s', $fk->name . '.' . $fk->from, $fk->table . '.' . $fk->to, strval($fk->on_update));
}
}

Expand All @@ -51,11 +50,10 @@ private function mysql(array &$data): void
order by fks.constraint_schema, fks.table_name;
');
foreach ($fks as $fk) {
/** @phpstan-ignore-next-line */
$data[] = sprintf('Foreign key: %-30s → %-20s : %s',
$fk->TABLE_NAME . '.' . $fk->COLUMN_NAME,
$fk->REFERENCED_TABLE_NAME . '.' . $fk->REFERENCED_COLUMN_NAME,
$fk->UPDATE_RULE);
strval($fk->UPDATE_RULE));
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Photo/Strategies/AddStandaloneStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function do(): Photo
// The original and final checksum may differ, if the photo has
// been rotated by `putSourceIntoFinalDestination` while being
// moved into final position.
$this->photo->checksum = $streamStat->checksum; // @phpstan-ignore-line
$this->photo->checksum = $streamStat->checksum;
$this->photo->save();

// Create original size variant of photo
Expand All @@ -173,7 +173,7 @@ public function do(): Photo
SizeVariantType::ORIGINAL,
$targetFile->getRelativePath(),
$imageDim,
$streamStat->bytes // @phpstan-ignore-line
$streamStat->bytes
);
} catch (LycheeException $e) {
// If source file could not be put into final destination, remove
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Photo/Strategies/RotateStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public function do(): Photo

// The checksum has been changed due to rotation.
$oldChecksum = $this->photo->checksum;
$this->photo->checksum = $streamStat->checksum; // @phpstan-ignore-line
$this->photo->checksum = $streamStat->checksum;
$this->photo->save();

// Re-create original size variant of photo
$newOriginalSizeVariant = $this->photo->size_variants->create(
SizeVariantType::ORIGINAL,
$targetFile->getRelativePath(),
$image->getDimensions(),
$streamStat->bytes // @phpstan-ignore-line
$streamStat->bytes
);

// Re-create remaining size variants
Expand Down
6 changes: 1 addition & 5 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ protected function prepareResponse($request, \Throwable $e): RedirectResponse|Re
$e = new HttpException(500, $e->getMessage(), $e);
}

// `renderHttpException` expects `$e` to be an instance of
// `HttpExceptionInterface`.
// This is ensured by `isHttpException` above, but PHPStan does not
// understand that.
// @phpstan-ignore-next-line
/** @var HttpExceptionInterface $e */
return $this->toIlluminateResponse($this->renderHttpException($e), $e);
}

Expand Down
12 changes: 6 additions & 6 deletions app/Http/Requests/Album/MergeAlbumsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = Album::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
// `findOrFail` returns a union type, but we know that it returns the
// correct collection in this case
// TODO: As part of our `FixedQueryBuilder` we should also consider adding a method `findManyOrFail` which does not return an union type, but only a `Collection`.
// This would avoid using phpstan-ignore-next-line here and in many similar cases.
/** @var string $id */
$id = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
/** @var array<int,string> $ids */
$ids = $values[RequestAttribute::ALBUM_IDS_ATTRIBUTE];
$this->album = Album::query()->findOrFail($id);
// @phpstan-ignore-next-line
$this->albums = Album::query()
->with(['children'])
->findOrFail($values[RequestAttribute::ALBUM_IDS_ATTRIBUTE]);
->findOrFail($ids);
}
}
14 changes: 7 additions & 7 deletions app/Http/Requests/Album/MoveAlbumsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
$targetAlbumID = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = $targetAlbumID === null ?
/** @var string|null $id */
$id = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
/** @var array<int,string> $ids */
$ids = $values[RequestAttribute::ALBUM_IDS_ATTRIBUTE];
$this->album = $id === null ?
null :
Album::query()->findOrFail($targetAlbumID);
// `findOrFail` returns a union type, but we know that it returns the
// correct collection in this case
// @phpstan-ignore-next-line
$this->albums = Album::query()->findOrFail($values[RequestAttribute::ALBUM_IDS_ATTRIBUTE]);
Album::findOrFail($id);
$this->albums = Album::findOrFail($ids);
}
}
8 changes: 3 additions & 5 deletions app/Http/Requests/Album/SetAlbumTagsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public function rules(): array
*/
protected function processValidatedValues(array $values, array $files): void
{
// `findOrFail` returns the union `TagAlbum|Collection<TagAlbum`
// which is not assignable to `TagAlbum`; but as we query for the ID
// we never get a collection
// @phpstan-ignore-next-line
$this->album = TagAlbum::query()->findOrFail($values[RequestAttribute::ALBUM_ID_ATTRIBUTE]);
/** @var string $id */
$id = $values[RequestAttribute::ALBUM_ID_ATTRIBUTE];
$this->album = TagAlbum::query()->findOrFail($id);
$this->tags = $values[RequestAttribute::SHOW_TAGS_ATTRIBUTE];
}
}
15 changes: 10 additions & 5 deletions app/Models/Extensions/UTCBasedTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models\Extensions;

use App\Exceptions\Internal\LycheeLogicException;
use Carbon\CarbonInterface;
use Carbon\Exceptions\InvalidTimeZoneException;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -81,10 +82,14 @@ public function fromDateTime($value): ?string
// If $value is already an instance of Carbon, the method returns a
// deep copy, hence it is safe to change the timezone below without
// altering the original object
if ($value === null || $value === '') {
return null;
}

$carbonTime = $this->asDateTime($value);
$carbonTime?->setTimezone(self::$DB_TIMEZONE_NAME);
$carbonTime->setTimezone(self::$DB_TIMEZONE_NAME);

return $carbonTime?->format(self::$DB_DATETIME_FORMAT);
return $carbonTime->format(self::$DB_DATETIME_FORMAT);
}

/**
Expand Down Expand Up @@ -123,14 +128,14 @@ public function fromDateTime($value): ?string
*
* @param mixed $value
*
* @return Carbon|null
* @return Carbon
*
* @throws InvalidTimeZoneException
*/
public function asDateTime($value): ?Carbon
public function asDateTime($value): Carbon
{
if ($value === null || $value === '') {
return null;
throw new LycheeLogicException('asDateTime called on null or empty string');
}

// If this value is already a Carbon instance, we shall just return it as is.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"itsgoingd/clockwork": "^5.1",
"lychee-org/phpstan-lychee": "^v1.0.1",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^2.0",
"larastan/larastan": "^2.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^10.0"
},
Expand Down
Loading

0 comments on commit 4197ee9

Please sign in to comment.