diff --git a/src/Entity/Accounting/Accounting.php b/src/Entity/Accounting/Accounting.php index f19e377..8c8700a 100644 --- a/src/Entity/Accounting/Accounting.php +++ b/src/Entity/Accounting/Accounting.php @@ -43,6 +43,17 @@ class Accounting #[ORM\OneToOne(mappedBy: 'accounting', cascade: ['persist'])] private ?Tipjar $tipjar = null; + /** + * Create a new Accounting entity instance for the given owner. + */ + public static function of(AccountingOwnerInterface $owner): Accounting + { + $accounting = new Accounting(); + $accounting->setOwner($owner); + + return $accounting; + } + public function __construct() { /* diff --git a/src/Entity/Project/Project.php b/src/Entity/Project/Project.php index cb42bbc..7e619b3 100644 --- a/src/Entity/Project/Project.php +++ b/src/Entity/Project/Project.php @@ -60,10 +60,7 @@ class Project implements AccountingOwnerInterface public function __construct() { - $accounting = new Accounting(); - $accounting->setOwner($this); - - $this->accounting = $accounting; + $this->accounting = Accounting::of($this); $this->rewards = new ArrayCollection(); } diff --git a/src/Entity/Tipjar.php b/src/Entity/Tipjar.php index 621bd84..8a177e7 100644 --- a/src/Entity/Tipjar.php +++ b/src/Entity/Tipjar.php @@ -40,10 +40,7 @@ class Tipjar implements AccountingOwnerInterface public function __construct() { - $accounting = new Accounting(); - $accounting->setOwner($this); - - $this->accounting = $accounting; + $this->accounting = Accounting::of($this); } public function getId(): ?int diff --git a/src/Entity/User.php b/src/Entity/User.php index afa5a83..e8f01ac 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -141,10 +141,7 @@ class User implements UserInterface, UserOwnedInterface, PasswordAuthenticatedUs public function __construct() { - $accounting = new Accounting(); - $accounting->setOwner($this); - - $this->accounting = $accounting; + $this->accounting = Accounting::of($this); $this->emailConfirmed = false; $this->active = false;