Files
InvoiceShelf/app/Services/Document/CurrencyService.php
Darko Gjorgjijoski 947d00a9f1 refactor(services): Documents→Document + ExchangeRate→Integrations/ExchangeRate
Two follow-ups to the Services reorg that landed in 6d1816bd.

**Documents → Document** (singular). Documents/ was the only plural subdir in app/Services/ — every other bucket (Company, Mail, Module, Pdf, Storage, Update, ExchangeRate) was singular. Renaming to Document/ normalizes the whole tree.

**ExchangeRate → Integrations/ExchangeRate**. Introduces Integrations/ as an umbrella for external-service adapter subsystems. Exchange rate providers move in first; AI providers, payment gateways, and any other driver-pattern integrations land as sibling subdirs (Integrations/Ai/, Integrations/Payment/) without another reorg. Integrations/ was chosen over Providers/ to avoid conceptual collision with Laravel's app/Providers/ — 'check the providers' shouldn't be ambiguous.

17 files moved, 21 consumer files rewritten to point at the new namespaces via literal-string replacement (same approach as the previous reorg). 350 tests pass, Pint clean.
2026-04-11 11:30:00 +02:00

30 lines
823 B
PHP

<?php
namespace App\Services\Document;
use App\Models\Currency;
use Illuminate\Database\Eloquent\Collection;
class CurrencyService
{
/**
* Retrieve all currencies with commonly-used currencies sorted first.
*
* @return Collection<int, Currency>
*/
public function getAllWithCommonFirst(): Collection
{
$currencies = Currency::query()->get();
$commonCodes = Currency::COMMON_CURRENCY_CODES;
$common = $currencies->filter(fn (Currency $c): bool => in_array($c->code, $commonCodes, true))
->sortBy(fn (Currency $c): int => array_search($c->code, $commonCodes));
$rest = $currencies->reject(fn (Currency $c): bool => in_array($c->code, $commonCodes, true))
->sortBy('name');
return $common->concat($rest)->values();
}
}