From 6e64a9c74aec782a42cba83048efcdb652ea4ebc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Aug 2023 19:44:52 +1000 Subject: [PATCH] Static Analysis Cleanup --- app/Http/Livewire/BillingPortalPurchase.php | 2 +- app/Jobs/Bank/MatchBankTransactions.php | 2 +- app/Models/CompanyGateway.php | 10 +++++----- app/Models/PurchaseOrder.php | 16 ++++++++-------- app/Models/Subscription.php | 5 +++-- app/PaymentDrivers/WePay/ACH.php | 2 +- app/Repositories/UserRepository.php | 2 +- app/Services/Bank/ProcessBankRules.php | 5 +++-- app/Services/Client/PaymentMethod.php | 9 ++++++--- app/Services/ClientPortal/InstantPayment.php | 4 ++-- .../Invoice/EInvoice/FacturaEInvoice.php | 1 + app/Services/Preview/StubBuilder.php | 5 +++-- app/Services/Report/ProfitLoss.php | 2 +- .../Subscription/SubscriptionService.php | 12 ++++++------ app/Transformers/ActivityTransformer.php | 18 +++++++++++++----- .../BankIntegrationTransformer.php | 1 + .../BankTransactionRuleTransformer.php | 2 +- .../BankTransactionTransformer.php | 4 +++- 18 files changed, 60 insertions(+), 42 deletions(-) diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 6c0415bfe2f5..9a7fae37b9ca 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -155,7 +155,7 @@ class BillingPortalPurchase extends Component public $request_data; /** - * @var string + * @var float */ public $price; diff --git a/app/Jobs/Bank/MatchBankTransactions.php b/app/Jobs/Bank/MatchBankTransactions.php index 164dede3a0b3..a65b142cdaf3 100644 --- a/app/Jobs/Bank/MatchBankTransactions.php +++ b/app/Jobs/Bank/MatchBankTransactions.php @@ -400,7 +400,7 @@ class MatchBankTransactions implements ShouldQueue $category = $this->categories->firstWhere('highLevelCategoryId', $this->bt->category_id); - $ec = ExpenseCategory::where('company_id', $this->bt->company_id)->where('bank_category_id', $this->bt->category_id)->first(); + $ec = ExpenseCategory::query()->where('company_id', $this->bt->company_id)->where('bank_category_id', $this->bt->category_id)->first(); if ($ec) { return $ec->id; diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 0ad3651ec11a..446d3022c8fe 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -167,17 +167,17 @@ class CompanyGateway extends BaseModel ->take(50); } - public function company() + public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Company::class); } - public function client_gateway_tokens() + public function client_gateway_tokens(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(ClientGatewayToken::class); } - public function gateway() + public function gateway(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Gateway::class, 'gateway_key', 'key'); } @@ -190,8 +190,8 @@ class CompanyGateway extends BaseModel /* This is the public entry point into the payment superclass */ public function driver(Client $client = null) { -// $class = static::driver_class(); -$class = self::driver_class(); + // $class = static::driver_class(); + $class = self::driver_class(); if (!$class) { return false; diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index a3a97f65b069..932d2ba9b935 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -50,12 +50,12 @@ use Illuminate\Support\Facades\Storage; * @property string|null $private_notes * @property string|null $terms * @property string|null $tax_name1 - * @property string $tax_rate1 + * @property float $tax_rate1 * @property string|null $tax_name2 - * @property string $tax_rate2 + * @property float $tax_rate2 * @property string|null $tax_name3 - * @property string $tax_rate3 - * @property string $total_taxes + * @property float $tax_rate3 + * @property float $total_taxes * @property int $uses_inclusive_taxes * @property string|null $reminder1_sent * @property string|null $reminder2_sent @@ -74,11 +74,11 @@ use Illuminate\Support\Facades\Storage; * @property int $custom_surcharge_tax2 * @property int $custom_surcharge_tax3 * @property int $custom_surcharge_tax4 - * @property string $exchange_rate - * @property string $balance + * @property float $exchange_rate + * @property float $balance * @property float|null $partial - * @property string $amount - * @property string $paid_to_date + * @property float $amount + * @property float $paid_to_date * @property string|null $partial_due_date * @property string|null $last_viewed * @property int|null $deleted_at diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index ea3cfcb49c8f..0ec9613ddc36 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -47,8 +47,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string|null $recurring_product_ids * @property string $name * @property int|null $group_id - * @property string $price - * @property string $promo_price + * @property float $price + * @property float $promo_price * @property int $registration_required * @property int $use_inventory_management * @property string|null $optional_product_ids @@ -68,6 +68,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope() * @method static \Illuminate\Database\Eloquent\Builder|Subscription withTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Subscription withoutTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|Subscription with($value) * @mixin \Eloquent */ class Subscription extends BaseModel diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index 7143bda330a0..945924ffc341 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -201,7 +201,7 @@ class ACH public function paymentResponse($request) { - $token = ClientGatewayToken::find($this->decodePrimaryKey($request->input('source'))); + $token = ClientGatewayToken::query()->find($this->decodePrimaryKey($request->input('source'))); $token_meta = $token->meta; if (! property_exists($token_meta, 'state') || $token_meta->state != 'authorized') { diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 582812b74daf..287d2d156a16 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -137,7 +137,7 @@ class UserRepository extends BaseRepository $cu->forceDelete(); } - event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event(new UserWasDeleted($user, auth()->user(), auth()->user()->company(), Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); $user->delete(); diff --git a/app/Services/Bank/ProcessBankRules.php b/app/Services/Bank/ProcessBankRules.php index fa9a9f6a8c53..f5dd8a9f9ab7 100644 --- a/app/Services/Bank/ProcessBankRules.php +++ b/app/Services/Bank/ProcessBankRules.php @@ -33,6 +33,9 @@ class ProcessBankRules extends AbstractService protected $invoices; + /** + * @param \App\Models\BankTransaction $bank_transaction + */ public function __construct(public BankTransaction $bank_transaction) { } @@ -48,14 +51,12 @@ class ProcessBankRules extends AbstractService private function matchCredit() { - /** @var \Illuminate\Database\Eloquent\Collection $this->invoices */ $this->invoices = Invoice::query()->where('company_id', $this->bank_transaction->company_id) ->whereIn('status_id', [1,2,3]) ->where('is_deleted', 0) ->get(); $invoice = $this->invoices->first(function ($value, $key) { - /** @var \App\Models\Invoice $value */ return str_contains($this->bank_transaction->description, $value->number); }); diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index 4c7d4517d44a..6b5bdd5eeee9 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -25,6 +25,7 @@ class PaymentMethod private $amount; + /** @var \Illuminate\Support\Collection $gateways */ private $gateways; private $payment_methods; @@ -78,7 +79,8 @@ class PaymentMethod return array_search($model->id, $transformed_ids); // this closure sorts for us }); } else { - $this->gateways = CompanyGateway::with('gateway') + $this->gateways = CompanyGateway::query() + ->with('gateway') ->where('company_id', $this->client->company_id) ->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa') ->whereNull('deleted_at') @@ -112,7 +114,8 @@ class PaymentMethod return array_search($model->id, $transformed_ids); // this closure sorts for us }); } else { - $this->gateways = CompanyGateway::with('gateway') + $this->gateways = CompanyGateway::query() + ->with('gateway') ->where('company_id', $this->client->company_id) ->where('gateway_key', '54faab2ab6e3223dbe848b1686490baa') ->whereNull('deleted_at') @@ -171,7 +174,7 @@ class PaymentMethod { foreach ($this->payment_methods as $key => $child_array) { foreach ($child_array as $gateway_id => $gateway_type_id) { - $gateway = CompanyGateway::find($gateway_id); + $gateway = CompanyGateway::query()->find($gateway_id); $fee_label = $gateway->calcGatewayFeeLabel($this->amount, $this->client, $gateway_type_id); diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index a23dd2ee4d13..909e4f003a3d 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -100,7 +100,7 @@ class InstantPayment * Determine the payable amount and the max payable. ie either partial or invoice balance */ - $payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount'], $client->currency()->precision)); + $payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount']), $client->currency()->precision); $invoice_balance = Number::roundValue(($invoice->partial > 0 ? $invoice->partial : $invoice->balance), $client->currency()->precision); @@ -155,7 +155,7 @@ class InstantPayment return $payable_invoice['invoice_id'] == $inv->hashed_id; }); - $payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount'], $client->currency()->precision)); + $payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount']), $client->currency()->precision); $invoice_balance = Number::roundValue($invoice->balance, $client->currency()->precision); $payable_invoice['due_date'] = $this->formatDate($invoice->due_date, $invoice->client->date_format()); diff --git a/app/Services/Invoice/EInvoice/FacturaEInvoice.php b/app/Services/Invoice/EInvoice/FacturaEInvoice.php index 7d109e21a618..12be24138c9e 100644 --- a/app/Services/Invoice/EInvoice/FacturaEInvoice.php +++ b/app/Services/Invoice/EInvoice/FacturaEInvoice.php @@ -302,6 +302,7 @@ class FacturaEInvoice extends AbstractService private function resolvePaymentMethod(\App\Models\Payment $payment): array { $data = []; + $method = FacturaePayment::TYPE_CARD; match($payment->type_id){ PaymentType::BANK_TRANSFER => $method = FacturaePayment::TYPE_TRANSFER , diff --git a/app/Services/Preview/StubBuilder.php b/app/Services/Preview/StubBuilder.php index 3755f077e742..4bf2eafcca47 100644 --- a/app/Services/Preview/StubBuilder.php +++ b/app/Services/Preview/StubBuilder.php @@ -42,7 +42,8 @@ class StubBuilder public $entity_type; - public \App\Models\Client | \App\Models\Vendor $recipient; + /** @var Client | Vendor $recipient **/ + public Client | Vendor $recipient; public mixed $contact; @@ -178,7 +179,7 @@ class StubBuilder $design_string = "{$this->entity_type}_design_id"; - $design = DesignModel::withTrashed()->find($this->decodePrimaryKey($html->settings->{$design_string})); + $design = DesignModel::query()->withTrashed()->find($this->decodePrimaryKey($html->settings->{$design_string})); $template = new PdfMakerDesign(strtolower($design->name)); diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index 56bf7ae7b55e..12b19f6488f7 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -293,7 +293,7 @@ class ProfitLoss foreach ($payment->paymentables as $pivot) { if ($pivot->paymentable_type == 'invoices') { - $invoice = Invoice::withTrashed()->find($pivot->paymentable_id); + $invoice = Invoice::query()->withTrashed()->find($pivot->paymentable_id); $amount_payment_paid += $pivot->amount - $pivot->refunded; $amount_payment_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 0e0ae3891bb9..0b36900c312d 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -213,7 +213,7 @@ class SubscriptionService $email_object->body = ctrans('texts.white_label_body', ['license_key' => $license_key]); $email_object->client_id = $invoice->client_id; $email_object->client_contact_id = $contact->id; - $email_object->invitation_key = $invitation->invitation_key; + $email_object->invitation_key = $invitation->key; $email_object->invitation_id = $invitation->id; $email_object->entity_id = $invoice->id; $email_object->entity_class = Invoice::class; @@ -676,7 +676,7 @@ class SubscriptionService $pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription); } elseif ($last_invoice->balance > 0) { - $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription); + $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice); nlog("pro rata charge = {$pro_rata_charge_amount}"); } else { $pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription) * -1; @@ -740,7 +740,7 @@ class SubscriptionService } if ($last_invoice->balance > 0) { - $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription); + $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice); nlog("pro rata charge = {$pro_rata_charge_amount}"); } else { $pro_rata_refund_amount = $this->calculateProRataRefund($last_invoice, $old_subscription) * -1; @@ -807,7 +807,7 @@ class SubscriptionService { nlog("handle plan change"); - $old_recurring_invoice = RecurringInvoice::find($this->decodePrimaryKey($payment_hash->data->billing_context->recurring_invoice)); + $old_recurring_invoice = RecurringInvoice::query()->find($this->decodePrimaryKey($payment_hash->data->billing_context->recurring_invoice)); if (!$old_recurring_invoice) { return $this->handleRedirect('/client/recurring_invoices/'); @@ -816,7 +816,7 @@ class SubscriptionService $recurring_invoice = $this->createNewRecurringInvoice($old_recurring_invoice); //update the invoice and attach to the recurring invoice!!!!! - $invoice = Invoice::find($payment_hash->fee_invoice_id); + $invoice = Invoice::query()->find($payment_hash->fee_invoice_id); $invoice->recurring_id = $recurring_invoice->id; $invoice->is_proforma = false; $invoice->save(); @@ -1243,7 +1243,7 @@ class SubscriptionService /** * Get available upgrades & downgrades for the plan. * - * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection + * @return \Illuminate\Database\Eloquent\Collection */ public function getPlans() { diff --git a/app/Transformers/ActivityTransformer.php b/app/Transformers/ActivityTransformer.php index 9bcf5b66dd63..77c3cebe6ae3 100644 --- a/app/Transformers/ActivityTransformer.php +++ b/app/Transformers/ActivityTransformer.php @@ -11,16 +11,24 @@ namespace App\Transformers; -use App\Models\Activity; -use App\Models\Backup; -use App\Models\ClientContact; -use App\Models\Invoice; -use App\Models\PurchaseOrder; use App\Models\Task; use App\Models\User; +use App\Models\Quote; +use App\Models\Backup; +use App\Models\Client; +use App\Models\Credit; use App\Models\Vendor; +use App\Models\Expense; +use App\Models\Invoice; +use App\Models\Payment; +use App\Models\Activity; +use App\Models\ClientContact; +use App\Models\PurchaseOrder; use App\Models\VendorContact; use App\Utils\Traits\MakesHash; +use App\Models\RecurringInvoice; +use App\Transformers\EntityTransformer; +use App\Transformers\InvoiceHistoryTransformer; class ActivityTransformer extends EntityTransformer { diff --git a/app/Transformers/BankIntegrationTransformer.php b/app/Transformers/BankIntegrationTransformer.php index b5eeb0ebea3c..4e71bd5f99f5 100644 --- a/app/Transformers/BankIntegrationTransformer.php +++ b/app/Transformers/BankIntegrationTransformer.php @@ -14,6 +14,7 @@ namespace App\Transformers; use App\Models\Account; use App\Models\BankIntegration; use App\Utils\Traits\MakesHash; +use App\Transformers\EntityTransformer; /** * Class BankIntegrationTransformer. diff --git a/app/Transformers/BankTransactionRuleTransformer.php b/app/Transformers/BankTransactionRuleTransformer.php index 588a802b492e..4d410c1b3bd9 100644 --- a/app/Transformers/BankTransactionRuleTransformer.php +++ b/app/Transformers/BankTransactionRuleTransformer.php @@ -43,7 +43,7 @@ class BankTransactionRuleTransformer extends EntityTransformer ]; /** - * @param BankTransaction $bank_integration + * @param BankTransactionRule $bank_transaction_rule * @return array */ public function transform(BankTransactionRule $bank_transaction_rule) diff --git a/app/Transformers/BankTransactionTransformer.php b/app/Transformers/BankTransactionTransformer.php index 5d941dbefe68..2a1c15f9e642 100644 --- a/app/Transformers/BankTransactionTransformer.php +++ b/app/Transformers/BankTransactionTransformer.php @@ -11,9 +11,11 @@ namespace App\Transformers; -use App\Models\BankTransaction; +use App\Models\Vendor; use App\Models\Company; use App\Models\Expense; +use App\Models\Payment; +use App\Models\BankTransaction; use App\Utils\Traits\MakesHash; /**