Skip to content

Commit

Permalink
Use lazy-loading in FileTrait; Add informative exception if the fil…
Browse files Browse the repository at this point in the history
…e is missing in `FileTrait`.
  • Loading branch information
priyadi committed Dec 27, 2023
1 parent 9e5f4d1 commit 0bfdfa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 1.7.3

* Use lazy-loading in `FileTrait`.
* Add informative exception if the file is missing in `FileTrait`.

## 1.7.2

* Fix typehints
Expand Down
6 changes: 5 additions & 1 deletion packages/file-association-entity/src/FileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait FileTrait
{
use FileDecoratorTrait;

#[AsFileAssociation]
#[AsFileAssociation(fetch: 'LAZY')]
private FileInterface $file;

#[Embedded()]
Expand All @@ -50,6 +50,10 @@ private function setWrapped(FileInterface $file): void

private function getWrapped(): FileInterface
{
if (!isset($this->file)) {

Check failure on line 53 in packages/file-association-entity/src/FileTrait.php

View workflow job for this annotation

GitHub Actions / Symfony 6.*, highest deps, PHP 8.1, ubuntu-latest

RedundantPropertyInitializationCheck

packages/file-association-entity/src/FileTrait.php:53:14: RedundantPropertyInitializationCheck: Property $this->file with type Rekalogika\Contracts\File\FileInterface should already be set in the constructor (see https://psalm.dev/261)

Check failure on line 53 in packages/file-association-entity/src/FileTrait.php

View workflow job for this annotation

GitHub Actions / Symfony 6.*, highest deps, PHP 8.3, ubuntu-latest

RedundantPropertyInitializationCheck

packages/file-association-entity/src/FileTrait.php:53:14: RedundantPropertyInitializationCheck: Property $this->file with type Rekalogika\Contracts\File\FileInterface should already be set in the constructor (see https://psalm.dev/261)
throw new \LogicException(sprintf('$file is not set. This might be caused by the use of `AbstractQuery::toIterable()`. If that is the case, you can: 1. stop involving "%s" in the query; 2. pre-hydrate the file entities before the query; or 3. use other means to iterate the query.', static::class));
}

return FileDecorator::getFile($this->file, $this->getMetadata()) ?? new NullFile();
}
}

0 comments on commit 0bfdfa8

Please sign in to comment.