1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

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)
{
$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);
}
@ -211,7 +213,11 @@ class InvoiceController extends BaseController
*/
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()
->fillDefaults()
@ -219,7 +225,7 @@ class InvoiceController extends BaseController
->adjustInventory()
->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 = [
'invoice' => $invoice->transaction_event(),
@ -473,62 +479,17 @@ class InvoiceController extends BaseController
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)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$action = $request->input('action');
$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);
}
@ -543,8 +504,8 @@ class InvoiceController extends BaseController
*/
if ($action == 'bulk_download' && $invoices->count() > 1) {
$invoices->each(function ($invoice) {
if (auth()->user()->cannot('view', $invoice)) {
$invoices->each(function ($invoice) use($user) {
if ($user->cannot('view', $invoice)) {
nlog('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);
}
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();
return response()->streamDownload(function () use ($file) {
@ -564,7 +525,7 @@ class InvoiceController extends BaseController
}, 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) {
return $invoice->service()->getInvoicePdf();
});
@ -579,15 +540,15 @@ class InvoiceController extends BaseController
/*
* Send the other actions to the switch
*/
$invoices->each(function ($invoice, $key) use ($action) {
if (auth()->user()->can('edit', $invoice)) {
$invoices->each(function ($invoice, $key) use ($action, $user) {
if ($user->can('edit', $invoice)) {
$this->performAction($invoice, $action, true);
}
});
/* 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)
{
UpdateReminders::dispatch(auth()->user()->company());
/** @var \App\Models\User $user */
$user = auth()->user();
UpdateReminders::dispatch($user->company());
return response()->json(['message' => 'Updating reminders'], 200);
}

View File

@ -1821,7 +1821,7 @@ class Import implements ShouldQueue
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();
nlog("deleting {$a->id}");
});