Passed
Push — task/ide-helper ( b1e475...159489 )
by Grant
10:45
created

Manager::getFirstNameAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
7
8
namespace App\Models;
9
10
use App\CRUD\TalentCloudCrudTrait as CrudTrait;
11
use Astrotomic\Translatable\Translatable as Translatable;
12
13
/**
14
 * Class Manager
15
 *
16
 * @property int $id
17
 * @property int $department_id
18
 * @property int $work_review_frequency_id
19
 * @property int $stay_late_frequency_id
20
 * @property int $engage_team_frequency_id
21
 * @property int $development_opportunity_frequency_id
22
 * @property int $refuse_low_value_work_frequency_id
23
 * @property int $years_experience
24
 * @property string $twitter_username
25
 * @property string $linkedin_url
26
 * @property int $user_id
27
 * @property \Jenssegers\Date\Date $created_at
28
 * @property \Jenssegers\Date\Date $updated_at
29
 *
30
 * @property \App\Models\User $user
31
 * @property \App\Models\Lookup\Department $department
32
 * @property \Illuminate\Database\Eloquent\Collection $job_posters
33
 * @property \App\Models\WorkEnvironment $work_environment
34
 * @property \App\Models\TeamCulture $team_culture
35
 * @property \App\Models\Lookup\Frequency $work_review_frequency
36
 * @property \App\Models\Lookup\Frequency $stay_late_frequency
37
 * @property \App\Models\Lookup\Frequency $engage_team_frequency
38
 * @property \App\Models\Lookup\Frequency $development_opportunity_frequency
39
 * @property \App\Models\Lookup\Frequency $refuse_low_value_work_frequency
40
 *
41
 * Localized Properties:
42
 * @property string $about_me
43
 * @property string $greatest_accomplishment
44
 * @property string $division
45
 * @property string $position
46
 * @property string $leadership_style
47
 * @property string $employee_learning
48
 * @property string $expectations
49
 * @property string $education
50
 * @property string $career_journey
51
 * @property string $learning_path
52
 *
53
 * Computed Properties
54
 * @property string $full_name
55
 * @property string $first_name
56
 * @property string $last_name
57
 * @property boolean $is_demo_manager
58
 *
59
 * Methods
60
 * @method   string toApiArray()
61
 */
62
class Manager extends BaseModel
63
{
64
    use Translatable;
0 ignored issues
show
Bug introduced by
The trait Astrotomic\Translatable\Translatable requires the property $each which is not provided by App\Models\Manager.
Loading history...
65
    // Trait for Backpack
66
    use CrudTrait;
0 ignored issues
show
introduced by
The trait App\CRUD\TalentCloudCrudTrait requires some properties which are not provided by App\Models\Manager: $Type, $fakeColumns
Loading history...
67
68
    public $translatedAttributes = [
1 ignored issue
show
introduced by
Property \App\Models\Manager::$translatedAttributes does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
69
        'about_me',
70
        'greatest_accomplishment',
71
        'division',
72
        'position',
73
        'leadership_style',
74
        'employee_learning',
75
        'expectations',
76
        'education',
77
        'career_journey',
78
        'learning_path'
79
    ];
80
    protected $casts = [
1 ignored issue
show
introduced by
Property \App\Models\Manager::$casts does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
81
        'department_id' => 'int',
82
        'user_id' => 'int'
83
    ];
84
    protected $fillable = [
1 ignored issue
show
introduced by
Property \App\Models\Manager::$fillable does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
85
        'department_id',
86
        'twitter_username',
87
        'linkedin_url',
88
        'work_review_frequency_id',
89
        'stay_late_frequency_id',
90
        'engage_team_frequency_id',
91
        'development_opportunity_frequency_id',
92
        'refuse_low_value_work_frequency_id',
93
        'years_experience'
94
    ];
95
96
    /**
97
     * The accessors to append to the model's array form.
98
     *
99
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Models\Manager::$appends does not specify type hint for its items.
Loading history...
100
     */
101
    protected $appends = ['first_name', 'last_name', 'full_name', 'is_demo_manager'];
102
103
    /**
104
     * The attributes that should be visible in arrays.
105
     *
106
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Models\Manager::$visible does not specify type hint for its items.
Loading history...
107
     */
108
    protected $visible = [
109
        'id',
110
        'user_id',
111
        'first_name',
112
        'last_name',
113
        'full_name',
114
        'department_id',
115
        'twitter_username',
116
        'linkedin_url',
117
        'is_demo_manager'
118
    ];
119
120
    public function user()
1 ignored issue
show
introduced by
Method \App\Models\Manager::user() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function user()
Loading history...
121
    {
122
        return $this->belongsTo(\App\Models\User::class);
123
    }
124
125
    public function department()
1 ignored issue
show
introduced by
Method \App\Models\Manager::department() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function department()
Loading history...
126
    {
127
        return $this->belongsTo(\App\Models\Lookup\Department::class);
128
    }
129
130
    public function job_posters() //phpcs:ignore
131
    {
132
        return $this->hasMany(\App\Models\JobPoster::class);
133
    }
134
135
    public function work_environment() //phpcs:ignore
136
    {
137
        return $this->hasOne(\App\Models\WorkEnvironment::class)->withDefault();
138
    }
139
140
    public function team_culture() //phpcs:ignore
141
    {
142
        return $this->hasOne(\App\Models\TeamCulture::class)->withDefault();
143
    }
144
    /*
145
    * @property \App\Models\Lookup\Frequency $review_options
146
    * @property \App\Models\Lookup\Frequency $staylate
147
    * @property \App\Models\Lookup\Frequency $engage
148
    * @property \App\Models\Lookup\Frequency $opportunities
149
    * @property \App\Models\Lookup\Frequency $low_value_work_requests
150
    *
151
    * work_review_frequency
152
    * stay_late_frequency
153
    * engage_team_frequency
154
    * development_opportunity_frequency
155
    * refuse_low_value_work_frequency
156
    */
157
    public function work_review_frequency() //phpcs:ignore
158
    {
159
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
160
    }
161
162
    public function stay_late_frequency() //phpcs:ignore
163
    {
164
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
165
    }
166
167
    public function engage_team_frequency() //phpcs:ignore
168
    {
169
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
170
    }
171
172
    public function development_opportunity_frequency() //phpcs:ignore
173
    {
174
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
175
    }
176
177
    public function refuse_low_value_work_frequency() //phpcs:ignore
178
    {
179
        return $this->belongsTo(\App\Models\Lookup\Frequency::class);
180
    }
181
182
    /**
183
     * Return the full name of the User associated with this Manager.
184
     *
185
     * @return string
186
     */
187
    public function getFullNameAttribute(): string
188
    {
189
        if ($this->user !== null) {
190
            return $this->user->first_name . ' ' . $this->user->last_name;
191
        }
192
        return '';
193
    }
194
195
    /**
196
     * Return the first name of the User associated with this Manager.
197
     *
198
     * @return string
199
     */
200
    public function getFirstNameAttribute(): string
201
    {
202
        if ($this->user !== null) {
203
            return $this->user->first_name;
204
        }
205
        return '';
206
    }
207
208
    /**
209
     * Return the last name of the User associated with this Manager.
210
     *
211
     * @return string
212
     */
213
    public function getLastNameAttribute(): string
214
    {
215
        if ($this->user !== null) {
216
            return $this->user->last_name;
217
        }
218
        return '';
219
    }
220
221
    /**
222
     * Return whether this is a Demo Manager.
223
     *
224
     * @return boolean
225
     */
226
    public function getIsDemoManagerAttribute(): bool
227
    {
228
        if ($this->user !== null) {
229
            return $this->user->isDemoManager();
230
        }
231
        return true;
232
    }
233
234
    /**
235
     * Return the array of values used to represent this object in an api response.
236
     * This array should contain no nested objects (besides translations).
237
     *
238
     * @return mixed[]
239
     */
240
    public function toApiArray()
0 ignored issues
show
introduced by
Method \App\Models\Manager::toApiArray() does not have return type hint for its return value but it should be possible to add it based on @return annotation "mixed[]".
Loading history...
241
    {
242
        $withTranslations = array_merge($this->toArray(), $this->getTranslationsArray());
243
        return $withTranslations;
244
    }
245
}
246