Static Analysis Cleanup

This commit is contained in:
David Bomba 2023-08-08 20:39:46 +10:00
parent 6e64a9c74a
commit 91d39aab82
21 changed files with 82 additions and 55 deletions

View File

@ -31,7 +31,10 @@ class StoreCreditRequest extends Request
*/
public function authorize()
{
return auth()->user()->can('create', Credit::class);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Credit::class);
}
/**
@ -55,10 +58,13 @@ class StoreCreditRequest extends Request
$rules['file'] = $this->file_validation;
}
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
/** @var \App\Models\User $user */
$user = auth()->user();
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
// $rules['number'] = new UniqueCreditNumberRule($this->all());
$rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', auth()->user()->company()->id)];
$rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean'];
$rules['tax_rate1'] = 'bail|sometimes|numeric';
@ -67,7 +73,7 @@ class StoreCreditRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
if ($this->invoice_id) {
$rules['invoice_id'] = new ValidInvoiceCreditRule();

View File

@ -30,7 +30,10 @@ class UpdateCreditRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->credit);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->credit);
}
/**
@ -40,6 +43,9 @@ class UpdateCreditRequest extends Request
*/
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -55,7 +61,7 @@ class UpdateCreditRequest extends Request
}
if ($this->number) {
$rules['number'] = Rule::unique('credits')->where('company_id', auth()->user()->company()->id)->ignore($this->credit->id);
$rules['number'] = Rule::unique('credits')->where('company_id', $user->company()->id)->ignore($this->credit->id);
}
$rules['line_items'] = 'array';
@ -67,7 +73,7 @@ class UpdateCreditRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -72,7 +72,7 @@ class StoreInvoiceRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -40,6 +40,9 @@ class UpdateInvoiceRequest extends Request
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -57,7 +60,7 @@ class UpdateInvoiceRequest extends Request
$rules['id'] = new LockedInvoiceRule($this->invoice);
if ($this->number) {
$rules['number'] = Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)->ignore($this->invoice->id);
$rules['number'] = Rule::unique('invoices')->where('company_id', $user->company()->id)->ignore($this->invoice->id);
}
$rules['is_amount_discount'] = ['boolean'];
@ -72,10 +75,7 @@ class UpdateInvoiceRequest extends Request
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['status_id'] = 'bail|sometimes|not_in:5'; //do not allow cancelled invoices to be modfified.
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
// not needed.
// $rules['partial_due_date'] = 'bail|sometimes|required_unless:partial,0,null';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -29,7 +29,10 @@ class StorePurchaseOrderRequest extends Request
*/
public function authorize()
{
return auth()->user()->can('create', PurchaseOrder::class);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', PurchaseOrder::class);
}
/**
* Get the validation rules that apply to the request.
@ -38,11 +41,14 @@ class StorePurchaseOrderRequest extends Request
*/
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
$rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
$rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['number'] = ['nullable', Rule::unique('purchase_orders')->where('company_id', auth()->user()->company()->id)];
$rules['number'] = ['nullable', Rule::unique('purchase_orders')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean'];
$rules['line_items'] = 'array';
@ -60,7 +66,7 @@ class StorePurchaseOrderRequest extends Request
}
$rules['status_id'] = 'nullable|integer|in:1,2,3,4,5';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -63,7 +63,7 @@ class UpdatePurchaseOrderRequest extends Request
}
$rules['status_id'] = 'sometimes|integer|in:1,2,3,4,5';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -30,14 +30,20 @@ class StoreQuoteRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('create', Quote::class);
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Quote::class);
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
if ($this->file('documents') && is_array($this->file('documents'))) {
$rules['documents.*'] = $this->file_validation;
@ -51,11 +57,11 @@ class StoreQuoteRequest extends Request
$rules['file'] = $this->file_validation;
}
$rules['number'] = ['nullable', Rule::unique('quotes')->where('company_id', auth()->user()->company()->id)];
$rules['number'] = ['nullable', Rule::unique('quotes')->where('company_id', $user->company()->id)];
$rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean'];
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
// $rules['number'] = new UniqueQuoteNumberRule($this->all());
$rules['line_items'] = 'array';

View File

@ -57,7 +57,7 @@ class UpdateQuoteRequest extends Request
$rules['line_items'] = 'array';
$rules['discount'] = 'sometimes|numeric';
$rules['is_amount_discount'] = ['boolean'];
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -40,6 +40,9 @@ class StoreRecurringInvoiceRequest extends Request
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -54,7 +57,7 @@ class StoreRecurringInvoiceRequest extends Request
$rules['file'] = $this->file_validation;
}
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
$rules['invitations.*.client_contact_id'] = 'distinct';
@ -71,7 +74,7 @@ class StoreRecurringInvoiceRequest extends Request
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['due_date_days'] = 'bail|sometimes|string';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}

View File

@ -67,7 +67,7 @@ class UpdateRecurringInvoiceRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
$rules['exchange_rate'] = 'bail|sometimes|numeric';
return $rules;
}
@ -132,7 +132,7 @@ class UpdateRecurringInvoiceRequest extends Request
unset($input['documents']);
}
if (array_key_exists('exchange_rate', $input) && (is_null($input['exchange_rate']) || $input['exchange_rate'] == 0)) {
if (array_key_exists('exchange_rate', $input) && (is_null($input['exchange_rate']) || $input['exchange_rate'] == 0) || !isset($input['exchange_rate'])) {
$input['exchange_rate'] = 1;
}
@ -148,7 +148,7 @@ class UpdateRecurringInvoiceRequest extends Request
*
* @return bool
*/
private function setAutoBillFlag($auto_bill)
private function setAutoBillFlag($auto_bill): bool
{
if ($auto_bill == 'always' || $auto_bill == 'optout') {
return true;

View File

@ -288,7 +288,7 @@ class MatchBankTransactions implements ShouldQueue
$this->available_balance = $amount;
\DB::connection(config('database.default'))->transaction(function () use ($invoices) {
$invoices->each(function ($invoice) use ($invoices) {
$invoices->each(function ($invoice) {
$this->invoice = Invoice::withTrashed()->where('id', $invoice->id)->lockForUpdate()->first();
$_amount = false;

View File

@ -1803,7 +1803,8 @@ class Import implements ShouldQueue
$modified['client_id'] = $this->transformId('clients', $resource['client_id']);
}
$project = Project::Create($modified);
/** @var \App\Models\Project $project **/
$project = Project::create($modified);
$key = "projects_{$resource['id']}";

View File

@ -53,11 +53,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int $use_inventory_management
* @property string|null $optional_product_ids
* @property string|null $optional_recurring_product_ids
* @property \App\Models\Company $company
* @property-read \App\Models\Company $company
* @property-read mixed $hashed_id
* @property-read \App\Models\GroupSetting|null $group_settings
* @property-read \App\Models\User $user
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Database\Factories\SubscriptionFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Subscription filter(\App\Filters\QueryFilters $filters)

View File

@ -39,7 +39,7 @@ class PaymentIntentPartiallyFundedWebhook implements ShouldQueue
{
MultiDB::findAndSetDbByCompanyKey($this->company_key);
$company = Company::where('company_key', $this->company_key)->first();
$company = Company::query()->where('company_key', $this->company_key)->first();
foreach ($this->stripe_request as $transaction) {
$payment_intent = false;
@ -65,7 +65,7 @@ class PaymentIntentPartiallyFundedWebhook implements ShouldQueue
nlog("paymentintent found but no payment");
}
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$stripe_driver = $company_gateway->driver()->init();
$hash = isset($transaction['metadata']['payment_hash']) ? $transaction['metadata']['payment_hash'] : false;

View File

@ -57,17 +57,15 @@ class PaymentIntentProcessingWebhook implements ShouldQueue
{
MultiDB::findAndSetDbByCompanyKey($this->company_key);
$company = Company::where('company_key', $this->company_key)->first();
$company = Company::query()->where('company_key', $this->company_key)->first();
foreach ($this->stripe_request as $transaction) {
if (array_key_exists('payment_intent', $transaction)) {
/** @var \App\Models\Payment $payment **/
$payment = Payment::query()
->where('company_id', $company->id)
->where('transaction_reference', $transaction['payment_intent'])
->first();
} else {
/** @var \App\Models\Payment $payment **/
$payment = Payment::query()
->where('company_id', $company->id)
->where('transaction_reference', $transaction['id'])
@ -97,8 +95,7 @@ class PaymentIntentProcessingWebhook implements ShouldQueue
if ($this->payment_completed) {
return;
}
/** @var \App\Models\CompanyGateway $company_gateway **/
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$stripe_driver = $company_gateway->driver()->init();
$charge_id = false;
@ -126,10 +123,8 @@ class PaymentIntentProcessingWebhook implements ShouldQueue
return;
}
/** @var \App\Models\Company $company **/
$company = Company::where('company_key', $this->company_key)->first();
$company = Company::query()->where('company_key', $this->company_key)->first();
/** @var \App\Models\Payment $payment **/
$payment = Payment::query()
->where('company_id', $company->id)
->where('transaction_reference', $charge['id'])
@ -189,7 +184,7 @@ class PaymentIntentProcessingWebhook implements ShouldQueue
private function updateAchPayment($payment_hash, $client, $meta)
{
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$payment_method_type = $meta['gateway_type_id'];
$driver = $company_gateway->driver($client)->init()->setPaymentMethod($payment_method_type);

View File

@ -56,7 +56,7 @@ class PaymentIntentWebhook implements ShouldQueue
{
MultiDB::findAndSetDbByCompanyKey($this->company_key);
$company = Company::where('company_key', $this->company_key)->first();
$company = Company::query()->where('company_key', $this->company_key)->first();
foreach ($this->stripe_request as $transaction) {
if (array_key_exists('payment_intent', $transaction)) {
@ -84,7 +84,7 @@ class PaymentIntentWebhook implements ShouldQueue
return;
}
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$stripe_driver = $company_gateway->driver()->init();
$charge_id = false;
@ -196,7 +196,7 @@ class PaymentIntentWebhook implements ShouldQueue
private function updateAchPayment($payment_hash, $client, $meta)
{
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$payment_method_type = $meta['gateway_type_id'];
$driver = $company_gateway->driver($client)->init()->setPaymentMethod($payment_method_type);
@ -267,7 +267,7 @@ class PaymentIntentWebhook implements ShouldQueue
private function updateCreditCardPayment($payment_hash, $client, $meta)
{
$company_gateway = CompanyGateway::find($this->company_gateway_id);
$company_gateway = CompanyGateway::query()->find($this->company_gateway_id);
$payment_method_type = $meta['gateway_type_id'];
$driver = $company_gateway->driver($client)->init()->setPaymentMethod($payment_method_type);

View File

@ -90,7 +90,7 @@ class UpdatePaymentMethods
);
foreach ($bank_methods->data as $method) {
$token = ClientGatewayToken::where([
$token = ClientGatewayToken::query()->where([
'gateway_customer_reference' => $customer->id,
'token' => $method->id,
'client_id' => $client->id,
@ -140,7 +140,7 @@ class UpdatePaymentMethods
}
foreach ($sources->data as $method) {
$token_exists = ClientGatewayToken::where([
$token_exists = ClientGatewayToken::query()->where([
'gateway_customer_reference' => $customer->id,
'token' => $method->id,
'client_id' => $client->id,
@ -176,7 +176,7 @@ class UpdatePaymentMethods
private function addOrUpdateCard(PaymentMethod $method, $customer_reference, Client $client, $type_id)
{
$token_exists = ClientGatewayToken::where([
$token_exists = ClientGatewayToken::query()->where([
'gateway_customer_reference' => $customer_reference,
'token' => $method->id,
'client_id' => $client->id,

View File

@ -501,7 +501,8 @@ class StripePaymentDriver extends BaseDriver
$this->init();
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)
$client_gateway_token = ClientGatewayToken::query()
->whereClientId($this->client->id)
->whereCompanyGatewayId($this->company_gateway->id)
->first();
@ -892,7 +893,7 @@ class StripePaymentDriver extends BaseDriver
public function setClientFromCustomer($customer)
{
$this->client = ClientGatewayToken::where('gateway_customer_reference', $customer)->client;
$this->client = ClientGatewayToken::query()->where('gateway_customer_reference', $customer)->client;
}
/**

View File

@ -25,7 +25,7 @@ class PaymentMethod
private $amount;
/** @var \Illuminate\Support\Collection<CompanyGateway> $gateways */
/** @var \Illuminate\Support\Collection<CompanyGateway> $gateways **/
private $gateways;
private $payment_methods;

View File

@ -13,6 +13,7 @@ namespace App\Transformers;
use App\Models\Account;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Utils\Traits\MakesHash;
use App\Transformers\EntityTransformer;

View File

@ -94,11 +94,14 @@ class UserTransformer extends EntityTransformer
return $this->includeCollection($user->company_users, $transformer, CompanyUser::class);
}
/**
*
* @param User $user
*/
public function includeCompanyUser(User $user)
{
if (! $user->company_id && request()->header('X-API-TOKEN')) {
$company_token = CompanyToken::where('token', request()->header('X-API-TOKEN'))->first();
/** @var \App\Models\User $user */
$company_token = CompanyToken::query()->where('token', request()->header('X-API-TOKEN'))->first();
$user->company_id = $company_token->company_id;
}