Skip to content

Commit

Permalink
[Debt] Upgrade Larastan to v3 (#12165)
Browse files Browse the repository at this point in the history
* bump larastan version

* add phpdoc for relationship types

* fix access of nullable properties

* fix misc errors

* fix relationship eager load

* add parent relationships

* add baseline ignore errors

* fix lint error

* revert morph to change
  • Loading branch information
esizer authored Dec 3, 2024
1 parent 2b895c8 commit fcabb77
Show file tree
Hide file tree
Showing 49 changed files with 366 additions and 240 deletions.
2 changes: 1 addition & 1 deletion api/app/Exceptions/ApiKeyNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ApiKeyNotFoundException extends Exception
/**
* Report the exception.
*
* @return bool|null
* @return void
*/
public function report()
{
Expand Down
2 changes: 1 addition & 1 deletion api/app/Exceptions/EmailAttachmentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EmailAttachmentException extends Exception
/**
* Report the exception.
*
* @return bool|null
* @return void
*/
public function report()
{
Expand Down
2 changes: 1 addition & 1 deletion api/app/Exceptions/InvalidBulkRowDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class InvalidBulkRowDataException extends Exception
/**
* Report the exception.
*
* @return bool|null
* @return void
*/
public function report()
{
Expand Down
2 changes: 1 addition & 1 deletion api/app/Exceptions/NotFutureDateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NotFutureDateException extends Exception
/**
* Report the exception.
*
* @return bool|null
* @return void
*/
public function report()
{
Expand Down
2 changes: 1 addition & 1 deletion api/app/Generators/ApplicationZipGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function generate(): self
{
PoolCandidate::with([
'educationRequirementExperiences',
'pool' => ['poolSkills' => ['skill']],
'pool' => ['poolSkills', 'poolSkills.skill'],
'screeningQuestionResponses' => ['screeningQuestion'],
'generalQuestionResponses' => ['generalQuestion'],
])
Expand Down
35 changes: 26 additions & 9 deletions api/app/Generators/PoolCandidateCsvGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
use App\Enums\PriorityWeight;
use App\Enums\ProvinceOrTerritory;
use App\Enums\WorkRegion;
use App\Models\GeneralQuestion;
use App\Models\Pool;
use App\Models\PoolCandidate;
use App\Models\ScreeningQuestion;
use App\Traits\Generator\Filterable;
use App\Traits\Generator\GeneratesFile;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Lang;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
Expand Down Expand Up @@ -307,12 +310,19 @@ public function generate(): self
*/
private function generatePoolHeaders()
{
Pool::with(['generalQuestions', 'screeningQuestions', 'poolSkills' => ['skill'], 'assessmentSteps' => ['poolSkills' => ['skill']]])
Pool::with([
'generalQuestions',
'screeningQuestions',
'poolSkills',
'poolSkills.skill',
'assessmentSteps' => ['poolSkills.skill'],
])
->whereIn('id', $this->poolIds)
->chunk(100, function ($pools) {
/** @var Pool $pool */
foreach ($pools as $pool) {
if ($pool->generalQuestions->count() > 0) {
/** @var GeneralQuestion $question */
foreach ($pool->generalQuestions as $question) {
$this->generalQuestionIds[] = $question->id;
$this->generatedHeaders['general_questions'][] =
Expand All @@ -321,6 +331,7 @@ private function generatePoolHeaders()
}

if ($pool->screeningQuestions->count() > 0) {
/** @var ScreeningQuestion $question */
foreach ($pool->screeningQuestions as $question) {
$this->screeningQuestionIds[] = $question->id;
$this->generatedHeaders['screening_questions'][] =
Expand Down Expand Up @@ -451,18 +462,23 @@ private function buildQuery()
'pool' => [
'generalQuestions',
'screeningQuestions',
'poolSkills' => ['skill'],
'assessmentSteps' => ['poolSkills'],
'poolSkills',
'poolSkills.skill',
'assessmentSteps',
'assessmentSteps.poolSkills',
],
'user' => [
'department',
'currentClassification',
'userSkills' => ['skill', 'experiences' => ['skills']],
'awardExperiences' => ['userSkills' => ['skill']],
'communityExperiences' => ['userSkills' => ['skill']],
'educationExperiences' => ['userSkills' => ['skill']],
'personalExperiences' => ['userSkills' => ['skill']],
'workExperiences' => ['userSkills' => ['skill']],
'userSkills',
'userSkills.skill',
'userSkills.experiences',
'userSkills.experiences.skills',
'awardExperiences.userSkills.skill',
'communityExperiences.userSkills.skill',
'educationExperiences.userSkills.skill',
'personalExperiences.userSkills.skill',
'workExperiences.userSkills.skill',
],
]);

Expand All @@ -474,6 +490,7 @@ private function buildQuery()
'community' => 'candidatesInCommunity',
]);

/** @var Builder<\App\Models\User> $query */
$query->authorizedToView(['userId' => $this->userId]);

return $query;
Expand Down
7 changes: 5 additions & 2 deletions api/app/Generators/PoolCandidateZipGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public function generate(): self
'user' => [
'department',
'currentClassification',
'experiences' => ['userSkills' => ['skill']],
'userSkills' => ['skill'],
'experiences',
'experiences.userSkills',
'experiences.userSkills.skill',
'userSkills',
'userSkills.skill',
],
'screeningQuestionResponses' => ['screeningQuestion'],
'generalQuestionResponses' => ['generalQuestion'],
Expand Down
2 changes: 2 additions & 0 deletions api/app/Generators/UserCsvGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Models\User;
use App\Traits\Generator\Filterable;
use App\Traits\Generator\GeneratesFile;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

Expand Down Expand Up @@ -164,6 +165,7 @@ private function buildQuery()
'skills' => 'skillsAdditive',
]);

/** @var Builder<User> $query */
$query->authorizedToView(['userId' => $this->userId]);

return $query;
Expand Down
2 changes: 1 addition & 1 deletion api/app/Generators/UserZipGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function generate(): self
User::with([
'department',
'currentClassification',
'experiences' => ['userSkills' => ['skill']],
'experiences' => ['userSkills', 'userSkills.skill'],
'userSkills' => ['skill'],
])
->whereIn('id', $this->ids)
Expand Down
1 change: 1 addition & 0 deletions api/app/GraphQL/Mutations/DuplicatePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __invoke($_, array $args)

$newPool->save();

/** @var iterable $skillsToSync */
$skillsToSync = $pool->poolSkills->map(function (PoolSkill $poolSkill) {
return [
'skill_id' => $poolSkill->skill->id,
Expand Down
5 changes: 5 additions & 0 deletions api/app/Models/ApplicantFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,31 @@ class ApplicantFilter extends Model
'qualified_streams' => 'array',
];

/** @return BelongsToMany<Classification, $this> */
public function classifications(): BelongsToMany
{
return $this->belongsToMany(Classification::class, 'applicant_filter_classification');
}

/** @return BelongsToMany<Classification, $this> */
public function qualifiedClassifications(): BelongsToMany
{
return $this->belongsToMany(Classification::class, 'applicant_filter_qualified_classification');
}

/** @return BelongsToMany<Skill, $this> */
public function skills(): BelongsToMany
{
return $this->belongsToMany(Skill::class, 'applicant_filter_skill');
}

/** @return BelongsToMany<Pool, $this> */
public function pools(): BelongsToMany
{
return $this->belongsToMany(Pool::class, 'applicant_filter_pool');
}

/** @return BelongsTo<Community, $this> */
public function community(): BelongsTo
{
return $this->belongsTo(Community::class);
Expand Down
3 changes: 3 additions & 0 deletions api/app/Models/AssessmentResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ public function getActivitylogOptions(): LogOptions
->dontSubmitEmptyLogs();
}

/** @return BelongsTo<AssessmentStep, $this> */
public function assessmentStep(): BelongsTo
{
return $this->belongsTo(AssessmentStep::class);
}

/** @return BelongsTo<PoolCandidate, $this> */
public function poolCandidate(): BelongsTo
{
return $this->belongsTo(PoolCandidate::class);
}

/** @return BelongsTo<PoolSkill, $this> */
public function poolSkill(): BelongsTo
{
return $this->belongsTo(PoolSkill::class);
Expand Down
4 changes: 4 additions & 0 deletions api/app/Models/AssessmentStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,26 @@ public function getActivitylogOptions(): LogOptions
->dontSubmitEmptyLogs();
}

/** @return BelongsTo<Pool, $this> */
public function pool(): BelongsTo
{
return $this->belongsTo(Pool::class);
}

/** @return BelongsToMany<PoolSkill, $this> */
public function poolSkills(): BelongsToMany
{
return $this->belongsToMany(PoolSkill::class, 'assessment_step_pool_skill')
->withTimestamps();
}

/** @return HasMany<AssessmentResult, $this> */
public function assessmentResults(): HasMany
{
return $this->hasMany(AssessmentResult::class);
}

/** @return HasMany<ScreeningQuestion, $this> */
public function screeningQuestions(): HasMany
{
return $this->hasMany(ScreeningQuestion::class);
Expand Down
2 changes: 0 additions & 2 deletions api/app/Models/AwardExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class AwardExperience extends Experience

/**
* Default values for attributes
*
* @var array an array with attribute as key and default as value
*/
protected $attributes = [
'experience_type' => AwardExperience::class,
Expand Down
1 change: 1 addition & 0 deletions api/app/Models/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Classification extends Model
'name' => 'array',
];

/** @return HasMany<GenericJobTitle, $this> */
public function genericJobTitles(): HasMany
{
return $this->hasMany(GenericJobTitle::class);
Expand Down
11 changes: 5 additions & 6 deletions api/app/Models/Community.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,31 @@ protected static function boot()
});
}

/**
* Search requests
*/
/** @return HasMany<PoolCandidateSearchRequest, $this> */
public function poolCandidateSearchRequests(): HasMany
{
return $this->hasMany(PoolCandidateSearchRequest::class);
}

/**
* ApplicationFilters
*/
/** @return HasMany<ApplicantFilter, $this> */
public function applicantFilters(): HasMany
{
return $this->hasMany(ApplicantFilter::class);
}

/** @return MorphOne<Team, $this> */
public function team(): MorphOne
{
return $this->morphOne(Team::class, 'teamable');
}

/** @return HasMany<Pool, $this> */
public function pools(): HasMany
{
return $this->hasMany(Pool::class);
}

/** @return HasManyThrough<RoleAssignment, Team, $this> */
public function roleAssignments(): HasManyThrough
{
// I think this only works because we use UUIDs
Expand Down
2 changes: 0 additions & 2 deletions api/app/Models/CommunityExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class CommunityExperience extends Experience

/**
* Default values for attributes
*
* @var array an array with attribute as key and default as value
*/
protected $attributes = [
'experience_type' => CommunityExperience::class,
Expand Down
11 changes: 4 additions & 7 deletions api/app/Models/Department.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ class Department extends Model
'name' => 'array',
];

/**
* Model relations
*/
/** @return HasMany<PoolCandidateSearchRequest, $this> */
public function poolCandidateSearchRequests(): HasMany
{
return $this->hasMany(PoolCandidateSearchRequest::class);
}

/** @return BelongsToMany<Team, $this> */
public function teams(): BelongsToMany
{
return $this->belongsToMany(Team::class, 'team_department');
Expand All @@ -68,10 +67,8 @@ public static function scopeDepartmentsByIds(Builder $query, ?array $departmentI
return $query;
}

/**
* Get the pools for the department.
*/
public function pools()
/** @return HasMany<Pool, $this> */
public function pools(): HasMany
{
return $this->hasMany(Pool::class);
}
Expand Down
2 changes: 0 additions & 2 deletions api/app/Models/EducationExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class EducationExperience extends Experience

/**
* Default values for attributes
*
* @var array an array with attribute as key and default as value
*/
protected $attributes = [
'experience_type' => EducationExperience::class,
Expand Down
Loading

0 comments on commit fcabb77

Please sign in to comment.