Skip to content

Commit

Permalink
Fix even more type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yungifez committed Apr 10, 2023
1 parent d181db3 commit 4da2f68
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 63 deletions.
2 changes: 1 addition & 1 deletion app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EncryptCookies extends Middleware
/**
* The names of the cookies that should not be encrypted.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PreventRequestsDuringMaintenance extends Middleware
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class VerifyCsrfToken extends Middleware
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
* @var array<int, string>
*/
protected $except = [
//
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/SchoolSetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function authorize()
if (auth()->user()->hasRole('super-admin')) {
return true;
}

return false;
}

/**
Expand Down
6 changes: 0 additions & 6 deletions app/Http/Requests/UpdateExamStatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 2 additions & 0 deletions app/Models/AcademicYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AcademicYear extends Model

public $name;

public AcademicYearStudentRecord $studentAcademicYearBasedRecords;

protected $fillable = [
'start_year',
'stop_year',
Expand Down
5 changes: 2 additions & 3 deletions app/Models/AccountApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Exam extends Model
/**
* The attributes that should be cast.
*
* @var array
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
Expand Down
8 changes: 2 additions & 6 deletions app/Models/MyClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 6 additions & 5 deletions app/Models/Promotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/StudentRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class StudentRecord extends Model
/**
* The attributes that should be cast.
*
* @var array
* @var array<string, string>
*/
protected $casts = [
'admission_date' => 'datetime:Y-m-d',
Expand Down
13 changes: 6 additions & 7 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +53,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The attributes that should be hidden for serialization.
*
* @var array
* @var array<int, string>
*/
protected $hidden = [
'password',
Expand All @@ -64,7 +65,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The attributes that should be cast.
*
* @var array
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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);
}
Expand Down
26 changes: 12 additions & 14 deletions app/Services/Fee/FeeInvoiceRecordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -26,24 +24,24 @@ 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;
}

/**
* Update a fee invoice record.
*
* @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'));
Expand All @@ -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();
}
Expand All @@ -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;
Expand All @@ -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);

Expand Down
9 changes: 4 additions & 5 deletions app/Services/Parent/ParentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
}
Expand Down
7 changes: 3 additions & 4 deletions app/Services/User/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}
Expand Down
5 changes: 1 addition & 4 deletions app/Traits/EnvEditorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions app/Traits/InSchool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
# Level 9 is the highest level
level: 5


# ignoreErrors:
# - '#PHPDoc tag @var#'
#
Expand Down

0 comments on commit 4da2f68

Please sign in to comment.