Fixes for static analysis

This commit is contained in:
David Bomba 2024-06-06 12:31:24 +10:00
parent 84e7cfcdaf
commit 0427f6c317
17 changed files with 89 additions and 66 deletions

View File

@ -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;
}
}

View File

@ -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'

View File

@ -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');

View File

@ -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' => [

View File

@ -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 = '';

View File

@ -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');

View File

@ -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
);
}

View File

@ -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');
});
}

View File

@ -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;
});

View File

@ -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');

View File

@ -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 ?

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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

View File

@ -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";

View File

@ -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) {

View File

@ -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);