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