Fixes for static analysis

This commit is contained in:
David Bomba 2023-08-15 09:49:09 +10:00
parent 17e4e901bd
commit c91e093a41
2 changed files with 26 additions and 62 deletions

View File

@ -162,7 +162,9 @@ class InvoiceController extends BaseController
*/ */
public function create(CreateInvoiceRequest $request) public function create(CreateInvoiceRequest $request)
{ {
$invoice = InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id); /** @var \App\Models\User $user */
$user = auth()->user();
$invoice = InvoiceFactory::create($user->company()->id, $user->id);
return $this->itemResponse($invoice); return $this->itemResponse($invoice);
} }
@ -211,7 +213,11 @@ class InvoiceController extends BaseController
*/ */
public function store(StoreInvoiceRequest $request) public function store(StoreInvoiceRequest $request)
{ {
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
/** @var \App\Models\User $user */
$user = auth()->user();
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create($user->company()->id, $user->id));
$invoice = $invoice->service() $invoice = $invoice->service()
->fillDefaults() ->fillDefaults()
@ -219,7 +225,7 @@ class InvoiceController extends BaseController
->adjustInventory() ->adjustInventory()
->save(); ->save();
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars($user ? $user->id : null)));
$transaction = [ $transaction = [
'invoice' => $invoice->transaction_event(), 'invoice' => $invoice->transaction_event(),
@ -473,62 +479,17 @@ class InvoiceController extends BaseController
return $this->itemResponse($invoice->fresh()); return $this->itemResponse($invoice->fresh());
} }
/**
* Perform bulk actions on the list view.
*
* @return \Illuminate\Support\Collection
*
* @OA\Post(
* path="/api/v1/invoices/bulk",
* operationId="bulkInvoices",
* tags={"invoices"},
* summary="Performs bulk actions on an array of invoices",
* description="",
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="User credentials",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="integer",
* description="Array of hashed IDs to be bulk 'actioned",
* example="[0,1,2,3]",
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
* description="The Bulk Action response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function bulk(BulkInvoiceRequest $request) public function bulk(BulkInvoiceRequest $request)
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$action = $request->input('action'); $action = $request->input('action');
$ids = $request->input('ids'); $ids = $request->input('ids');
if (Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified) { if (Ninja::isHosted() && (stripos($action, 'email') !== false) && !$user->company()->account->account_sms_verified) {
return response(['message' => 'Please verify your account to send emails.'], 400); return response(['message' => 'Please verify your account to send emails.'], 400);
} }
@ -543,8 +504,8 @@ class InvoiceController extends BaseController
*/ */
if ($action == 'bulk_download' && $invoices->count() > 1) { if ($action == 'bulk_download' && $invoices->count() > 1) {
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) use($user) {
if (auth()->user()->cannot('view', $invoice)) { if ($user->cannot('view', $invoice)) {
nlog('access denied'); nlog('access denied');
return response()->json(['message' => ctrans('text.access_denied')]); return response()->json(['message' => ctrans('text.access_denied')]);
@ -556,7 +517,7 @@ class InvoiceController extends BaseController
return response()->json(['message' => ctrans('texts.sent_message')], 200); return response()->json(['message' => ctrans('texts.sent_message')], 200);
} }
if ($action == 'download' && $invoices->count() >=1 && auth()->user()->can('view', $invoices->first())) { if ($action == 'download' && $invoices->count() >=1 && $user->can('view', $invoices->first())) {
$file = $invoices->first()->service()->getInvoicePdf(); $file = $invoices->first()->service()->getInvoicePdf();
return response()->streamDownload(function () use ($file) { return response()->streamDownload(function () use ($file) {
@ -564,7 +525,7 @@ class InvoiceController extends BaseController
}, basename($file), ['Content-Type' => 'application/pdf']); }, basename($file), ['Content-Type' => 'application/pdf']);
} }
if ($action == 'bulk_print' && auth()->user()->can('view', $invoices->first())) { if ($action == 'bulk_print' && $user->can('view', $invoices->first())) {
$paths = $invoices->map(function ($invoice) { $paths = $invoices->map(function ($invoice) {
return $invoice->service()->getInvoicePdf(); return $invoice->service()->getInvoicePdf();
}); });
@ -579,15 +540,15 @@ class InvoiceController extends BaseController
/* /*
* Send the other actions to the switch * Send the other actions to the switch
*/ */
$invoices->each(function ($invoice, $key) use ($action) { $invoices->each(function ($invoice, $key) use ($action, $user) {
if (auth()->user()->can('edit', $invoice)) { if ($user->can('edit', $invoice)) {
$this->performAction($invoice, $action, true); $this->performAction($invoice, $action, true);
} }
}); });
/* Need to understand which permission are required for the given bulk action ie. view / edit */ /* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); return $this->listResponse(Invoice::query()->withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
} }
/** /**
@ -1022,7 +983,10 @@ class InvoiceController extends BaseController
public function update_reminders(UpdateReminderRequest $request) public function update_reminders(UpdateReminderRequest $request)
{ {
UpdateReminders::dispatch(auth()->user()->company()); /** @var \App\Models\User $user */
$user = auth()->user();
UpdateReminders::dispatch($user->company());
return response()->json(['message' => 'Updating reminders'], 200); return response()->json(['message' => 'Updating reminders'], 200);
} }

View File

@ -1821,7 +1821,7 @@ class Import implements ShouldQueue
private function processActivities(array $data): void private function processActivities(array $data): void
{ {
Activity::where('company_id', $this->company->id)->cursor()->each(function ($a){ Activity::query()->where('company_id', $this->company->id)->cursor()->each(function ($a){
$a->forceDelete(); $a->forceDelete();
nlog("deleting {$a->id}"); nlog("deleting {$a->id}");
}); });