Skip to content

Commit

Permalink
Handle null value for target
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed May 17, 2024
1 parent 88a8736 commit b12ef0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/Entity/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,21 @@ public function getMessageTranslated(Translator $translator): Stringable|string
}


public function setTarget(object $target, mixed $targetId = null): void
public function setTarget(?object $target, mixed $targetId = null): void
{
if (is_null($target)) {
$this->targetId = null;
$this->target = null;

return;
}

if (!$targetId && $target instanceof Identified) {
$targetId ??= $target->getId();
}

$this->target = $target::class;
$this->targetId = $targetId;
$this->target = $target::class;

if ($target instanceof Proxy && $targetParent = get_parent_class($target)) {
$this->target = $targetParent;
Expand Down
4 changes: 2 additions & 2 deletions src/RecordBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* note?: ?string,
* finished?: bool,
* event?: ?string,
* target?: object,
* target?: ?object,
* owner?: ?Identity,
* params?: array<string, mixed>,
* }
Expand Down Expand Up @@ -134,7 +134,7 @@ public function withEvent(?string $event): static
}


public function withTarget(object $target): static
public function withTarget(?object $target): static
{
if ($target instanceof ParamsProvider) {
$this->withParams($target->getRecordParams());
Expand Down

0 comments on commit b12ef0c

Please sign in to comment.