Skip to content

Commit

Permalink
clean(ZMS-3414): add todos for zmscitizenapis and require code format…
Browse files Browse the repository at this point in the history
…ting complexity passing
  • Loading branch information
Thomas Fink authored and Thomas Fink committed Feb 10, 2025
1 parent 28d4e1e commit 5ee6584
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/combined-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
if: |
always() &&
(needs.call-code-quality.result == 'success' || needs.call-code-quality.result == 'skipped') &&
needs.call-code-quality.result == 'success' &&
needs.call-unit-tests.result == 'success'
steps:
- run: echo "All required checks passed"
68 changes: 36 additions & 32 deletions zmscitizenapi/src/Zmscitizenapi/Services/Core/ExceptionService.php

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions zmscitizenapi/src/Zmscitizenapi/Services/Core/MapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static function mapScopeForProvider(int $providerId, ?ThinnedScopeList $s
return $matchingScope;
}

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @TODO: Extract mapping logic into specialized mapper classes for each entity type
*/
public static function mapOfficesWithScope(ProviderList $providerList): OfficeList
{
$offices = [];
Expand Down Expand Up @@ -91,10 +96,10 @@ public static function mapServicesWithCombinations(RequestList $requestList, Req
usort($requestArray, function ($a, $b) {

return $a->getId() <=> $b->getId();
// Sorting by service ID (ascending order)
// Sorting by service ID (ascending order)
});
foreach ($requestArray as $service) {
/** @var array<string, array<int>> $serviceCombinations */
/** @var array<string, array<int>> $serviceCombinations */
$serviceCombinations = [];
$combinableData = $service->getAdditionalData()['combinable'] ?? [];
foreach ($combinableData as $combinationServiceId) {
Expand Down Expand Up @@ -140,6 +145,11 @@ public static function scopeToThinnedScope(Scope $scope): ThinnedScope
return new ThinnedScope(id: (int) ($scope->id ?? 0), provider: $thinnedProvider, shortName: $scope->shortName ?? null, telephoneActivated: isset($scope->data['telephoneActivated']) ? (bool) $scope->data['telephoneActivated'] : null, telephoneRequired: isset($scope->data['telephoneRequired']) ? (bool) $scope->data['telephoneRequired'] : null, customTextfieldActivated: isset($scope->data['customTextfieldActivated']) ? (bool) $scope->data['customTextfieldActivated'] : null, customTextfieldRequired: isset($scope->data['customTextfieldRequired']) ? (bool) $scope->data['customTextfieldRequired'] : null, customTextfieldLabel: $scope->data['customTextfieldLabel'] ?? null, captchaActivatedRequired: isset($scope->data['captchaActivatedRequired']) ? (bool) $scope->data['captchaActivatedRequired'] : null, displayInfo: $scope->data['displayInfo'] ?? null);
}

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @TODO: Break down process mapping into smaller, focused methods
*/
public static function processToThinnedProcess(Process $myProcess): ThinnedProcess
{
if (!$myProcess || !isset($myProcess->id)) {
Expand Down Expand Up @@ -183,7 +193,7 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
$processEntity->id = $thinnedProcess->processId;
$processEntity->authKey = $thinnedProcess->authKey ?? null;
$processEntity->customTextfield = $thinnedProcess->customTextfield ?? null;
// Moved to Process level
// Moved to Process level

$client = new Client();
$client->familyName = $thinnedProcess->familyName ?? null;
Expand Down Expand Up @@ -258,6 +268,6 @@ public static function contactToThinnedContact($contact): ThinnedContact
*/
public static function providerToThinnedProvider(Provider $provider): ThinnedProvider
{
return new ThinnedProvider(id: isset($provider->id) ? (int) $provider->id : null, name: isset($provider->name) ? $provider->name : null, source: isset($provider->source) ? $provider->source : null, lon: isset($provider->data['geo']['lon']) ? (float)$provider->data['geo']['lon'] : null, lat: isset($provider->data['geo']['lat']) ? (float)$provider->data['geo']['lat'] : null, contact: isset($provider->contact) ? self::contactToThinnedContact($provider->contact) : null,);
return new ThinnedProvider(id: isset($provider->id) ? (int) $provider->id : null, name: isset($provider->name) ? $provider->name : null, source: isset($provider->source) ? $provider->source : null, lon: isset($provider->data['geo']['lon']) ? (float) $provider->data['geo']['lon'] : null, lat: isset($provider->data['geo']['lat']) ? (float) $provider->data['geo']['lat'] : null, contact: isset($provider->contact) ? self::contactToThinnedContact($provider->contact) : null, );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
use DateTime;
use Psr\Http\Message\ServerRequestInterface;

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @TODO: Split this service into domain-specific validation services
*/
class ValidationService
{
private static ?string $currentLanguage = null;
Expand All @@ -21,7 +25,7 @@ class ValidationService
private const PHONE_PATTERN = '/^\+?[1-9]\d{6,14}$/';
private const SERVICE_COUNT_PATTERN = '/^\d+$/';
private const MAX_FUTURE_DAYS = 365;
// Maximum days in the future for appointments
// Maximum days in the future for appointments

public static function setLanguageContext(?string $language): void
{
Expand Down Expand Up @@ -85,6 +89,10 @@ public static function validateServiceLocationCombination(int $officeId, array $
: ['errors' => [self::getError('invalidLocationAndServiceCombination')]];
}

/**
* @SuppressWarnings(PHPMD.NPathComplexity)
* @TODO: Extract validation rules into separate rule objects using the specification pattern
*/
public static function validateGetBookableFreeDays(?array $officeIds, ?array $serviceIds, ?string $startDate, ?string $endDate, ?array $serviceCounts): array
{
$errors = [];
Expand Down Expand Up @@ -364,7 +372,7 @@ private static function isValidServiceCounts(?array $serviceCounts): bool
}

foreach ($serviceCounts as $count) {
if (!is_numeric($count) || $count < 0 || !preg_match(self::SERVICE_COUNT_PATTERN, (string)$count)) {
if (!is_numeric($count) || $count < 0 || !preg_match(self::SERVICE_COUNT_PATTERN, (string) $count)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
use BO\Zmsentities\Collection\RequestList;
use BO\Zmsentities\Collection\ProcessList;

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @TODO: Break down this facade into smaller domain-specific facades or use the Command pattern
*/
class ZmsApiFacadeService
{
private static ?string $currentLanguage = null;
Expand Down Expand Up @@ -348,7 +352,7 @@ public static function getBookableFreeDays(array $officeIds, array $serviceIds,
];
}

$freeDays = ZmsApiClientService::getFreeDays(new ProviderList($providers), new RequestList($services), $firstDay, $lastDay,) ?? new Calendar();
$freeDays = ZmsApiClientService::getFreeDays(new ProviderList($providers), new RequestList($services), $firstDay, $lastDay, ) ?? new Calendar();
$daysCollection = $freeDays->days;
$formattedDays = [];
foreach ($daysCollection as $day) {
Expand Down Expand Up @@ -432,12 +436,12 @@ private static function processFreeSlots(ProcessList $freeSlots): array
if (isset($appointment->date)) {
$timestamp = (int) $appointment->date;
if ($timestamp > $currentTimestamp) {
$timestamps[$providerId][$timestamp] = true;
$timestamps[$providerId][$timestamp] = true;
}
}
}
}
return $timestamps;
return $timestamps;
}, []);
foreach ($appointmentTimestamps as $providerId => &$timestamps) {
$timestamps = array_keys($timestamps);
Expand Down
13 changes: 9 additions & 4 deletions zmsticketprinter/src/Zmsticketprinter/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

namespace BO\Zmsticketprinter;

/**
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @TODO: Refactor this class into smaller focused classes (LoggerInitializer, MiddlewareInitializer) to reduce complexity
*/
class Application extends \BO\Slim\Application
{
/**
Expand All @@ -26,13 +31,13 @@ class Application extends \BO\Slim\Application
public static $supportedLanguages = array(
// Default language
'de' => array(
'name' => 'Deutsch',
'locale' => 'de_DE.utf-8',
'name' => 'Deutsch',
'locale' => 'de_DE.utf-8',
'default' => true,
),
'en' => array(
'name' => 'English',
'locale' => 'en_GB.utf-8',
'name' => 'English',
'locale' => 'en_GB.utf-8',
'default' => false,
)
);
Expand Down

0 comments on commit 5ee6584

Please sign in to comment.