Static analysis

This commit is contained in:
David Bomba 2023-08-08 18:56:31 +10:00
parent 53ddb61cdb
commit b352178696
24 changed files with 63 additions and 44 deletions

View File

@ -64,9 +64,9 @@ class BillingPortalPurchase extends Component
/** /**
* Instance of subscription. * Instance of subscription.
* *
* @var Subscription * @var \App\Models\Subscription $subscription
*/ */
public $subscription; public Subscription $subscription;
/** /**
* Instance of client contact. * Instance of client contact.

View File

@ -280,7 +280,7 @@ class CompanyImport implements ShouldQueue
'errors' => [] 'errors' => []
]; ];
$_company = Company::find($this->company->id); $_company = Company::query()->find($this->company->id);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new ImportCompleted($_company, $data); $nmo->mailable = new ImportCompleted($_company, $data);

View File

@ -122,11 +122,11 @@ class CreateRawPdf implements ShouldQueue
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id)); $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
$design = Design::withTrashed()->find($entity_design_id); $design = Design::query()->withTrashed()->find($entity_design_id);
/* Catch all in case migration doesn't pass back a valid design */ /* Catch all in case migration doesn't pass back a valid design */
if (! $design) { if (! $design) {
$design = Design::find(2); $design = Design::query()->find(2);
} }
$html = new HtmlEngine($this->invitation); $html = new HtmlEngine($this->invitation);

View File

@ -131,7 +131,7 @@ class AdjustProductInventory implements ShouldQueue
collect($this->old_invoice)->filter(function ($item) { collect($this->old_invoice)->filter(function ($item) {
return $item->type_id == '1'; return $item->type_id == '1';
})->each(function ($i) { })->each(function ($i) {
$p = Product::where('product_key', $i->product_key)->where('company_id', $this->company->id)->first(); $p = Product::query()->where('product_key', $i->product_key)->where('company_id', $this->company->id)->first();
if ($p) { if ($p) {
$p->in_stock_quantity += $i->quantity; $p->in_stock_quantity += $i->quantity;

View File

@ -43,16 +43,16 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
CompanyLedger::where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) { CompanyLedger::query()->where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) {
if ($company_ledger->balance == 0) { if ($company_ledger->balance == 0) {
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id) $last_record = CompanyLedger::query()->where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id) ->where('company_id', $company_ledger->company_id)
->where('balance', '!=', 0) ->where('balance', '!=', 0)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->first(); ->first();
if (! $last_record) { if (! $last_record) {
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id) $last_record = CompanyLedger::query()->where('client_id', $company_ledger->client_id)
->where('company_id', $company_ledger->company_id) ->where('company_id', $company_ledger->company_id)
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->first(); ->first();

View File

@ -51,7 +51,7 @@ class NinjaMailerJob implements ShouldQueue
public $override; public $override;
/* @var \App\Models\Company $company*/ /** @var \App\Models\Company $company | null **/
public ?Company $company; public ?Company $company;
private $mailer; private $mailer;
@ -83,7 +83,7 @@ class NinjaMailerJob implements ShouldQueue
MultiDB::setDb($this->nmo->company->db); MultiDB::setDb($this->nmo->company->db);
/* Serializing models from other jobs wipes the primary key */ /* Serializing models from other jobs wipes the primary key */
$this->company = Company::where('company_key', $this->nmo->company->company_key)->first(); $this->company = Company::query()->where('company_key', $this->nmo->company->company_key)->first();
/* If any pre conditions fail, we return early here */ /* If any pre conditions fail, we return early here */
if (!$this->company || $this->preFlightChecksFail()) { if (!$this->company || $this->preFlightChecksFail()) {
@ -552,7 +552,7 @@ class NinjaMailerJob implements ShouldQueue
* Logs any errors to the SystemLog * Logs any errors to the SystemLog
* *
* @param string $errors * @param string $errors
* @param App\Models\User | App\Models\Client | null $recipient_object * @param \App\Models\User | \App\Models\Client | null $recipient_object
* @return void * @return void
*/ */
private function logMailError($errors, $recipient_object) :void private function logMailError($errors, $recipient_object) :void

View File

@ -84,7 +84,14 @@ class PaymentFailureMailer implements ShouldQueue
if (($key = array_search('mail', $methods)) !== false) { if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]); unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null))->build(); $use_react_link = false;
if(isset($company_user->react_settings->react_notification_link) && $company_user->react_settings->react_notification_link) {
$use_react_link = true;
}
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null, $use_react_link))->build();
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj); $nmo->mailable = new NinjaMailer($mail_obj);

View File

@ -42,7 +42,7 @@ class UpdateRecurring implements ShouldQueue
$this->user->setCompany($this->company); $this->user->setCompany($this->company);
RecurringInvoice::where('company_id', $this->company->id) RecurringInvoice::query()->where('company_id', $this->company->id)
->whereIn('id', $this->ids) ->whereIn('id', $this->ids)
->chunk(100, function ($recurring_invoices) { ->chunk(100, function ($recurring_invoices) {
foreach ($recurring_invoices as $recurring_invoice) { foreach ($recurring_invoices as $recurring_invoice) {

View File

@ -1654,8 +1654,8 @@ class Import implements ShouldQueue
$modified['company_gateway_id'] = $this->transformId('company_gateways', $resource['company_gateway_id']); $modified['company_gateway_id'] = $this->transformId('company_gateways', $resource['company_gateway_id']);
//$modified['user_id'] = $this->processUserId($resource); //$modified['user_id'] = $this->processUserId($resource);
/** @var \App\Models\ClientGatewayToken $cgt **/
$cgt = ClientGatewayToken::Create($modified); $cgt = ClientGatewayToken::create($modified);
$key = "client_gateway_tokens_{$resource['id']}"; $key = "client_gateway_tokens_{$resource['id']}";
@ -1684,7 +1684,8 @@ class Import implements ShouldQueue
$modified['company_id'] = $this->company->id; $modified['company_id'] = $this->company->id;
$modified['user_id'] = $this->processUserId($resource); $modified['user_id'] = $this->processUserId($resource);
$task_status = TaskStatus::Create($modified); /** @var \App\Models\TaskStatus $task_status **/
$task_status = TaskStatus::create($modified);
$key = "task_statuses_{$resource['id']}"; $key = "task_statuses_{$resource['id']}";
@ -1712,7 +1713,8 @@ class Import implements ShouldQueue
$modified['company_id'] = $this->company->id; $modified['company_id'] = $this->company->id;
$modified['user_id'] = $this->processUserId($resource); $modified['user_id'] = $this->processUserId($resource);
$expense_category = ExpenseCategory::Create($modified); /** @var \App\Models\ExpenseCategory $expense_category **/
$expense_category = ExpenseCategory::create($modified);
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id; $old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
@ -1757,7 +1759,8 @@ class Import implements ShouldQueue
$modified['status_id'] = $this->transformId('task_statuses', $resource['status_id']); $modified['status_id'] = $this->transformId('task_statuses', $resource['status_id']);
} }
$task = Task::Create($modified); /** @var \App\Models\Task $task **/
$task = Task::create($modified);
if (array_key_exists('created_at', $modified)) { if (array_key_exists('created_at', $modified)) {
$task->created_at = Carbon::parse($modified['created_at']); $task->created_at = Carbon::parse($modified['created_at']);
@ -1767,8 +1770,6 @@ class Import implements ShouldQueue
$task->updated_at = Carbon::parse($modified['updated_at']); $task->updated_at = Carbon::parse($modified['updated_at']);
} }
$task->save(['timestamps' => false]); $task->save(['timestamps' => false]);
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id; $old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;
@ -1871,6 +1872,7 @@ try {
$modified['updated_at'] = $modified['created_at']; $modified['updated_at'] = $modified['created_at'];
/** @var \App\Models\Activity $act **/
$act = Activity::make($modified); $act = Activity::make($modified);
$act->save(['timestamps' => false]); $act->save(['timestamps' => false]);
@ -1921,7 +1923,8 @@ nlog("could not import activity: {$e->getMessage()}");
$modified['vendor_id'] = $this->transformId('vendors', $resource['vendor_id']); $modified['vendor_id'] = $this->transformId('vendors', $resource['vendor_id']);
} }
$expense = Expense::Create($modified); /** @var \App\Models\Expense $expense **/
$expense = Expense::create($modified);
if (array_key_exists('created_at', $modified)) { if (array_key_exists('created_at', $modified)) {
$expense->created_at = Carbon::parse($modified['created_at']); $expense->created_at = Carbon::parse($modified['created_at']);
@ -1931,8 +1934,6 @@ nlog("could not import activity: {$e->getMessage()}");
$expense->updated_at = Carbon::parse($modified['updated_at']); $expense->updated_at = Carbon::parse($modified['updated_at']);
} }
$expense->save(['timestamps' => false]); $expense->save(['timestamps' => false]);
$old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id; $old_user_key = array_key_exists('user_id', $resource) ?? $this->user->id;

View File

@ -44,13 +44,13 @@ class ImportStripeCustomers implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
* *
* @return bool
*/ */
public function handle() public function handle()
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$cgs = CompanyGateway::where('company_id', $this->company->id) $cgs = CompanyGateway::query()
->where('company_id', $this->company->id)
->where('is_deleted', 0) ->where('is_deleted', 0)
->whereIn('gateway_key', $this->stripe_keys) ->whereIn('gateway_key', $this->stripe_keys)
->get(); ->get();

View File

@ -159,7 +159,7 @@ class ReminderJob implements ShouldQueue
} }
} }
private function addFeeToNewInvoice(Invoice $over_due_invoice, string $reminder_template, array $fees): void private function addFeeToNewInvoice(Invoice $over_due_invoice, string $reminder_template, array $fees)
{ {
$amount = $fees[0]; $amount = $fees[0];

View File

@ -42,13 +42,13 @@ class StripeUpdatePaymentMethods implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
* *
* @return bool
*/ */
public function handle() public function handle()
{ {
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
$cgs = CompanyGateway::where('company_id', $this->company->id) $cgs = CompanyGateway::query()
->where('company_id', $this->company->id)
->whereIn('gateway_key', $this->stripe_keys) ->whereIn('gateway_key', $this->stripe_keys)
->get(); ->get();

View File

@ -51,6 +51,8 @@ class UploadFile implements ShouldQueue
public $entity; public $entity;
public $disk;
public function __construct($file, $type, $user, $company, $entity, $disk = null, $is_public = false) public function __construct($file, $type, $user, $company, $entity, $disk = null, $is_public = false)
{ {
$this->file = $file; $this->file = $file;

View File

@ -43,7 +43,6 @@ class WebhookHandler implements ShouldQueue
/** /**
* Execute the job. * Execute the job.
* *
* @return bool
*/ */
public function handle() public function handle()
{ {
@ -54,7 +53,8 @@ class WebhookHandler implements ShouldQueue
return true; return true;
} }
Webhook::where('company_id', $this->company->id) Webhook::query()
->where('company_id', $this->company->id)
->where('event_id', $this->event_id) ->where('event_id', $this->event_id)
->cursor() ->cursor()
->each(function ($subscription) { ->each(function ($subscription) {

View File

@ -39,6 +39,10 @@ class OAuth
const SOCIAL_APPLE = 8; const SOCIAL_APPLE = 8;
public $provider_instance;
public $provider_id;
/** /**
* @param \Laravel\Socialite\Facades\Socialite $socialite_user * @param \Laravel\Socialite\Facades\Socialite $socialite_user
* @return bool | \App\Models\User | \App\Models\User | null * @return bool | \App\Models\User | \App\Models\User | null
@ -87,6 +91,8 @@ class OAuth
return 'microsoft'; return 'microsoft';
case self::SOCIAL_APPLE: case self::SOCIAL_APPLE:
return 'apple'; return 'apple';
default:
return 'google';
} }
} }
@ -109,6 +115,8 @@ class OAuth
return self::SOCIAL_MICROSOFT; return self::SOCIAL_MICROSOFT;
case 'apple': case 'apple':
return self::SOCIAL_APPLE; return self::SOCIAL_APPLE;
default:
return self::SOCIAL_GOOGLE;
} }
} }

View File

@ -38,7 +38,7 @@ class MigrationCompleted extends Mailable
public function build() public function build()
{ {
MultiDB::setDb($this->db); MultiDB::setDb($this->db);
$this->company = Company::find($this->company_id); $this->company = Company::query()->find($this->company_id);
App::forgetInstance('translator'); App::forgetInstance('translator');
$t = app('translator'); $t = app('translator');

View File

@ -537,8 +537,8 @@ class Client extends BaseModel implements HasLocalePreference
foreach ($pms as $pm) { foreach ($pms as $pm) {
if ($pm['gateway_type_id'] == GatewayType::CREDIT_CARD) { if ($pm['gateway_type_id'] == GatewayType::CREDIT_CARD) {
/**@var \App\Models\CompanyGateway $cg */
$cg = CompanyGateway::find($pm['company_gateway_id']); $cg = CompanyGateway::query()->find($pm['company_gateway_id']);
if ($cg && ! property_exists($cg->fees_and_limits, strval(GatewayType::CREDIT_CARD))) { if ($cg && ! property_exists($cg->fees_and_limits, strval(GatewayType::CREDIT_CARD))) {
$fees_and_limits = $cg->fees_and_limits; $fees_and_limits = $cg->fees_and_limits;
@ -561,7 +561,7 @@ class Client extends BaseModel implements HasLocalePreference
foreach ($pms as $pm) { foreach ($pms as $pm) {
if ($pm['gateway_type_id'] == GatewayType::BACS) { if ($pm['gateway_type_id'] == GatewayType::BACS) {
$cg = CompanyGateway::find($pm['company_gateway_id']); $cg = CompanyGateway::query()->find($pm['company_gateway_id']);
if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::BACS)) { if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::BACS)) {
$fees_and_limits = $cg->fees_and_limits; $fees_and_limits = $cg->fees_and_limits;
@ -587,7 +587,7 @@ class Client extends BaseModel implements HasLocalePreference
if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id'))) { if ($this->currency()->code == 'USD' && in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id'))) {
foreach ($pms as $pm) { foreach ($pms as $pm) {
if ($pm['gateway_type_id'] == GatewayType::BANK_TRANSFER) { if ($pm['gateway_type_id'] == GatewayType::BANK_TRANSFER) {
$cg = CompanyGateway::find($pm['company_gateway_id']); $cg = CompanyGateway::query()->find($pm['company_gateway_id']);
if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::BANK_TRANSFER)) { if ($cg && ! property_exists($cg->fees_and_limits, GatewayType::BANK_TRANSFER)) {
$fees_and_limits = $cg->fees_and_limits; $fees_and_limits = $cg->fees_and_limits;
@ -606,7 +606,7 @@ class Client extends BaseModel implements HasLocalePreference
if ($this->currency()->code == 'EUR' && (in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id')) || in_array(GatewayType::SEPA, array_column($pms, 'gateway_type_id')))) { if ($this->currency()->code == 'EUR' && (in_array(GatewayType::BANK_TRANSFER, array_column($pms, 'gateway_type_id')) || in_array(GatewayType::SEPA, array_column($pms, 'gateway_type_id')))) {
foreach ($pms as $pm) { foreach ($pms as $pm) {
if ($pm['gateway_type_id'] == GatewayType::SEPA) { if ($pm['gateway_type_id'] == GatewayType::SEPA) {
$cg = CompanyGateway::find($pm['company_gateway_id']); $cg = CompanyGateway::query()->find($pm['company_gateway_id']);
if ($cg && $cg->fees_and_limits->{GatewayType::SEPA}->is_enabled) { if ($cg && $cg->fees_and_limits->{GatewayType::SEPA}->is_enabled) {
return $cg; return $cg;
@ -618,7 +618,7 @@ class Client extends BaseModel implements HasLocalePreference
if (in_array(GatewayType::DIRECT_DEBIT, array_column($pms, 'gateway_type_id'))) { if (in_array(GatewayType::DIRECT_DEBIT, array_column($pms, 'gateway_type_id'))) {
foreach ($pms as $pm) { foreach ($pms as $pm) {
if ($pm['gateway_type_id'] == GatewayType::DIRECT_DEBIT) { if ($pm['gateway_type_id'] == GatewayType::DIRECT_DEBIT) {
$cg = CompanyGateway::find($pm['company_gateway_id']); $cg = CompanyGateway::query()->find($pm['company_gateway_id']);
if ($cg && $cg->fees_and_limits->{GatewayType::DIRECT_DEBIT}->is_enabled) { if ($cg && $cg->fees_and_limits->{GatewayType::DIRECT_DEBIT}->is_enabled) {
return $cg; return $cg;

View File

@ -67,6 +67,10 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property bool $is_large * @property bool $is_large
* @property int $enable_shop_api * @property int $enable_shop_api
* @property string $default_auto_bill * @property string $default_auto_bill
* @property string $custom_value1
* @property string $custom_value2
* @property string $custom_value3
* @property string $custom_value4
* @property bool $mark_expenses_invoiceable * @property bool $mark_expenses_invoiceable
* @property bool $mark_expenses_paid * @property bool $mark_expenses_paid
* @property bool $invoice_expense_documents * @property bool $invoice_expense_documents

View File

@ -18,7 +18,7 @@ use Illuminate\Database\Eloquent\Model;
* *
* @property int $id * @property int $id
* @property string $hash * @property string $hash
* @property string $fee_total * @property float $fee_total
* @property int|null $fee_invoice_id * @property int|null $fee_invoice_id
* @property mixed $data * @property mixed $data
* @property int|null $payment_id * @property int|null $payment_id

View File

@ -31,7 +31,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property-read \App\Models\Company|null $company * @property-read \App\Models\Company|null $company
* @property-read mixed $hashed_id * @property-read mixed $hashed_id
* @property-read \App\Models\User|null $user * @property-read \App\Models\User|null $user
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|Webhook filter(\App\Filters\QueryFilters $filters) * @method static \Illuminate\Database\Eloquent\Builder|Webhook filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Webhook newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Webhook newModelQuery()

View File

@ -166,7 +166,6 @@ class ClientService
* *
* @param mixed $pdf The pdf blob * @param mixed $pdf The pdf blob
* @param array $options The statement options array * @param array $options The statement options array
* @return void
*/ */
private function emailStatement($pdf, array $options): void private function emailStatement($pdf, array $options): void
{ {

View File

@ -52,7 +52,7 @@ class InstantPayment
$is_credit_payment = true; $is_credit_payment = true;
} }
$gateway = CompanyGateway::find($this->request->input('company_gateway_id')); $gateway = CompanyGateway::query()->find($this->request->input('company_gateway_id'));
/** /**
* find invoices * find invoices

View File

@ -33,7 +33,6 @@ class SendEmail
/** /**
* Builds the correct template to send. * Builds the correct template to send.
* @return void
*/ */
public function run() public function run()
{ {

View File

@ -194,7 +194,7 @@ class AutoBillInvoice extends AbstractService
$current_credit = false; $current_credit = false;
foreach ($this->used_credit as $credit) { foreach ($this->used_credit as $credit) {
$current_credit = Credit::find($credit['credit_id']); $current_credit = Credit::query()->find($credit['credit_id']);
$payment->credits() $payment->credits()
->attach($current_credit->id, ['amount' => $credit['amount']]); ->attach($current_credit->id, ['amount' => $credit['amount']]);