Fixes for static analysis

This commit is contained in:
David Bomba 2023-08-11 08:10:21 +10:00
parent 1c909d6c60
commit 5ca41f5f86
4 changed files with 26 additions and 17 deletions

View File

@ -13,14 +13,12 @@ namespace App\Http\Middleware;
use Auth; use Auth;
use Closure; use Closure;
use App\Utils\Ninja;
use App\Models\Vendor; use App\Models\Vendor;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\VendorContact; use App\Models\VendorContact;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Events\Vednor\VendorContactLoggedIn;
class VendorContactKeyLogin class VendorContactKeyLogin
{ {
@ -59,8 +57,6 @@ class VendorContactKeyLogin
auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); 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'))) { if ($request->query('redirect') && ! empty($request->query('redirect'))) {
return redirect()->to($request->query('redirect')); return redirect()->to($request->query('redirect'));
} }
@ -76,7 +72,6 @@ class VendorContactKeyLogin
$vendor_contact->save(); $vendor_contact->save();
auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); auth()->guard('vendor')->loginUsingId($vendor_contact->id, true);
event(new VendorContactLoggedIn($vendor_contact, $vendor_contact->company, Ninja::eventVars()));
if ($request->query('next')) { if ($request->query('next')) {
return redirect()->to($request->query('next')); return redirect()->to($request->query('next'));
} }

View File

@ -39,7 +39,7 @@ class YodleeAuthRequest extends Request
return []; return [];
} }
/** @var $token */ /** @var Request $token */
public function getTokenContent() public function getTokenContent()
{ {
if ($this->state) { if ($this->state) {

View File

@ -44,7 +44,7 @@ class VendorContactTransformer extends EntityTransformer
'custom_value3' => $vendor->custom_value3 ?: '', 'custom_value3' => $vendor->custom_value3 ?: '',
'custom_value4' => $vendor->custom_value4 ?: '', 'custom_value4' => $vendor->custom_value4 ?: '',
'link' => $vendor->getLoginLink(), 'link' => $vendor->getLoginLink(),
'last_login' => 'timestamp', 'last_login' => (int)$vendor->last_login,
]; ];
} }
} }

View File

@ -52,8 +52,8 @@ class TemplateEngine
public $template; public $template;
/** @var Invoice | Quote | Credit | PurchaseOrder | RecurringInvoice | null $entity_obj **/ /** @var \App\Models\Invoice | \App\Models\Quote | \App\Models\Credit | \App\Models\PurchaseOrder | \App\Models\RecurringInvoice $entity_obj **/
private $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 **/ /** @var \App\Models\Company | \App\Models\Client | null $settings_entity **/
private $settings_entity; private $settings_entity;
@ -81,7 +81,7 @@ class TemplateEngine
$this->template = $template; $this->template = $template;
$this->entity_obj = null; // $this->entity_obj = null;
$this->settings_entity = null; $this->settings_entity = null;
} }
@ -99,7 +99,7 @@ class TemplateEngine
{ {
if (strlen($this->entity) > 1 && strlen($this->entity_id) > 1) { if (strlen($this->entity) > 1 && strlen($this->entity_id) > 1) {
$class = 'App\Models\\' . ucfirst(Str::camel($this->entity)); $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()) { } elseif (stripos($this->template, 'quote') !== false && $quote = Quote::query()->whereHas('invitations')->withTrashed()->company()->first()) {
$this->entity = 'quote'; $this->entity = 'quote';
$this->entity_obj = $quote; $this->entity_obj = $quote;
@ -111,6 +111,7 @@ class TemplateEngine
$this->entity_obj = $payment; $this->entity_obj = $payment;
} }
elseif ($invoice = Invoice::query()->whereHas('invitations')->withTrashed()->company()->first()) { elseif ($invoice = Invoice::query()->whereHas('invitations')->withTrashed()->company()->first()) {
/** @var \App\Models\Invoice $invoice */
$this->entity_obj = $invoice; $this->entity_obj = $invoice;
} else { } else {
$this->mockEntity(); $this->mockEntity();
@ -286,6 +287,8 @@ class TemplateEngine
private function mockEntity() private function mockEntity()
{ {
$invitation = false;
if (!$this->entity && $this->template && str_contains($this->template, 'purchase_order')) { if (!$this->entity && $this->template && str_contains($this->template, 'purchase_order')) {
$this->entity = 'purchaseOrder'; $this->entity = 'purchaseOrder';
} elseif (str_contains($this->template, 'payment')) { } elseif (str_contains($this->template, 'payment')) {
@ -304,7 +307,6 @@ class TemplateEngine
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
]); ]);
/** @var \App\Models\ClientContact $contact */ /** @var \App\Models\ClientContact $contact */
$contact = ClientContact::factory()->create([ $contact = ClientContact::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
@ -315,7 +317,8 @@ class TemplateEngine
]); ]);
if ($this->entity == 'payment') { if ($this->entity == 'payment') {
$this->entity_obj = Payment::factory()->create([ /** @var \App\Models\Payment $payment */
$payment = Payment::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
'client_id' => $client->id, 'client_id' => $client->id,
@ -324,6 +327,8 @@ class TemplateEngine
'refunded' => 5, 'refunded' => 5,
]); ]);
$this->entity_obj = $payment;
/** @var \App\Models\Invoice $invoice */ /** @var \App\Models\Invoice $invoice */
$invoice = Invoice::factory()->create([ $invoice = Invoice::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
@ -349,7 +354,8 @@ class TemplateEngine
} }
if (!$this->entity || $this->entity == 'invoice') { 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, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
'client_id' => $client->id, 'client_id' => $client->id,
@ -357,6 +363,8 @@ class TemplateEngine
'balance' => '10', 'balance' => '10',
]); ]);
$this->entity_obj = $invoice;
$invitation = InvoiceInvitation::factory()->create([ $invitation = InvoiceInvitation::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
@ -366,12 +374,15 @@ class TemplateEngine
} }
if ($this->entity == 'quote') { if ($this->entity == 'quote') {
$this->entity_obj = Quote::factory()->create([ /** @var \App\Models\Quote $quote */
$quote = Quote::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
'client_id' => $client->id, 'client_id' => $client->id,
]); ]);
$this->entity_obj = $quote;
$invitation = QuoteInvitation::factory()->create([ $invitation = QuoteInvitation::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
@ -396,12 +407,15 @@ class TemplateEngine
'send_email' => true, 'send_email' => true,
]); ]);
$this->entity_obj = PurchaseOrder::factory()->create([ /** @var \App\Models\PurchaseOrder $purchase_order **/
$purchase_order = PurchaseOrder::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,
'company_id' => $user->company()->id, 'company_id' => $user->company()->id,
'vendor_id' => $vendor->id, 'vendor_id' => $vendor->id,
]); ]);
$this->entity_obj = $purchase_order;
/** @var \App\Models\PurchaseOrderInvitation $invitation **/ /** @var \App\Models\PurchaseOrderInvitation $invitation **/
$invitation = PurchaseOrderInvitation::factory()->create([ $invitation = PurchaseOrderInvitation::factory()->create([
'user_id' => $user->id, 'user_id' => $user->id,