From 5338ee13a8e925bd1e0c35f741a7e7ae2694d51c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 1 May 2025 10:26:02 +1000 Subject: [PATCH] Static analysis cleanup --- app/Export/CSV/BaseExport.php | 1 + app/Export/CSV/InvoiceExport.php | 30 +++++++++++-------- app/Export/Decorators/InvoiceDecorator.php | 1 + app/Helpers/Bank/Nordigen/Nordigen.php | 3 ++ .../Controllers/Bank/NordigenController.php | 10 +++++-- .../Requests/Client/StoreClientRequest.php | 2 +- app/Jobs/Report/PreviewReport.php | 20 +++++++++++-- app/Jobs/Report/SendToAdmin.php | 13 ++++++-- app/Services/Pdf/PdfService.php | 2 +- 9 files changed, 61 insertions(+), 21 deletions(-) diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index 86e52a5b62..07e58ffa29 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -1506,6 +1506,7 @@ class BaseExport public function processMetaData(array $row, $resource): array { + nlog($row); $class = get_class($resource); $entity = ''; diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index df502c0c42..758da070f2 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -199,22 +199,28 @@ class InvoiceExport extends BaseExport $entity[$key] = $transformed_invoice[$parts[1]]; } elseif ($decorated_value = $this->decorator->transform($key, $invoice)) { $entity[$key] = $decorated_value; - } elseif (count($this->tax_names) > 0) { - - $calc = $invoice->calc(); - $taxes = $calc->getTaxMap()->merge($calc->getTotalTaxMap())->toArray(); - nlog($this->tax_names); - foreach ($this->tax_names as $tax_name) { - $entity[$tax_name] = 0; - } - - foreach ($taxes as $tax) { - $entity[$tax['name']] += $tax['total']; - } + } else { + $entity[$key] = ''; } } + + if (count($this->tax_names) > 0) { + + $calc = $invoice->calc(); + $taxes = $calc->getTaxMap()->merge($calc->getTotalTaxMap())->toArray(); + + foreach ($this->tax_names as $tax_name) { + $entity[$tax_name] = 0; + } + + foreach ($taxes as $tax) { + $entity[$tax['name']] += $tax['total']; + } + } + + $entity = $this->decorateAdvancedFields($invoice, $entity); return $this->convertFloats($entity); diff --git a/app/Export/Decorators/InvoiceDecorator.php b/app/Export/Decorators/InvoiceDecorator.php index 902b5d17ac..0632e3cace 100644 --- a/app/Export/Decorators/InvoiceDecorator.php +++ b/app/Export/Decorators/InvoiceDecorator.php @@ -18,6 +18,7 @@ class InvoiceDecorator extends Decorator implements DecoratorInterface { public function transform(string $key, mixed $entity): mixed { + $invoice = false; if ($entity instanceof Invoice) { diff --git a/app/Helpers/Bank/Nordigen/Nordigen.php b/app/Helpers/Bank/Nordigen/Nordigen.php index ce3e4b0d4b..50d9b3c9ab 100644 --- a/app/Helpers/Bank/Nordigen/Nordigen.php +++ b/app/Helpers/Bank/Nordigen/Nordigen.php @@ -101,8 +101,11 @@ class Nordigen return Arr::first( $this->client->endUserAgreement->getEndUserAgreements()['results'], function (array $eua) use ($institutionId, $requiredScopes, $accessDays, $txDays): bool { + $isNotExpired = !isset($eua['status']) || $eua['status'] !== 'EXPIRED'; + return $eua['institution_id'] === $institutionId && $eua['accepted'] === null + && $isNotExpired && $eua['max_historical_days'] >= $txDays && $eua['access_valid_for_days'] >= $accessDays && !array_diff($requiredScopes, $eua['access_scope'] ?? []); diff --git a/app/Http/Controllers/Bank/NordigenController.php b/app/Http/Controllers/Bank/NordigenController.php index 64af7ff207..a28ba85c97 100644 --- a/app/Http/Controllers/Bank/NordigenController.php +++ b/app/Http/Controllers/Bank/NordigenController.php @@ -80,8 +80,12 @@ class NordigenController extends BaseController try { $txDays = $data['tx_days'] ?? 0; //@phpstan-ignore-line - $agreement = $nordigen->firstValidAgreement($institution['id'], $data['access_days'] ?? 0, $txDays) - ?? $nordigen->createAgreement($institution, $data['access_days'] ?? 9999, $txDays); + + $agreement = $nordigen->createAgreement($institution, $data['access_days'] ?? 9999, $txDays); + + //this does not work in a multi tenant environment, it simply grabs the first agreement, without differentiating between companies. we may need to store the current requistion... + // $agreement = $nordigen->firstValidAgreement($institution['id'], $data['access_days'] ?? 0, $txDays) + // ?? $nordigen->createAgreement($institution, $data['access_days'] ?? 9999, $txDays); } catch (\Exception $e) { $debug = "{$e->getMessage()} ({$e->getCode()})"; @@ -95,7 +99,7 @@ class NordigenController extends BaseController $requisition = $nordigen->createRequisition( config('ninja.app_url') . '/nordigen/confirm', $institution, - $agreement, + $agreement, //@phpstan-ignore-line $request->token, $lang, ); diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index e56fb9b70d..c3ef873f21 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -117,7 +117,7 @@ class StoreClientRequest extends Request $settings = (array)ClientSettings::defaults(); /* Stub settings if they don't exist */ - if (!array_key_exists('settings', $input)) { + if (!array_key_exists('settings', $input) || is_null($input['settings'])) { $input['settings'] = []; } elseif (is_object($input['settings'])) { $input['settings'] = (array)$input['settings']; diff --git a/app/Jobs/Report/PreviewReport.php b/app/Jobs/Report/PreviewReport.php index 0ab38644ca..733dc2371a 100644 --- a/app/Jobs/Report/PreviewReport.php +++ b/app/Jobs/Report/PreviewReport.php @@ -29,6 +29,7 @@ class PreviewReport implements ShouldQueue use Queueable; use SerializesModels; + public $tries = 1; /** * Create a new job instance */ @@ -52,8 +53,23 @@ class PreviewReport implements ShouldQueue Cache::put($this->hash, $report, 60 * 60); } - public function middleware() + // public function middleware() + // { + // return [ + // (new WithoutOverlapping("report-{$this->company->company_key}-{$this->report_class}")) + // ->releaseAfter(60) + // ->expireAfter(60) // 5 minutes + // ->dontRelease(), // This prevents the job from being marked as a "release" which counts towards attempts + // ]; + // } + + /** + * Handle a job failure. + */ + public function failed(\Throwable $exception = null) { - return [new WithoutOverlapping("report-{$this->company->company_key}-{$this->report_class}")]; + if($exception) { + nlog("EXCEPTION:: PreviewReport:: could not preview report for" . $exception->getMessage()); + } } } diff --git a/app/Jobs/Report/SendToAdmin.php b/app/Jobs/Report/SendToAdmin.php index 4c9532d40c..6e2430a17f 100644 --- a/app/Jobs/Report/SendToAdmin.php +++ b/app/Jobs/Report/SendToAdmin.php @@ -45,6 +45,8 @@ class SendToAdmin implements ShouldQueue protected string $file_name; + public $tries = 1; + /** * Create a new job instance. */ @@ -90,8 +92,15 @@ class SendToAdmin implements ShouldQueue } - public function middleware() + // public function middleware() + // { + // return [(new WithoutOverlapping("report-{$this->company->company_key}-{$this->report_class}"))->expireAfter(60)]; + // } + + public function failed(\Throwable $exception = null) { - return [new WithoutOverlapping("report-{$this->company->company_key}-{$this->report_class}")]; + if($exception) { + nlog("EXCEPTION:: SendToAdmin:: could not email report for" . $exception->getMessage()); + } } } diff --git a/app/Services/Pdf/PdfService.php b/app/Services/Pdf/PdfService.php index 754b1b625f..d506aa7811 100644 --- a/app/Services/Pdf/PdfService.php +++ b/app/Services/Pdf/PdfService.php @@ -92,7 +92,7 @@ class PdfService try { $html = $this->getHtml(); - nlog($html); + // nlog($html); $pdf = $this->resolvePdfEngine($html); $numbered_pdf = $this->pageNumbering($pdf, $this->company);