Refactor Classes
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
<?php /** @noinspection PhpUnusedPrivateFieldInspection */
|
||||
<?php
|
||||
/** @noinspection PhpUnusedPrivateFieldInspection */
|
||||
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Models;
|
||||
|
||||
use MyCLabs\Enum\Enum;
|
||||
|
||||
/**
|
||||
* Enum-Klasse für die unterstützten Periode-Definitionen.
|
||||
* Der Wert der Periode ist ein Format-String für {@link https://secure.php.net/manual/en/datetime.format.php}.
|
||||
*
|
||||
* @extends Enum<string>
|
||||
*
|
||||
* @method static PeriodDesignationEnum WEEKLY()
|
||||
* @method static PeriodDesignationEnum MONTHLY()
|
||||
* @method static PeriodDesignationEnum YEARLY()
|
||||
*/
|
||||
class PeriodDesignationEnum extends Enum
|
||||
enum PeriodDesignationEnum: string
|
||||
{
|
||||
private const WEEKLY = 'Y#W';
|
||||
private const MONTHLY = 'Y-m';
|
||||
private const YEARLY = 'Y';
|
||||
case WEEKLY = 'Y#W';
|
||||
case MONTHLY = 'Y-m';
|
||||
case YEARLY = 'Y';
|
||||
}
|
||||
@@ -10,42 +10,26 @@ use JetBrains\PhpStorm\ArrayShape;
|
||||
|
||||
class WorkingHours implements ModelInterface
|
||||
{
|
||||
protected ?DateTime $workingDay = null;
|
||||
protected ?DateTime $workingDay = null;
|
||||
protected ?DateInterval $workingTime = null;
|
||||
|
||||
/**
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function getWorkingDay(): ?DateTime
|
||||
{
|
||||
return $this->workingDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $workingDay
|
||||
*
|
||||
* @return WorkingHours
|
||||
*/
|
||||
public function setWorkingDay(DateTime $workingDay): WorkingHours
|
||||
public function setWorkingDay(DateTime $workingDay): static
|
||||
{
|
||||
$this->workingDay = $workingDay;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateInterval|null
|
||||
*/
|
||||
public function getWorkingTime(): ?DateInterval
|
||||
{
|
||||
return $this->workingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateInterval $workingTime
|
||||
*
|
||||
* @return WorkingHours
|
||||
*/
|
||||
public function setWorkingTime(DateInterval $workingTime): WorkingHours
|
||||
public function setWorkingTime(DateInterval $workingTime): static
|
||||
{
|
||||
$this->workingTime = $workingTime;
|
||||
return $this;
|
||||
@@ -58,7 +42,7 @@ class WorkingHours implements ModelInterface
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'workingDay' => $this->getWorkingDay()->format('Y-m-d'),
|
||||
'workingDay' => $this->getWorkingDay()->format('Y-m-d'),
|
||||
'workingTime' => $this->getWorkingTime()->format('%H:%I:%S')
|
||||
];
|
||||
}
|
||||
|
||||
@@ -10,21 +10,12 @@ use JetBrains\PhpStorm\ArrayShape;
|
||||
|
||||
class WorkingHoursView implements ModelInterface
|
||||
{
|
||||
protected DateTimeInterface $period;
|
||||
protected DateTimeInterface $period;
|
||||
protected PeriodDesignationEnum $periodDesignation;
|
||||
protected int $workingDays;
|
||||
protected DateInterval $totalHours;
|
||||
protected DateInterval $overtime;
|
||||
protected int $workingDays;
|
||||
protected DateInterval $totalHours;
|
||||
protected DateInterval $overtime;
|
||||
|
||||
/**
|
||||
* WorkingHoursView constructor.
|
||||
*
|
||||
* @param DateTimeInterface $period
|
||||
* @param PeriodDesignationEnum $periodDesignation
|
||||
* @param int $workingDays
|
||||
* @param DateInterval $totalHours
|
||||
* @param DateInterval $overtime
|
||||
*/
|
||||
public function __construct(
|
||||
DateTimeInterface $period,
|
||||
PeriodDesignationEnum $periodDesignation,
|
||||
@@ -39,41 +30,26 @@ class WorkingHoursView implements ModelInterface
|
||||
$this->overtime = $overtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface
|
||||
*/
|
||||
public function getPeriod(): DateTimeInterface
|
||||
{
|
||||
return $this->period;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PeriodDesignationEnum
|
||||
*/
|
||||
public function getPeriodDesignation(): PeriodDesignationEnum
|
||||
{
|
||||
return $this->periodDesignation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWorkingDays(): int
|
||||
{
|
||||
return $this->workingDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateInterval
|
||||
*/
|
||||
public function getTotalHours(): DateInterval
|
||||
{
|
||||
return $this->totalHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateInterval
|
||||
*/
|
||||
public function getOvertime(): DateInterval
|
||||
{
|
||||
return $this->overtime;
|
||||
@@ -84,17 +60,18 @@ class WorkingHoursView implements ModelInterface
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
#[ArrayShape(['period' => "string",
|
||||
'periodDesignation' => "string",
|
||||
'totalHours' => "string",
|
||||
'workingDays' => "int",
|
||||
'overtime' => "string"
|
||||
#[ArrayShape([
|
||||
'period' => "string",
|
||||
'periodDesignation' => "string",
|
||||
'totalHours' => "string",
|
||||
'workingDays' => "int",
|
||||
'overtime' => "string"
|
||||
])] public function jsonSerialize(): array
|
||||
{
|
||||
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
|
||||
return [
|
||||
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()),
|
||||
'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()),
|
||||
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->value),
|
||||
'periodDesignation' => strtolower($this->getPeriodDesignation()->name),
|
||||
'workingDays' => $this->getWorkingDays(),
|
||||
'totalHours' => $this->getTotalHours()->format('%H:%I:%S'),
|
||||
'overtime' => $this->getOvertime()->format($formatOvertime)
|
||||
|
||||
Reference in New Issue
Block a user