Skip to content

Commit

Permalink
Merge getId and findId into single method
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed May 16, 2024
1 parent 4418bb8 commit 34bf249
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Entity/Traits/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ trait Identifier


/**
* @return ($require is true ? int : ?int)
* @throws EntityNotPersistedException
*/
public function getId(): int
public function getId(bool $require = false): ?int
{
if (!$this->isPersisted()) {
if ($require && !$this->isPersisted()) {
throw EntityNotPersistedException::fromEntity($this);
}

return $this->id;
}


public function findId(): ?int
{
return $this->id ?? null;
}

Expand Down

0 comments on commit 34bf249

Please sign in to comment.