Passed
Push — dev ( 03a84b...1c649f )
by Chris
06:48 queued 10s
created

Department   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 53
rs 10
ccs 0
cts 6
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A department_translations() 0 3 1
A toApiArray() 0 10 2
A job_posters() 0 3 1
A managers() 0 3 1
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\Lookup;
9
10
use App\Models\BaseModel;
11
12
use Backpack\CRUD\CrudTrait;
13
use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
14
15
/**
16
 * Class Department
17
 * @property int $id
18
 * @property string $name
19
 * @property string $impact
20
 * @property string $preference
21
 *
22
 * @property \Jenssegers\Date\Date $created_at
23
 * @property \Jenssegers\Date\Date $updated_at
24
 *
25
 * @property \Illuminate\Database\Eloquent\Collection $managers
26
 * @property \Illuminate\Database\Eloquent\Collection $job_posters
27
 *
28
 * Localized Properties:
29
 * @property string $name
30
 * @property string $impact
31
 * @property string $preference
32
 *
33
 * Methods
34
 * @method mixed[] toApiArray()
35
 */
36
class Department extends BaseModel
37
{
38
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\CrudTrait requires some properties which are not provided by App\Models\Lookup\Department: $Type, $fakeColumns
Loading history...
39
    use HasTranslations;
40
41
    /**
42
     * @var $translatable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $translatable at position 0 could not be parsed: Unknown type name '$translatable' at position 0 in $translatable.
Loading history...
43
     * */
44
    public $translatable = [
45
        'name',
46
        'impact',
47
        'preference',
48
    ];
49
50
    /**
51
     * @var $fillable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $fillable at position 0 could not be parsed: Unknown type name '$fillable' at position 0 in $fillable.
Loading history...
52
     * */
53
    protected $fillable = [
54
        'name',
55
        'impact',
56
        'preference',
57
    ];
58
59
    public function managers() // phpcs:ignore
60
    {
61
        return $this->hasMany(\App\Models\Manager::class);
62
    }
63
64
    public function department_translations() // phpcs:ignore
65
    {
66
        return $this->hasMany(\App\Models\Lookup\DepartmentTranslation::class);
67
    }
68
69
    public function job_posters() // phpcs:ignore
70
    {
71
        return $this->hasMany(\App\Models\JobPoster::class);
72
    }
73
74
    /**
75
     * Return the array of values used to represent this object in an api response.
76
     *
77
     * @return mixed[]
78
     */
79
    public function toApiArray()
0 ignored issues
show
introduced by
Method \App\Models\Lookup\Department::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...
80
    {
81
        $deptArray = ['id' => $this->id];
82
        foreach (['en', 'fr'] as $locale) {
83
            $deptArray[$locale] = [
84
                'name' => $this->getTranslation('name', $locale),
85
                'impact' => $this->getTranslation('impact', $locale),
86
            ];
87
        }
88
        return $deptArray;
89
    }
90
}
91