Skip to content

Commit

Permalink
Simplify accounting creation with specified ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Nov 28, 2024
1 parent c285ade commit 8440f16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/Entity/Accounting/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
/*
Expand Down
5 changes: 1 addition & 4 deletions src/Entity/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 1 addition & 4 deletions src/Entity/Tipjar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8440f16

Please sign in to comment.