Completed
Push — feature/default-questions-for-... ( 71cb2f...4b5016 )
by Chris
14:16 queued 06:35
created

Criteria::getLevelNameAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
7
8
namespace App\Models;
9
10
use App\Models\Lookup\CriteriaTypeTranslation;
11
use Illuminate\Support\Facades\Lang;
12
13
/**
14
 * Class Criteria
15
 *
16
 * @property int $id
17
 * @property int $criteria_type_id
18
 * @property int $job_poster_id
19
 * @property int $skill_id
20
 * @property int $skill_level_id
21
 * @property \Jenssegers\Date\Date $created_at
22
 * @property \Jenssegers\Date\Date $updated_at
23
 *
24
 * @property \App\Models\Lookup\CriteriaType $criteria_type
25
 * @property \App\Models\JobPoster $job_poster
26
 * @property \App\Models\Skill $skill
27
 * @property \App\Models\Lookup\SkillLevel $skill_level
28
 * @property \Illuminate\Database\Eloquent\Collection $criteria_translations
29
 * @property \Illuminate\Database\Eloquent\Collection[Assessment] $assessments
30
 *
31
 *  Accessors
32
 * @property string $level_name The localized name of the skill level (accounts for skill type).
33
 * @property string $level_description The localized description of the skill level (accounts for skill type).
34
 *
35
 *  Localized Properties:
36
  * @property string $description
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) before asterisk; 2 found
Loading history...
37
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment \Illuminate\Database\Elo...\Collection[Assessment] at position 1 could not be parsed: Expected ']' at position 1, but found '['.
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
38
class Criteria extends BaseModel {
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
39
40
    use \Dimsav\Translatable\Translatable;
0 ignored issues
show
introduced by
The trait Dimsav\Translatable\Translatable requires some properties which are not provided by App\Models\Criteria: $translations, $useTranslationFallback, $translationModel, $localeKey, $translationForeignKey
Loading history...
41
    public $translatedAttributes = ['description'];
42
43
    protected $table = 'criteria';
44
    protected $casts = [
45
        'criteria_type_id' => 'int',
46
        'job_poster_id' => 'int',
47
        'skill_id' => 'int',
48
        'skill_level_id' => 'int',
49
    ];
50
    protected $fillable = [
51
        'criteria_type_id',
52
        'skill_id',
53
        'skill_level_id',
54
    ];
55
    protected $with = [
56
        'criteria_type',
57
        'skill',
58
        'skill_level'
59
    ];
60
61 2
    public function criteria_type() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria_type()
Loading history...
Coding Style introduced by
Public method name "Criteria::criteria_type" is not in camel caps format
Loading history...
62 2
        return $this->belongsTo(\App\Models\Lookup\CriteriaType::class);
63
    }
64
65
    public function job_poster() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_poster()
Loading history...
Coding Style introduced by
Public method name "Criteria::job_poster" is not in camel caps format
Loading history...
66
        return $this->belongsTo(\App\Models\JobPoster::class);
67
    }
68
69 2
    public function skill() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function skill()
Loading history...
70 2
        return $this->belongsTo(\App\Models\Skill::class);
71
    }
72
73 2
    public function skill_level() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function skill_level()
Loading history...
Coding Style introduced by
Public method name "Criteria::skill_level" is not in camel caps format
Loading history...
74 2
        return $this->belongsTo(\App\Models\Lookup\SkillLevel::class);
75
    }
76
77
    public function criteria_translations() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria_translations()
Loading history...
Coding Style introduced by
Public method name "Criteria::criteria_translations" is not in camel caps format
Loading history...
78
        return $this->hasMany(\App\Models\Lookup\CriteriaTypeTranslation::class);
79
    }
80
81
    /**
82
     * Get all assessments for this Criteria, for all Screening Plans.
83
     *
84
     * @return \Illuminate\Database\Eloquent\Collection
85
     */
86
    public function assessments() // phpcs:ignore
87
    {
88
        return $this->hasMany(\App\Models\Assessment::class, 'criterion_id');
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->hasMany(Ap...:class, 'criterion_id') returns the type Illuminate\Database\Eloquent\Relations\HasMany which is incompatible with the documented return type Illuminate\Database\Eloquent\Collection.
Loading history...
89
    }
90
91
    /**
92
     * Get the translated name of this Criteria's required skill level.
93
     *
94
     * @return string
95
     */
96
    public function getLevelNameAttribute(): string
97
    {
98
        $level = $this->skill_level->name;
99
        $type = $this->skill->skill_type->name;
100
        return Lang::get("common/lookup/skill_level.$level.$type.name");
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...evel.'.'.$type.'.name') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
101
    }
102
103
    /**
104
     * Get the translated description of this Criteria's required skill level.
105
     *
106
     * @return string
107
     */
108
    public function getLevelDescriptionAttribute() : string
109
    {
110
        $level = $this->skill_level->name;
111
        $type = $this->skill->skill_type->name;
112
        return Lang::get("common/lookup/skill_level.$level.$type.description");
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...'.$type.'.description') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
113
    }
114
}
115