From 0427f6c3179a86ea30438106c0c3423016f723f8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 6 Jun 2024 12:31:24 +1000 Subject: [PATCH] Fixes for static analysis --- app/DataMapper/Analytics/DbQuery.php | 4 ++- .../Transformer/Csv/QuoteTransformer.php | 2 +- app/Jobs/Cron/SubscriptionCron.php | 1 + app/Jobs/Mail/NinjaMailerJob.php | 20 ++++++----- app/Jobs/Mail/NinjaMailerObject.php | 2 +- app/Livewire/BillingPortal/RFF.php | 2 ++ app/Livewire/RequiredClientInfo.php | 2 +- app/Models/Client.php | 5 +++ app/Models/Company.php | 3 ++ app/PaymentDrivers/BTCPayPaymentDriver.php | 3 +- .../PayPal/PayPalBasePaymentDriver.php | 21 ++++++++++++ .../PayPalPPCPPaymentDriver.php | 33 ++++++++----------- .../PayPalRestPaymentDriver.php | 25 ++------------ app/PaymentDrivers/WePayPaymentDriver.php | 4 +-- .../EDocument/Standards/OrderXDocument.php | 6 ++-- .../EDocument/Standards/ZugferdEDokument.php | 5 +++ app/Services/Email/Email.php | 17 ++++++---- 17 files changed, 89 insertions(+), 66 deletions(-) diff --git a/app/DataMapper/Analytics/DbQuery.php b/app/DataMapper/Analytics/DbQuery.php index ac65c29b36c0..833aa9707e85 100644 --- a/app/DataMapper/Analytics/DbQuery.php +++ b/app/DataMapper/Analytics/DbQuery.php @@ -66,12 +66,14 @@ class DbQuery extends GenericMixedMetric public $double_metric2 = 1; - public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7) + public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7, $string_metric8, $string_metric9) { $this->int_metric1 = $int_metric1; $this->string_metric5 = $string_metric5; $this->string_metric6 = $string_metric6; $this->double_metric2 = $double_metric2; $this->string_metric7 = $string_metric7; + $this->string_metric8 = $string_metric8; + $this->string_metric9 = $string_metric9; } } diff --git a/app/Import/Transformer/Csv/QuoteTransformer.php b/app/Import/Transformer/Csv/QuoteTransformer.php index 1ee131f390cd..00c2cb54d952 100644 --- a/app/Import/Transformer/Csv/QuoteTransformer.php +++ b/app/Import/Transformer/Csv/QuoteTransformer.php @@ -94,7 +94,7 @@ class QuoteTransformer extends BaseTransformer ), 'footer' => $this->getString($quote_data, 'quote.footer'), 'partial' => $this->getFloat($quote_data, 'quote.partial'), - 'partial_due_date' => isset($invoice_data['quote.partial_due_date']) ? $this->parseDate($quote_data['quote.partial_due_date']) : null, + 'partial_due_date' => isset($quote_data['quote.partial_due_date']) ? $this->parseDate($quote_data['quote.partial_due_date']) : null, 'custom_surcharge1' => $this->getString( $quote_data, 'quote.custom_surcharge1' diff --git a/app/Jobs/Cron/SubscriptionCron.php b/app/Jobs/Cron/SubscriptionCron.php index 82b54d48ee8e..e9d0d32b4838 100644 --- a/app/Jobs/Cron/SubscriptionCron.php +++ b/app/Jobs/Cron/SubscriptionCron.php @@ -79,6 +79,7 @@ class SubscriptionCron ->cursor() ->each(function ($company_id){ + /** @var \App\Models\Company $company */ $company = Company::find($company_id); $timezone_now = now()->setTimezone($company->timezone()->name ?? 'Pacific/Midway'); diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 595e6fb8ace1..def9c4fc733d 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -168,11 +168,6 @@ class NinjaMailerJob implements ShouldQueue $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; } - catch(\Symfony\Component\Mailer\Transport\Dsn $e){ - nlog("Incorrectly configured mail server - setting to default mail driver."); - $this->nmo->settings->email_sending_method = 'default'; - return $this->setMailDriver(); - } catch(\Google\Service\Exception $e){ if ($e->getCode() == '429') { @@ -194,7 +189,7 @@ class NinjaMailerJob implements ShouldQueue * this merges a text string with a json object * need to harvest the ->Message property using the following */ - if (stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) { + if (stripos($e->getMessage(), 'code 300') !== false || stripos($e->getMessage(), 'code 413') !== false) { $message = "Either Attachment too large, or recipient has been suppressed."; $this->fail(); @@ -209,7 +204,15 @@ class NinjaMailerJob implements ShouldQueue return; } - if (stripos($e->getMessage(), 'code 406')) { + if(stripos($e->getMessage(), 'Dsn') !== false){ + + nlog("Incorrectly configured mail server - setting to default mail driver."); + $this->nmo->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + + } + + if (stripos($e->getMessage(), 'code 406') !== false) { $email = $this->nmo->to_user->email ?? ''; @@ -790,6 +793,7 @@ class NinjaMailerJob implements ShouldQueue private function refreshOfficeToken(User $user) { $expiry = $user->oauth_user_token_expiry ?: now()->subDay(); + $token = false; if ($expiry->lt(now())) { $guzzle = new \GuzzleHttp\Client(); @@ -798,7 +802,7 @@ class NinjaMailerJob implements ShouldQueue if (!$user->oauth_user_refresh_token || $user->oauth_user_refresh_token == '') { return false; } - + try { $token = json_decode($guzzle->post($url, [ 'form_params' => [ diff --git a/app/Jobs/Mail/NinjaMailerObject.php b/app/Jobs/Mail/NinjaMailerObject.php index d330a89e7bea..f00cbbbdf517 100644 --- a/app/Jobs/Mail/NinjaMailerObject.php +++ b/app/Jobs/Mail/NinjaMailerObject.php @@ -38,7 +38,7 @@ class NinjaMailerObject public $template = false; - /* @var bool | App\Models\Invoice | App\Models\Quote | App\Models\Credit | App\Models\RecurringInvoice | App\Models\PurchaseOrder | App\Models\Payment $entity */ + /* @var \bool | App\Models\Invoice | App\Models\Quote | App\Models\Credit | App\Models\RecurringInvoice | App\Models\PurchaseOrder | App\Models\Payment $entity */ public $entity = false; public $reminder_template = ''; diff --git a/app/Livewire/BillingPortal/RFF.php b/app/Livewire/BillingPortal/RFF.php index 38b36f868108..30ce571869a0 100644 --- a/app/Livewire/BillingPortal/RFF.php +++ b/app/Livewire/BillingPortal/RFF.php @@ -45,6 +45,7 @@ class RFF extends Component $contact = auth()->guard('contact'); + /** @var \App\Models\ClientContact $contact */ $contact->user()->update([ 'first_name' => $data['contact_first_name'], 'last_name' => $data['contact_last_name'], @@ -65,6 +66,7 @@ class RFF extends Component public function render() { + /** @var \App\Models\CompanyGateway $gateway */ $gateway = CompanyGateway::find($this->context['form']['company_gateway_id']); $countries = Cache::get('countries'); diff --git a/app/Livewire/RequiredClientInfo.php b/app/Livewire/RequiredClientInfo.php index 361338b33a90..3ff7d5374bba 100644 --- a/app/Livewire/RequiredClientInfo.php +++ b/app/Livewire/RequiredClientInfo.php @@ -402,7 +402,7 @@ class RequiredClientInfo extends Component if ($this->unfilled_fields === 0 && (!$this->company_gateway->always_show_required_fields || $this->is_subscription)) { $this->dispatch( 'passed-required-fields-check', - client_postal_code: $this->contact->client->postal_code + client_postal_code: $_contact->client->postal_code ); } diff --git a/app/Models/Client.php b/app/Models/Client.php index aa054d06f3df..b48973655050 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -386,6 +386,7 @@ class Client extends BaseModel implements HasLocalePreference // } return $languages->first(function ($item) { + /** @var \stdClass $item */ return $item->id == $this->getSetting('language_id'); }); } @@ -419,6 +420,8 @@ class Client extends BaseModel implements HasLocalePreference // } return $date_formats->first(function ($item) { + + /** @var \stdClass $item */ return $item->id == $this->getSetting('date_format_id'); })->format; } @@ -433,6 +436,8 @@ class Client extends BaseModel implements HasLocalePreference // } return $currencies->first(function ($item) { + + /** @var \stdClass $item */ return $item->id == $this->getSetting('currency_id'); }); } diff --git a/app/Models/Company.php b/app/Models/Company.php index 8a276ac3ac76..815b21aa8ffc 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -647,6 +647,8 @@ class Company extends BaseModel // } return $countries->first(function ($item) { + + /** @var \stdClass $item */ return $item->id == $this->getSetting('country_id'); }); @@ -670,6 +672,7 @@ class Company extends BaseModel // } return $timezones->first(function ($item) { + /** @var \stdClass $item */ return $item->id == $this->settings->timezone_id; }); diff --git a/app/PaymentDrivers/BTCPayPaymentDriver.php b/app/PaymentDrivers/BTCPayPaymentDriver.php index 368f5b7beb0b..e7560cec2784 100644 --- a/app/PaymentDrivers/BTCPayPaymentDriver.php +++ b/app/PaymentDrivers/BTCPayPaymentDriver.php @@ -87,7 +87,8 @@ class BTCPayPaymentDriver extends BaseDriver public function processWebhookRequest() { $webhook_payload = file_get_contents('php://input'); - + $sig = false; + /** @var \stdClass $btcpayRep */ $btcpayRep = json_decode($webhook_payload); if ($btcpayRep == null) { throw new PaymentFailed('Empty data'); diff --git a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php index 7bcad8d32d14..dc5f845a0c76 100644 --- a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php +++ b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php @@ -176,6 +176,27 @@ class PayPalBasePaymentDriver extends BaseDriver } + public function handleDuplicateInvoiceId(string $orderID) + { + + $_invoice = collect($this->payment_hash->data->invoices)->first(); + $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); + $new_invoice_number = $invoice->number."_".Str::random(5); + + $update_data = + [[ + "op" => "replace", + "path" => "/purchase_units/@reference_id=='default'/invoice_id", + "value" => $new_invoice_number, + ]]; + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $update_data); + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + + return $r; + } + public function getShippingAddress(): ?array { return $this->company_gateway->require_shipping_address ? diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 6918f951c221..ab9cc5932027 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -114,15 +114,19 @@ class PayPalPPCPPaymentDriver extends PayPalBasePaymentDriver public function processPaymentResponse($request) { + nlog("response"); + $request['gateway_response'] = str_replace("Error: ", "", $request['gateway_response']); $response = json_decode($request['gateway_response'], true); + nlog($response); + if($request->has('token') && strlen($request->input('token')) > 2) { return $this->processTokenPayment($request, $response); } //capture - $orderID = $response['orderID']; + $orderID = $response['orderID'] ?? $this->payment_hash->data->orderID; if($this->company_gateway->require_shipping_address) { @@ -149,36 +153,26 @@ class PayPalPPCPPaymentDriver extends PayPalBasePaymentDriver if($r->status() == 422) { //handle conditions where the client may need to try again. - return $this->handleRetry($r, $request); + // return $this->handleRetry($r, $request); + + $r = $this->handleDuplicateInvoiceId($orderID); + } } catch(\Exception $e) { //Rescue for duplicate invoice_id if(stripos($e->getMessage(), 'DUPLICATE_INVOICE_ID') !== false) { - - - $_invoice = collect($this->payment_hash->data->invoices)->first(); - $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); - $new_invoice_number = $invoice->number."_".Str::random(5); - - $update_data = - [[ - "op" => "replace", - "path" => "/purchase_units/@reference_id=='default'/invoice_id", - "value" => $new_invoice_number, - ]]; - - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $update_data); - - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); - + $r = $this->handleDuplicateInvoiceId($orderID); } } $response = $r; + nlog("Process response =>"); + nlog($response->json()); + if(isset($response['status']) && $response['status'] == 'COMPLETED' && isset($response['purchase_units'])) { $data = [ @@ -222,7 +216,6 @@ class PayPalPPCPPaymentDriver extends PayPalBasePaymentDriver return response()->json(['message' => $message], 400); - // throw new PaymentFailed($message, 400); } } diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index 9fb6c139c8c3..f9e6725aae3d 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -148,31 +148,11 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver return response()->json(['message' => $message], 400); - //throw new PaymentFailed($message, 400); } } - private function handleDuplicateInvoiceId(string $orderID) - { - - $_invoice = collect($this->payment_hash->data->invoices)->first(); - $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); - $new_invoice_number = $invoice->number."_".Str::random(5); - - $update_data = - [[ - "op" => "replace", - "path" => "/purchase_units/@reference_id=='default'/invoice_id", - "value" => $new_invoice_number, - ]]; - - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $update_data); - - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); - - return $r; - } + private function createNinjaPayment($request, $response) { @@ -297,7 +277,7 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver } - + /** * processTokenPayment * @@ -314,6 +294,7 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver */ public function processTokenPayment($request, array $response) { + /** @car \App\Models\ClientGatwayToken $cgt */ $cgt = ClientGatewayToken::where('client_id', $this->client->id) ->where('token', $request['token']) ->firstOrFail(); diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 2cd93f7905de..4d1cb96e1766 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -161,9 +161,9 @@ class WePayPaymentDriver extends BaseDriver } - public function detach(ClientGatewayToken $token) + public function detach(ClientGatewayToken $token): bool { - + return true; } public function getClientRequiredFields(): array diff --git a/app/Services/EDocument/Standards/OrderXDocument.php b/app/Services/EDocument/Standards/OrderXDocument.php index 71349db49595..ec63eb4029fc 100644 --- a/app/Services/EDocument/Standards/OrderXDocument.php +++ b/app/Services/EDocument/Standards/OrderXDocument.php @@ -26,14 +26,16 @@ class OrderXDocument extends AbstractService { public OrderDocumentBuilder $orderxdocument; - public function __construct(public object $document, private readonly bool $returnObject = false, private array $tax_map = []) + /** @var \App\Models\Invoice | \App\Models\Quote | \App\Models\PurchaseOrder | \App\Models\Credit $document */ + public function __construct(public mixed $document, private readonly bool $returnObject = false, private array $tax_map = []) { } public function run(): self { - + $company = $this->document->company; + /** @var \App\Models\Client | \App\Models\Vendor $settings_entity */ $settings_entity = ($this->document instanceof PurchaseOrder) ? $this->document->vendor : $this->document->client; $profile = $settings_entity->getSetting('e_quote_type') ? $settings_entity->getSetting('e_quote_type') : "OrderX_Extended"; diff --git a/app/Services/EDocument/Standards/ZugferdEDokument.php b/app/Services/EDocument/Standards/ZugferdEDokument.php index 9638563cf77c..0b9f776ec435 100644 --- a/app/Services/EDocument/Standards/ZugferdEDokument.php +++ b/app/Services/EDocument/Standards/ZugferdEDokument.php @@ -32,8 +32,13 @@ class ZugferdEDokument extends AbstractService public function run(): self { + /** @var \App\Models\Company $company */ $company = $this->document->company; + + + /** @var \App\Models\Client $client */ $client = $this->document->client; + $profile = $client->getSetting('e_invoice_type'); $profile = match ($profile) { diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index f1bd7ee01d11..ef8c2b2fe9aa 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -303,11 +303,6 @@ class Email implements ShouldQueue $this->logMailError($e->getMessage(), $this->company->clients()->first()); return; } - catch(\Symfony\Component\Mailer\Transport\Dsn $e){ - nlog("Incorrectly configured mail server - setting to default mail driver."); - $this->email_object->settings->email_sending_method = 'default'; - return $this->setMailDriver(); - } catch(\Google\Service\Exception $e){ if ($e->getCode() == '429') { @@ -326,7 +321,7 @@ class Email implements ShouldQueue $message = $e->getMessage(); - if (stripos($e->getMessage(), 'code 300') || stripos($e->getMessage(), 'code 413')) { + if (stripos($e->getMessage(), 'code 300') !== false || stripos($e->getMessage(), 'code 413') !== false) { $message = "Either Attachment too large, or recipient has been suppressed."; $this->fail(); @@ -337,8 +332,16 @@ class Email implements ShouldQueue return; } + + if(stripos($e->getMessage(), 'Dsn') !== false) { - if (stripos($e->getMessage(), 'code 406')) { + nlog("Incorrectly configured mail server - setting to default mail driver."); + $this->email_object->settings->email_sending_method = 'default'; + return $this->setMailDriver(); + + } + + if (stripos($e->getMessage(), 'code 406') !== false) { $address_object = reset($this->email_object->to);