From 0792638e9073be35f10191b0df24148e352376dd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 1 Aug 2023 23:28:30 +1000 Subject: [PATCH] Static analysis cleanup --- app/DataMapper/FeesAndLimits.php | 28 +++++++------- .../Migration/UploadMigrationFileRequest.php | 6 ++- .../Requests/Payment/RefundPaymentRequest.php | 4 +- .../Payment/ValidRefundableRequest.php | 9 ++--- app/Models/BaseModel.php | 37 ++++++++++--------- app/Models/Invoice.php | 2 + app/Models/Payment.php | 1 + phpstan.neon | 2 +- 8 files changed, 47 insertions(+), 42 deletions(-) diff --git a/app/DataMapper/FeesAndLimits.php b/app/DataMapper/FeesAndLimits.php index eda9f4b300..a790de9db7 100644 --- a/app/DataMapper/FeesAndLimits.php +++ b/app/DataMapper/FeesAndLimits.php @@ -13,35 +13,35 @@ namespace App\DataMapper; class FeesAndLimits { - public $min_limit = -1; //equivalent to null + public float $min_limit = -1; //equivalent to null - public $max_limit = -1; //equivalent to null + public float $max_limit = -1; //equivalent to null - public $fee_amount = 0; + public float $fee_amount = 0; - public $fee_percent = 0; + public float $fee_percent = 0; - public $fee_tax_name1 = ''; + public string $fee_tax_name1 = ''; - public $fee_tax_name2 = ''; + public string $fee_tax_name2 = ''; - public $fee_tax_name3 = ''; + public string $fee_tax_name3 = ''; - public $fee_tax_rate1 = 0; + public float $fee_tax_rate1 = 0; - public $fee_tax_rate2 = 0; + public float $fee_tax_rate2 = 0; - public $fee_tax_rate3 = 0; + public float $fee_tax_rate3 = 0; - public $fee_cap = 0; + public float $fee_cap = 0; - public $adjust_fee_percent = false; + public bool $adjust_fee_percent = false; - public $is_enabled = true; + public bool $is_enabled = true; //public $gateway_type_id = 1; - public static $casts = [ + public static array $casts = [ 'is_enabled' => 'bool', 'gateway_type_id' => 'int', 'min_limit' => 'float', diff --git a/app/Http/Requests/Migration/UploadMigrationFileRequest.php b/app/Http/Requests/Migration/UploadMigrationFileRequest.php index b0d72dfe7d..a67614f15a 100644 --- a/app/Http/Requests/Migration/UploadMigrationFileRequest.php +++ b/app/Http/Requests/Migration/UploadMigrationFileRequest.php @@ -22,7 +22,9 @@ class UploadMigrationFileRequest extends Request */ public function authorize() { - return auth()->user()->isAdmin(); + /** @var \App\Models\User $user */ + $user = auth()->user(); + return $user->isAdmin(); } /** @@ -30,7 +32,7 @@ class UploadMigrationFileRequest extends Request * * @return array */ - public function rules() + public function rules(): array { $rules = [ 'migration' => [], diff --git a/app/Http/Requests/Payment/RefundPaymentRequest.php b/app/Http/Requests/Payment/RefundPaymentRequest.php index 5ee4d0614b..5f0a8381d5 100644 --- a/app/Http/Requests/Payment/RefundPaymentRequest.php +++ b/app/Http/Requests/Payment/RefundPaymentRequest.php @@ -64,12 +64,12 @@ class RefundPaymentRequest extends Request $this->replace($input); } - public function rules() + public function rules(): array { $input = $this->all(); $rules = [ - 'id' => 'bail|required', + 'id' => 'bail|required', //@phpstan-ignore-line 'id' => new ValidRefundableRequest($input), 'amount' => 'numeric', 'date' => 'required', diff --git a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php index 752889a370..db2f8ad2e1 100644 --- a/app/Http/ValidationRules/Payment/ValidRefundableRequest.php +++ b/app/Http/ValidationRules/Payment/ValidRefundableRequest.php @@ -46,8 +46,8 @@ class ValidRefundableRequest implements Rule return false; } - /**@var \App\Models\Payment $payment */ - $payment = Payment::whereId($this->input['id'])->withTrashed()->first(); + /**@var \App\Models\Payment $payment **/ + $payment = Payment::where('id', $this->input['id'])->withTrashed()->first(); if (! $payment) { $this->error_msg = ctrans('texts.unable_to_retrieve_payment'); @@ -56,7 +56,6 @@ class ValidRefundableRequest implements Rule } $request_invoices = request()->has('invoices') ? $this->input['invoices'] : []; - // $request_credits = request()->has('credits') ? $this->input['credits'] : []; if ($payment->invoices()->exists()) { foreach ($payment->invoices as $paymentable_invoice) { @@ -77,8 +76,8 @@ class ValidRefundableRequest implements Rule private function checkInvoiceIsPaymentable($invoice, $payment) { - /**@var \App\Models\Invoice $invoice */ - $invoice = Invoice::whereId($invoice['invoice_id'])->whereCompanyId($payment->company_id)->withTrashed()->first(); + /**@var \App\Models\Invoice $invoice **/ + $invoice = Invoice::where('id', $invoice['invoice_id'])->where('company_id', $payment->company_id)->withTrashed()->first(); if (! $invoice) { $this->error_msg = 'Invoice not found for refund'; diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index e720c89a6b..f50ecb81ca 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -35,25 +35,26 @@ use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundExceptio * @property \App\Models\Company $company * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\HasMany|BaseModel orderBy() - * @method static \Illuminate\Database\Eloquent\Builder exclude($columns) - * @method static \Illuminate\Database\Eloquent\Builder company() - * @method static \Illuminate\Database\Eloquent\Builder with($value) - * @method static \Illuminate\Database\Eloquent\Builder newModelQuery($query) - * @method static \Illuminate\Database\Eloquent\Builder newQuery($query) - * @method static \Illuminate\Database\Eloquent\Builder query() - * @method static \Illuminate\Database\Eloquent\Builder exclude(array $excludeable) - * @method static \Illuminate\Database\Eloquent\Builder withTrashed() - * @method static \Illuminate\Database\Eloquent\Builder scopeExclude($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel with($value) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel query() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude(array $excludeable) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel scopeExclude($query) * @method static BaseModel find($value) - * @method static \Illuminate\Database\Eloquent\Builder whereIn($query) - * @method static \Illuminate\Database\Eloquent\Builder where($query) - * @method static \Illuminate\Database\Eloquent\Builder count() - * @method static \Illuminate\Database\Eloquent\Builder create($query) - * @method static \Illuminate\Database\Eloquent\Builder insert($query) - * @method static \Illuminate\Database\Eloquent\Builder service() - * @method static \Illuminate\Database\Eloquent\Builder orderBy($column, $direction) - * @method static \Illuminate\Database\Eloquent\Builder invitations() - * @method static \Illuminate\Database\Eloquent\Builder whereHas($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereId($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereIn($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel where($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel count() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel create($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel insert($query) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel service() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel orderBy($column, $direction) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel invitations() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereHas($query) * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read int|null $invitations_count * diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index b0fd235a2a..812539485d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -132,6 +132,8 @@ use App\Events\Invoice\InvoiceReminderWasEmailed; * @property-read \Illuminate\Database\Eloquent\Collection $payments * @property-read \Illuminate\Database\Eloquent\Collection $tasks * @property object|null $tax_data + * @method static \Illuminate\Database\Eloquent\Builder company() + * @method static \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true) * @mixin \Eloquent */ class Invoice extends BaseModel diff --git a/app/Models/Payment.php b/app/Models/Payment.php index e60b4ec726..3685462831 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -92,6 +92,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $invoices * @property-read \Illuminate\Database\Eloquent\Collection $paymentables + * @method static \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true) * @mixin \Eloquent */ class Payment extends BaseModel diff --git a/phpstan.neon b/phpstan.neon index dba885569b..6e4f01ab20 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ includes: - ./vendor/nunomaduro/larastan/extension.neon parameters: - level: 4 + level: 2 paths: - 'app/' excludePaths: