AchievementModel   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A criterias() 0 4 1
A completed() 0 4 2
1
<?php
2
3
namespace Laravel\Achievements;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Class AchievementModel
9
 *
10
 * @property int $id
11
 * @property string $name
12
 * @property string $description
13
 * @property int $points
14
 * @property \Carbon\Carbon $created_at
15
 * @property \Carbon\Carbon $updated_at
16
 * @property \Illuminate\Database\Eloquent\Collection|AchievementCriteriaModel[] $criterias
17
 */
18
class AchievementModel extends Model
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $table = 'achievements';
24
25
    /**
26
     * @var array
27
     */
28
    protected $fillable = [
29
        'name', 'description', 'points',
30
    ];
31
32
    /**
33
     * @var array
34
     */
35
    protected $casts = [
36
        'points' => 'integer',
37
    ];
38
39
    /**
40
     * Criterias list.
41
     *
42
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
43
     */
44
    public function criterias()
45
    {
46
        return $this->hasMany(config('achievements.models.criteria'), 'achievement_id');
47
    }
48
49
    /**
50
     * Determines if achievement was completed.
51
     * This works only in user-related achievements lists.
52
     *
53
     * @return bool
54
     */
55
    public function completed(): bool
56
    {
57
        return $this->relationLoaded('pivot') && !is_null($this->pivot->completed_at);
58
    }
59
}
60