Skip to content

Commit

Permalink
Pushed common properties from Participant and Instructor to Participa…
Browse files Browse the repository at this point in the history
…tingPerson
  • Loading branch information
marekdedic committed Oct 8, 2023
1 parent b5f0f86 commit ec73d65
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 64 deletions.
33 changes: 2 additions & 31 deletions app/model/DTO/Instructor/Instructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,20 @@

use Model\DTO\Participant\ParticipatingPerson;
use Model\Participant\Payment;
use Model\Utils\MoneyFactory;

/**
* @property-read int $personId
* @property-read int $educationId
* @property-read string $educationName
* @property-read string $instructorType
* @property-read string $scoutExperience
* @property-read string $professionalExperience
* @property-read string $eventFocus
* @property-read float $payment
* @property-read float $repayment
* @property-read string $onAccount
*/
class Instructor extends ParticipatingPerson
{
private Payment $paymentObj;

public function __construct(
int $id,
private int $personId,
int $personId,
string $firstName,
string $lastName,
string|null $nickname = null,
Expand All @@ -38,14 +31,7 @@ public function __construct(
private string $eventFocus,
Payment $payment,
) {
parent::__construct($id, $firstName, $lastName, $nickname);

$this->paymentObj = $payment;
}

public function getPersonId(): int
{
return $this->personId;
parent::__construct($id, $personId, $firstName, $lastName, $nickname, $payment);
}

public function getEducationId(): int
Expand Down Expand Up @@ -77,19 +63,4 @@ public function getEventFocus(): string
{
return $this->eventFocus;
}

public function getPayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getPayment());
}

public function getRepayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getRepayment());
}

public function getOnAccount(): string
{
return $this->paymentObj->getAccount();
}
}
40 changes: 7 additions & 33 deletions app/model/DTO/Participant/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@

use Cake\Chronos\Date;
use Model\Participant\Payment;
use Model\Utils\MoneyFactory;

/**
* @property-read int $personId
* @property-read int|null $age
* @property-read Date|null $birthday
* @property-read string $unitRegistrationNumber
* @property-read string $street
* @property-read string $city
* @property-read int $postcode
* @property-read Date|null $birthday
* @property-read string $unitRegistrationNumber
* @property-read float $payment
* @property-read float $repayment
* @property-read string $onAccount
* @property-read string $state
* @property-read string $unit
* @property-read int $days
* @property-read string $category
*/
class Participant extends ParticipatingPerson
{
private Payment $paymentObj;

public function __construct(
int $id,
private int $personId,
int $personId,
string $firstName,
string $lastName,
string|null $nickName = null,
Expand All @@ -43,14 +39,7 @@ public function __construct(
Payment $payment,
private string|null $category = null,
) {
parent::__construct($id, $firstName, $lastName, $nickName);

$this->paymentObj = $payment;
}

public function getPersonId(): int
{
return $this->personId;
parent::__construct($id, $personId, $firstName, $lastName, $nickName, $payment);
}

public function getAge(): int|null
Expand Down Expand Up @@ -98,21 +87,6 @@ public function getDays(): int
return $this->days;
}

public function getPayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getPayment());
}

public function getRepayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getRepayment());
}

public function getOnAccount(): string
{
return $this->paymentObj->getAccount();
}

public function getCategory(): string
{
return $this->category ?? '';
Expand Down
31 changes: 31 additions & 0 deletions app/model/DTO/Participant/ParticipatingPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,48 @@

namespace Model\DTO\Participant;

use Model\Participant\Payment;
use Model\Utils\MoneyFactory;
use Nette\SmartObject;

/**
* @property-read int $id
* @property-read int $personId
* @property-read string $firstName
* @property-read string $lastName
* @property-read string $nickName
* @property-read string $displayName
* @property-read float $payment
* @property-read float $repayment
* @property-read string $onAccount
*/
class ParticipatingPerson
{
use SmartObject;

private Payment $paymentObj;

public function __construct(
private int $id,
private int $personId,
private string $firstName,
private string $lastName,
private string|null $nickName = null,
Payment $payment,
) {
$this->paymentObj = $payment;
}

public function getId(): int
{
return $this->id;
}

public function getPersonId(): int
{
return $this->personId;
}

public function getFirstName(): string
{
return $this->firstName;
Expand All @@ -49,4 +65,19 @@ public function getDisplayName(): string
{
return $this->lastName . ' ' . $this->firstName . ($this->nickName !== null ? '(' . $this->nickName . ')' : '');
}

public function getPayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getPayment());
}

public function getRepayment(): float
{
return MoneyFactory::toFloat($this->paymentObj->getRepayment());
}

public function getOnAccount(): string
{
return $this->paymentObj->getAccount();
}
}

0 comments on commit ec73d65

Please sign in to comment.