refactor(01-tech-debt): extract AllegroTokenManager and StringHelper

Phase 1 complete (2/2 plans):

- Plan 01-01: Extract AllegroTokenManager — OAuth token logic
  centralized from 4 classes into dedicated manager class

- Plan 01-02: Extract StringHelper — nullableString/normalizeDateTime/
  normalizeColorHex extracted from 15+ classes into App\Core\Support\StringHelper;
  removed 19 duplicate private methods

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 23:36:06 +01:00
parent 4c3daf69b7
commit f8db8c0162
26 changed files with 1374 additions and 547 deletions

View File

@@ -8,6 +8,7 @@ use App\Core\Http\Response;
use App\Core\I18n\Translator;
use App\Core\Security\Csrf;
use App\Core\View\Template;
use App\Core\Support\StringHelper;
use App\Modules\Auth\AuthService;
use App\Modules\Shipments\ShipmentPackageRepository;
@@ -344,7 +345,7 @@ final class OrdersController
foreach ($config as $group) {
$items = [];
$groupColor = $this->normalizeColorHex((string) ($group['color_hex'] ?? '#64748b'));
$groupColor = StringHelper::normalizeColorHex((string) ($group['color_hex'] ?? '#64748b'));
$groupItems = is_array($group['items'] ?? null) ? $group['items'] : [];
foreach ($groupItems as $status) {
$code = strtolower(trim((string) ($status['code'] ?? '')));
@@ -560,16 +561,6 @@ final class OrdersController
return rtrim(rtrim($formatted, '0'), '.');
}
private function normalizeColorHex(string $value): string
{
$trimmed = trim($value);
if (preg_match('/^#[0-9a-fA-F]{6}$/', $trimmed) === 1) {
return strtolower($trimmed);
}
return '#64748b';
}
/**
* @return array<string, string>
*/

View File

@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace App\Modules\Orders;
use App\Core\Support\StringHelper;
use PDO;
use Throwable;
@@ -370,7 +371,7 @@ final class OrdersRepository
if (!isset($groupMap[$groupId])) {
$groupMap[$groupId] = [
'name' => trim((string) ($row['group_name'] ?? '')),
'color_hex' => $this->normalizeColorHex((string) ($row['group_color_hex'] ?? '#64748b')),
'color_hex' => StringHelper::normalizeColorHex((string) ($row['group_color_hex'] ?? '#64748b')),
'items' => [],
];
}
@@ -780,13 +781,4 @@ final class OrdersRepository
return $code;
}
private function normalizeColorHex(string $value): string
{
$trimmed = trim($value);
if (preg_match('/^#[0-9a-fA-F]{6}$/', $trimmed) === 1) {
return strtolower($trimmed);
}
return '#64748b';
}
}