From 4da2f68195b30abc2dfe8a8a74cbcdf8c8445358 Mon Sep 17 00:00:00 2001 From: yungifez Date: Mon, 10 Apr 2023 14:38:57 +0000 Subject: [PATCH] Fix even more type errors --- app/Http/Middleware/EncryptCookies.php | 2 +- .../PreventRequestsDuringMaintenance.php | 2 +- app/Http/Middleware/VerifyCsrfToken.php | 2 +- app/Http/Requests/SchoolSetRequest.php | 2 ++ app/Http/Requests/UpdateExamStatusRequest.php | 6 ----- app/Models/AcademicYear.php | 2 ++ app/Models/AccountApplication.php | 5 ++-- app/Models/Exam.php | 2 +- app/Models/MyClass.php | 8 ++---- app/Models/Promotion.php | 11 ++++---- app/Models/StudentRecord.php | 2 +- app/Models/User.php | 13 +++++----- app/Services/Fee/FeeInvoiceRecordService.php | 26 +++++++++---------- app/Services/Parent/ParentService.php | 9 +++---- app/Services/User/UserService.php | 7 +++-- app/Traits/EnvEditorTrait.php | 5 +--- app/Traits/InSchool.php | 7 +++-- phpstan.neon | 1 + 18 files changed, 49 insertions(+), 63 deletions(-) diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index 033136ad..867695bd 100755 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -9,7 +9,7 @@ class EncryptCookies extends Middleware /** * The names of the cookies that should not be encrypted. * - * @var array + * @var array */ protected $except = [ // diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php index e4956d0b..74cbd9a9 100755 --- a/app/Http/Middleware/PreventRequestsDuringMaintenance.php +++ b/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -9,7 +9,7 @@ class PreventRequestsDuringMaintenance extends Middleware /** * The URIs that should be reachable while maintenance mode is enabled. * - * @var array + * @var array */ protected $except = [ // diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 0c13b854..9e865217 100755 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -9,7 +9,7 @@ class VerifyCsrfToken extends Middleware /** * The URIs that should be excluded from CSRF verification. * - * @var array + * @var array */ protected $except = [ // diff --git a/app/Http/Requests/SchoolSetRequest.php b/app/Http/Requests/SchoolSetRequest.php index e3febca7..6b01f202 100755 --- a/app/Http/Requests/SchoolSetRequest.php +++ b/app/Http/Requests/SchoolSetRequest.php @@ -16,6 +16,8 @@ public function authorize() if (auth()->user()->hasRole('super-admin')) { return true; } + + return false; } /** diff --git a/app/Http/Requests/UpdateExamStatusRequest.php b/app/Http/Requests/UpdateExamStatusRequest.php index 579913c3..ddfd504f 100755 --- a/app/Http/Requests/UpdateExamStatusRequest.php +++ b/app/Http/Requests/UpdateExamStatusRequest.php @@ -6,13 +6,7 @@ class UpdateExamStatusRequest extends FormRequest { - /** - * Determine if the user is authorized to make this request. - * - * @return bool - */ - //prepare attribute for validation protected function prepareForValidation() { if ($this->status == 'active' || $this->status == 1 || $this->status == 'on') { diff --git a/app/Models/AcademicYear.php b/app/Models/AcademicYear.php index e9ca1dea..0c49ce9b 100755 --- a/app/Models/AcademicYear.php +++ b/app/Models/AcademicYear.php @@ -16,6 +16,8 @@ class AcademicYear extends Model public $name; + public AcademicYearStudentRecord $studentAcademicYearBasedRecords; + protected $fillable = [ 'start_year', 'stop_year', diff --git a/app/Models/AccountApplication.php b/app/Models/AccountApplication.php index 8243b325..73c412ad 100644 --- a/app/Models/AccountApplication.php +++ b/app/Models/AccountApplication.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Collection; use Spatie\ModelStatus\HasStatuses; use Spatie\Permission\Models\Role; @@ -33,10 +34,8 @@ public function role(): BelongsTo /** * Possible account application statuses. - * - * @return void */ - public function getAllStatuses() + public function getAllStatuses() : Collection { return collect(['approved', 'rejected', 'under review', 'user action required']); } diff --git a/app/Models/Exam.php b/app/Models/Exam.php index 14b5b0d9..b4a1d78d 100755 --- a/app/Models/Exam.php +++ b/app/Models/Exam.php @@ -24,7 +24,7 @@ class Exam extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', diff --git a/app/Models/MyClass.php b/app/Models/MyClass.php index f6951c27..d7cb2412 100755 --- a/app/Models/MyClass.php +++ b/app/Models/MyClass.php @@ -53,20 +53,16 @@ public function studentRecords() /** * The subjects that belong to the MyClass. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function subjects() + public function subjects() : HasMany { return $this->hasMany(Subject::class); } /** * Get the students in class. - * - * @return Collection */ - public function students() + public function students() : Collection { $students = User::students()->inSchool()->whereRelation('studentRecord.myClass', 'id', $this->id)->get(); diff --git a/app/Models/Promotion.php b/app/Models/Promotion.php index 837a1715..831e34eb 100755 --- a/app/Models/Promotion.php +++ b/app/Models/Promotion.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Promotion extends Model { @@ -28,27 +29,27 @@ public function getLabelAttribute() return "{$this->oldClass->name} - {$this->oldSection->name} to {$this->newClass->name} - {$this->newSection->name} year: {$this->academicYear->start_year} - {$this->academicYear->stop_year}"; } - public function oldClass() + public function oldClass() : BelongsTo { return $this->belongsTo(MyClass::class, 'old_class_id'); } - public function newClass() + public function newClass() : BelongsTo { return $this->belongsTo(MyClass::class, 'new_class_id'); } - public function oldSection() + public function oldSection() : BelongsTo { return $this->belongsTo(Section::class, 'old_section_id'); } - public function newSection() + public function newSection() : BelongsTo { return $this->belongsTo(Section::class, 'new_section_id'); } - public function academicYear() + public function academicYear() : BelongsTo { return $this->belongsTo(AcademicYear::class, 'academic_year_id'); } diff --git a/app/Models/StudentRecord.php b/app/Models/StudentRecord.php index 8860eee5..e9b159bf 100755 --- a/app/Models/StudentRecord.php +++ b/app/Models/StudentRecord.php @@ -17,7 +17,7 @@ class StudentRecord extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'admission_date' => 'datetime:Y-m-d', diff --git a/app/Models/User.php b/app/Models/User.php index 4b2ea173..b89b7798 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; @@ -52,7 +53,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * The attributes that should be hidden for serialization. * - * @var array + * @var array */ protected $hidden = [ 'password', @@ -64,7 +65,7 @@ class User extends Authenticatable implements MustVerifyEmail /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', @@ -94,9 +95,9 @@ public function scopeStudents($query) */ public function scopeApplicants($query) { - return $query->role('applicant')->whereHas('accountApplication', function (Builder $query) { + return $query->whereHas('accountApplication', function (Builder $query) { $query->otherCurrentStatus('rejected'); - }); + })->role('applicant'); } /** @@ -120,10 +121,8 @@ public function scopeActiveStudents($query) /** * Get the school that owns the User. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function school() + public function school() : BelongsTo { return $this->belongsTo(School::class); } diff --git a/app/Services/Fee/FeeInvoiceRecordService.php b/app/Services/Fee/FeeInvoiceRecordService.php index 97af3483..20001b02 100644 --- a/app/Services/Fee/FeeInvoiceRecordService.php +++ b/app/Services/Fee/FeeInvoiceRecordService.php @@ -14,10 +14,8 @@ class FeeInvoiceRecordService * Store a new fee invoice record. * * @param array $records - * - * @return $feeInvoiceRecord */ - public function storeFeeInvoiceRecord($records) + public function storeFeeInvoiceRecord($records) : FeeInvoiceRecord { $fee = Fee::where('id', $records['fee_id'])->whereRelation('feeCategory', 'school_id', auth()->user()->school_id)->get(); $feeInvoice = FeeInvoice::where('id', $records['fee_invoice_id'])->whereRelation('user', 'school_id', auth()->user()->school_id)->get(); @@ -26,13 +24,15 @@ public function storeFeeInvoiceRecord($records) throw new InvalidValueException("The fee you selected doesn't exist"); } - FeeInvoiceRecord::create([ + $feeInvoiceRecord = FeeInvoiceRecord::create([ 'fee_invoice_id' => $records['fee_invoice_id'], 'fee_id' => $records['fee_id'], 'amount' => $records['amount'], 'waiver' => $records['waiver'] ?? 0, 'fine' => $records['fine'] ?? 0, ]); + + return $feeInvoiceRecord; } /** @@ -40,10 +40,8 @@ public function storeFeeInvoiceRecord($records) * * @param FeeInvoiceRecord $feeInvoiceRecord * @param $records - * - * @return void */ - public function updateFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord, $records) + public function updateFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord, $records) : FeeInvoiceRecord { $amount = Money::ofMinor($records['amount'], config('app.currency')); $waiver = Money::ofMinor($records['waiver'] ?? 0, config('app.currency')); @@ -58,16 +56,16 @@ public function updateFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord, $reco 'waiver' => $records['waiver'] ?? 0, 'fine' => $records['fine'] ?? 0, ]); + + return $feeInvoiceRecord; } /** * Delete a fee invoice. * * @param FeeInvoiceRecord $feeInvoiceRecord - * - * @return void */ - public function deleteFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord) + public function deleteFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord) : void { $feeInvoiceRecord->delete(); } @@ -77,10 +75,8 @@ public function deleteFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord) * * @param FeeInvoiceRecord $feeInvoiceRecord * @param array $records - * - * @return void */ - public function addPayment(FeeInvoiceRecord $feeInvoiceRecord, $records) + public function addPayment(FeeInvoiceRecord $feeInvoiceRecord, $records) : FeeInvoiceRecord { $pay = Money::of($records['pay'], config('app.currency')); $paid = $feeInvoiceRecord->paid; @@ -93,9 +89,11 @@ public function addPayment(FeeInvoiceRecord $feeInvoiceRecord, $records) $feeInvoiceRecord->update([ 'paid' => $newAmount, ]); + + return $feeInvoiceRecord; } - public function isPaymentHigherThanDue(Money $amount, Money $paid, Money $waiver, Money $fine) + public function isPaymentHigherThanDue(Money $amount, Money $paid, Money $waiver, Money $fine) : bool { $due = $amount->plus($fine)->minus($waiver); diff --git a/app/Services/Parent/ParentService.php b/app/Services/Parent/ParentService.php index 0a4b1754..e9cafcaa 100755 --- a/app/Services/Parent/ParentService.php +++ b/app/Services/Parent/ParentService.php @@ -2,11 +2,12 @@ namespace App\Services\Parent; -use App\Exceptions\InvalidUserException; use App\Models\User; -use App\Services\Print\PrintService; use App\Services\User\UserService; use Illuminate\Support\Facades\DB; +use App\Services\Print\PrintService; +use App\Exceptions\InvalidUserException; +use Illuminate\Database\Eloquent\Collection; class ParentService { @@ -22,10 +23,8 @@ public function __construct(UserService $user) /** * Get all parents in school. - * - * @return Illuminate\Eloquent\Database\Collection|static[] */ - public function getAllParents() + public function getAllParents() : Collection|static { return $this->user->getUsersByRole('parent')->load('parentRecord'); } diff --git a/app/Services/User/UserService.php b/app/Services/User/UserService.php index fbe2e455..cc50d146 100755 --- a/app/Services/User/UserService.php +++ b/app/Services/User/UserService.php @@ -2,9 +2,10 @@ namespace App\Services\User; +use App\Models\User; use App\Actions\Fortify\CreateNewUser; +use Illuminate\Database\Eloquent\Collection; use App\Actions\Fortify\UpdateUserProfileInformation; -use App\Models\User; class UserService { @@ -26,10 +27,8 @@ public function __construct(CreateNewUser $createUserAction, UpdateUserProfileIn /** * Get all users. - * - * @return \Illuminate\Database\Eloquent\Collection|static[] */ - public function getAllUsers() + public function getAllUsers() : Collection|static { return User::school()->get(); } diff --git a/app/Traits/EnvEditorTrait.php b/app/Traits/EnvEditorTrait.php index 37816e56..56bc648d 100644 --- a/app/Traits/EnvEditorTrait.php +++ b/app/Traits/EnvEditorTrait.php @@ -9,11 +9,8 @@ trait EnvEditorTrait { /** * Write a new Env value to the env file the app is currently using. - * - * - * @return void */ - public function setEnvironmentValue(array $values) + public function setEnvironmentValue(array $values) : bool { $envFile = app()->environmentFilePath(); $str = file_get_contents($envFile); diff --git a/app/Traits/InSchool.php b/app/Traits/InSchool.php index c801acbf..141cf0f9 100644 --- a/app/Traits/InSchool.php +++ b/app/Traits/InSchool.php @@ -3,17 +3,16 @@ namespace App\Traits; use App\Models\School; +use Illuminate\Database\Eloquent\Builder; trait InSchool { /** * Scopes school procied else scopes school of currently authenticated user. * - * @param Illuminate\Database\Eloquent\Builder $query - * - * @return Illuminate\Database\Eloquent\Builder + * @param \Illuminate\Database\Eloquent\Builder $query */ - public function scopeInSchool($query, ?School $school = null) + public function scopeInSchool($query, ?School $school = null) : Builder { $school == null ? $school = auth()->user()->school_id : $school->id; diff --git a/phpstan.neon b/phpstan.neon index 6ce003e3..234f8a76 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,6 +9,7 @@ parameters: # Level 9 is the highest level level: 5 + # ignoreErrors: # - '#PHPDoc tag @var#' #