refactor/update #30

Merged
TorstenHettstedt merged 15 commits from refactor/update into master 2025-06-16 15:48:34 +02:00
7 changed files with 23 additions and 33 deletions
Showing only changes of commit d52a9d77ab - Show all commits
+7 -16
View File
@@ -10,24 +10,14 @@ use JetBrains\PhpStorm\ArrayShape;
class WorkingHoursView implements ModelInterface
{
protected DateTimeInterface $period;
protected PeriodDesignationEnum $periodDesignation;
protected int $workingDays;
protected DateInterval $totalHours;
protected DateInterval $overtime;
public function __construct(
DateTimeInterface $period,
PeriodDesignationEnum $periodDesignation,
int $workingDays,
DateInterval $totalHours,
DateInterval $overtime
protected DateTimeInterface $period,
protected PeriodDesignationEnum $periodDesignation,
protected int $workingDays,
protected DateInterval $totalHours,
protected DateInterval $overtime
TorstenHettstedt marked this conversation as resolved Outdated
Outdated
Review

ist es nicht besser, die ganzen Parameter über den Konstrukt zu bestimmen?

ist es nicht besser, die ganzen Parameter über den Konstrukt zu bestimmen?
) {
$this->period = $period;
$this->periodDesignation = $periodDesignation;
$this->workingDays = $workingDays;
$this->totalHours = $totalHours;
$this->overtime = $overtime;
}
public function getPeriod(): DateTimeInterface
@@ -66,7 +56,8 @@ class WorkingHoursView implements ModelInterface
'totalHours' => "string",
'workingDays' => "int",
'overtime' => "string"
])] public function jsonSerialize(): array
])]
public function jsonSerialize(): array
{
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
return [
@@ -12,7 +12,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewRepository
{
protected const SQL_SELECT = <<<SQL
protected const string SQL_SELECT = <<<SQL
select
"Monat" as "period",
"Gesamtarbeitszeit" as "totalHours",
@@ -20,7 +20,7 @@ class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewReposito
"Überstunden" as "overtime"
from "Arbeitszeiten - Monat"
SQL;
protected const SQL_WHERE = ' where "Monat" = ?';
protected const string SQL_WHERE = ' where "Monat" = ?';
public function __construct(PDO $database)
{
@@ -20,6 +20,13 @@ use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
*/
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
{
protected const string SQL_SELECT = <<<'SQL'
select
"Datum" as "workingDay",
"Arbeitszeit" as "workingTime"
from public."Arbeitszeiten"
SQL;
public function __construct(protected PDO $database)
{
@@ -88,7 +95,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
protected function buildFindFilteredStatement(?string $start, ?string $end): ?PDOStatement
{
$query = 'select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" ';
$query = static::SQL_SELECT . ' ';
$query .= $this->buildFilterString($start, $end);
$query .= 'order by "Datum"';
$stmt = $this->database->prepare($query);
1
@@ -113,9 +120,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
*/
public function findByKey(mixed $primary_key): WorkingHours
{
$stmt = $this->database->prepare(
'select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" where "Datum" = ?'
);
$stmt = $this->database->prepare(static::SQL_SELECT . ' where "Datum" = ?');
$stmt->bindParam(1, $primary_key);
$stmt->execute();
$row = $stmt->fetch();
@@ -11,7 +11,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepository
{
protected const SQL_SELECT = <<<SQL
protected const string SQL_SELECT = <<<SQL
select
"Woche" as "period",
"Gesamtarbeitszeit" as "totalHours",
@@ -19,7 +19,7 @@ class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepositor
"Überstunden" as "overtime"
from "Arbeitszeiten - Woche"
SQL;
protected const SQL_WHERE = ' where "Woche" = ?';
protected const string SQL_WHERE = ' where "Woche" = ?';
public function __construct(PDO $database)
{
@@ -11,7 +11,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepository
{
protected const SQL_SELECT = <<<SQL
protected const string SQL_SELECT = <<<SQL
select
"Jahr" as "period",
"Gesamtarbeitszeit" as "totalHours",
@@ -19,7 +19,7 @@ class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepositor
"Überstunden" as "overtime"
from "Arbeitszeiten - Jahr"
SQL;
protected const SQL_WHERE = ' where "Jahr" = ?';
protected const string SQL_WHERE = ' where "Jahr" = ?';
public function __construct(PDO $database)
{
+1 -1
View File
@@ -3,6 +3,6 @@ modules:
enabled:
- \Helper\Api
- REST:
url: http://localhost:8091/
url: http://api:80/
depends: PhpBrowser
part: Json
@@ -4,14 +4,12 @@ namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
use Codeception\Attribute\DataProvider;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use TorstenHettstedt\TimekeepingApi\Controller\HttpConflictRequestException;
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursController;
@@ -25,10 +23,6 @@ class WorkingHoursControllerTest extends AbstractControllerTest
public const string NEW_DATE = '2020-04-01';
public const string NEW_INTERVAL = '07:59:00';
protected ContainerInterface $container;
protected Request $request;
protected Response|MockObject $response;
/**
* @throws Exception
* @throws \PHPUnit\Framework\MockObject\Exception
1