From 5ca41f5f8641127f8729a8c6ccd05e7058b1db6a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 11 Aug 2023 08:10:21 +1000 Subject: [PATCH] Fixes for static analysis --- app/Http/Middleware/VendorContactKeyLogin.php | 5 --- .../Requests/Yodlee/YodleeAuthRequest.php | 2 +- app/Transformers/VendorContactTransformer.php | 2 +- app/Utils/TemplateEngine.php | 34 +++++++++++++------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/Http/Middleware/VendorContactKeyLogin.php b/app/Http/Middleware/VendorContactKeyLogin.php index 5b569bbded08..e73a32554662 100644 --- a/app/Http/Middleware/VendorContactKeyLogin.php +++ b/app/Http/Middleware/VendorContactKeyLogin.php @@ -13,14 +13,12 @@ namespace App\Http\Middleware; use Auth; use Closure; -use App\Utils\Ninja; use App\Models\Vendor; use App\Libraries\MultiDB; use Illuminate\Support\Str; use Illuminate\Http\Request; use App\Models\VendorContact; use Illuminate\Support\Facades\Cache; -use App\Events\Vednor\VendorContactLoggedIn; class VendorContactKeyLogin { @@ -59,8 +57,6 @@ class VendorContactKeyLogin auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); - event(new VendorContactLoggedIn($vendor_contact, $vendor_contact->company, Ninja::eventVars())); - if ($request->query('redirect') && ! empty($request->query('redirect'))) { return redirect()->to($request->query('redirect')); } @@ -76,7 +72,6 @@ class VendorContactKeyLogin $vendor_contact->save(); auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); - event(new VendorContactLoggedIn($vendor_contact, $vendor_contact->company, Ninja::eventVars())); if ($request->query('next')) { return redirect()->to($request->query('next')); } diff --git a/app/Http/Requests/Yodlee/YodleeAuthRequest.php b/app/Http/Requests/Yodlee/YodleeAuthRequest.php index 942139a2e25e..34b214da9f48 100644 --- a/app/Http/Requests/Yodlee/YodleeAuthRequest.php +++ b/app/Http/Requests/Yodlee/YodleeAuthRequest.php @@ -39,7 +39,7 @@ class YodleeAuthRequest extends Request return []; } - /** @var $token */ + /** @var Request $token */ public function getTokenContent() { if ($this->state) { diff --git a/app/Transformers/VendorContactTransformer.php b/app/Transformers/VendorContactTransformer.php index 39f4d60d0e6e..ca344634ce5b 100644 --- a/app/Transformers/VendorContactTransformer.php +++ b/app/Transformers/VendorContactTransformer.php @@ -44,7 +44,7 @@ class VendorContactTransformer extends EntityTransformer 'custom_value3' => $vendor->custom_value3 ?: '', 'custom_value4' => $vendor->custom_value4 ?: '', 'link' => $vendor->getLoginLink(), - 'last_login' => 'timestamp', + 'last_login' => (int)$vendor->last_login, ]; } } diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 3cd5221d5de3..2e531daf9484 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -52,8 +52,8 @@ class TemplateEngine public $template; - /** @var Invoice | Quote | Credit | PurchaseOrder | RecurringInvoice | null $entity_obj **/ - private $entity_obj; + /** @var \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder | \App\Models\RecurringInvoice $entity_obj **/ + private \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder | \App\Models\RecurringInvoice $entity_obj; /** @var \App\Models\Company | \App\Models\Client | null $settings_entity **/ private $settings_entity; @@ -81,7 +81,7 @@ class TemplateEngine $this->template = $template; - $this->entity_obj = null; + // $this->entity_obj = null; $this->settings_entity = null; } @@ -99,7 +99,7 @@ class TemplateEngine { if (strlen($this->entity) > 1 && strlen($this->entity_id) > 1) { $class = 'App\Models\\' . ucfirst(Str::camel($this->entity)); - $this->entity_obj = $class::withTrashed()->where('id', $this->decodePrimaryKey($this->entity_id))->company()->first(); + $this->entity_obj = $class::query()->withTrashed()->where('id', $this->decodePrimaryKey($this->entity_id))->company()->first(); } elseif (stripos($this->template, 'quote') !== false && $quote = Quote::query()->whereHas('invitations')->withTrashed()->company()->first()) { $this->entity = 'quote'; $this->entity_obj = $quote; @@ -111,6 +111,7 @@ class TemplateEngine $this->entity_obj = $payment; } elseif ($invoice = Invoice::query()->whereHas('invitations')->withTrashed()->company()->first()) { + /** @var \App\Models\Invoice $invoice */ $this->entity_obj = $invoice; } else { $this->mockEntity(); @@ -286,6 +287,8 @@ class TemplateEngine private function mockEntity() { + $invitation = false; + if (!$this->entity && $this->template && str_contains($this->template, 'purchase_order')) { $this->entity = 'purchaseOrder'; } elseif (str_contains($this->template, 'payment')) { @@ -304,7 +307,6 @@ class TemplateEngine 'company_id' => $user->company()->id, ]); - /** @var \App\Models\ClientContact $contact */ $contact = ClientContact::factory()->create([ 'user_id' => $user->id, @@ -315,7 +317,8 @@ class TemplateEngine ]); if ($this->entity == 'payment') { - $this->entity_obj = Payment::factory()->create([ + /** @var \App\Models\Payment $payment */ + $payment = Payment::factory()->create([ 'user_id' => $user->id, 'company_id' => $user->company()->id, 'client_id' => $client->id, @@ -324,6 +327,8 @@ class TemplateEngine 'refunded' => 5, ]); + $this->entity_obj = $payment; + /** @var \App\Models\Invoice $invoice */ $invoice = Invoice::factory()->create([ 'user_id' => $user->id, @@ -349,7 +354,8 @@ class TemplateEngine } if (!$this->entity || $this->entity == 'invoice') { - $this->entity_obj = Invoice::factory()->create([ + /** @var \App\Models\Invoice $invoice */ + $invoice = Invoice::factory()->create([ 'user_id' => $user->id, 'company_id' => $user->company()->id, 'client_id' => $client->id, @@ -357,6 +363,8 @@ class TemplateEngine 'balance' => '10', ]); + $this->entity_obj = $invoice; + $invitation = InvoiceInvitation::factory()->create([ 'user_id' => $user->id, 'company_id' => $user->company()->id, @@ -366,11 +374,14 @@ class TemplateEngine } if ($this->entity == 'quote') { - $this->entity_obj = Quote::factory()->create([ + /** @var \App\Models\Quote $quote */ + $quote = Quote::factory()->create([ 'user_id' => $user->id, 'company_id' => $user->company()->id, 'client_id' => $client->id, ]); + + $this->entity_obj = $quote; $invitation = QuoteInvitation::factory()->create([ 'user_id' => $user->id, @@ -395,12 +406,15 @@ class TemplateEngine 'is_primary' => 1, 'send_email' => true, ]); - - $this->entity_obj = PurchaseOrder::factory()->create([ + + /** @var \App\Models\PurchaseOrder $purchase_order **/ + $purchase_order = PurchaseOrder::factory()->create([ 'user_id' => $user->id, 'company_id' => $user->company()->id, 'vendor_id' => $vendor->id, ]); + + $this->entity_obj = $purchase_order; /** @var \App\Models\PurchaseOrderInvitation $invitation **/ $invitation = PurchaseOrderInvitation::factory()->create([