feat(06-sonarqube-quality): introduce typed exception hierarchy (S112 fix)

Replace 86+ generic RuntimeException throws with domain-specific exception
classes: AllegroApiException, AllegroOAuthException, ApaczkaApiException,
ShipmentException, IntegrationConfigException — all extending OrderProException
extends RuntimeException. Existing catch(RuntimeException) blocks unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 11:04:52 +01:00
parent 3a9cfcd4a2
commit 3c27c4e54a
21 changed files with 141 additions and 87 deletions

View File

@@ -8,6 +8,8 @@ use App\Modules\Settings\AllegroApiClient;
use App\Modules\Settings\AllegroTokenManager;
use App\Modules\Settings\CompanySettingsRepository;
use RuntimeException;
use AppCoreExceptionsIntegrationConfigException;
use AppCoreExceptionsShipmentException;
use Throwable;
final class AllegroShipmentService implements ShipmentProviderInterface
@@ -44,7 +46,7 @@ final class AllegroShipmentService implements ShipmentProviderInterface
{
$order = $this->ordersRepository->findDetails($orderId);
if ($order === null) {
throw new RuntimeException('Zamowienie nie znalezione.');
throw new ShipmentException('Zamowienie nie znalezione.');
}
$company = $this->companySettings->getSettings();
@@ -53,7 +55,7 @@ final class AllegroShipmentService implements ShipmentProviderInterface
$deliveryMethodId = trim((string) ($formData['delivery_method_id'] ?? ''));
if ($deliveryMethodId === '') {
throw new RuntimeException('Nie podano metody dostawy.');
throw new ShipmentException('Nie podano metody dostawy.');
}
$receiverAddress = $this->buildReceiverAddress($order, $formData);
@@ -177,12 +179,12 @@ final class AllegroShipmentService implements ShipmentProviderInterface
{
$package = $this->packages->findById($packageId);
if ($package === null) {
throw new RuntimeException('Paczka nie znaleziona.');
throw new ShipmentException('Paczka nie znaleziona.');
}
$commandId = trim((string) ($package['command_id'] ?? ''));
if ($commandId === '') {
throw new RuntimeException('Brak command_id dla tej paczki.');
throw new ShipmentException('Brak command_id dla tej paczki.');
}
[$accessToken, $env] = $this->tokenManager->resolveToken();
@@ -238,12 +240,12 @@ final class AllegroShipmentService implements ShipmentProviderInterface
{
$package = $this->packages->findById($packageId);
if ($package === null) {
throw new RuntimeException('Paczka nie znaleziona.');
throw new ShipmentException('Paczka nie znaleziona.');
}
$shipmentId = trim((string) ($package['shipment_id'] ?? ''));
if ($shipmentId === '') {
throw new RuntimeException('Przesylka nie zostala jeszcze utworzona.');
throw new ShipmentException('Przesylka nie zostala jeszcze utworzona.');
}
[$accessToken, $env] = $this->tokenManager->resolveToken();
@@ -346,14 +348,14 @@ final class AllegroShipmentService implements ShipmentProviderInterface
$required = ['street', 'city', 'postalCode', 'phone', 'email'];
foreach ($required as $field) {
if (trim((string) ($sender[$field] ?? '')) === '') {
throw new RuntimeException('Uzupelnij dane nadawcy w Ustawienia > Dane firmy (brak: ' . $field . ').');
throw new IntegrationConfigException('Uzupelnij dane nadawcy w Ustawienia > Dane firmy (brak: ' . $field . ').');
}
}
$name = trim((string) ($sender['name'] ?? ''));
$company = trim((string) ($sender['company'] ?? ''));
if ($name === '' && $company === '') {
throw new RuntimeException('Uzupelnij dane nadawcy w Ustawienia > Dane firmy (brak nazwy/firmy).');
throw new IntegrationConfigException('Uzupelnij dane nadawcy w Ustawienia > Dane firmy (brak nazwy/firmy).');
}
}