Passed
Push — master ( b831b6...96f132 )
by John
06:04 queued 21s
created

Dojo   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
dl 0
loc 41
rs 10
c 1
b 0
f 1
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 1
A phase() 0 3 1
A canPass() 0 8 2
A getAvailabilityAttribute() 0 7 5
A problems() 0 3 1
A getPassedAttribute() 0 3 1
1
<?php
2
3
namespace App\Models\Eloquent\Dojo;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Dojo extends Model
9
{
10
    use SoftDeletes;
11
12
    public function phase()
13
    {
14
        return $this->belongsTo('App\Models\Eloquent\Dojo\DojoPhase', 'dojo_phase_id');
15
    }
16
17
    public function problems()
18
    {
19
        return $this->hasMany('App\Models\Eloquent\Dojo\DojoProblem', 'dojo_id');
20
    }
21
22
    public function passes()
23
    {
24
        return $this->hasMany('App\Models\Eloquent\Dojo\DojoPass', 'dojo_id');
25
    }
26
27
    public function canPass()
28
    {
29
        $tot=0;
30
        foreach($this->problems->sortBy('order') as $problem){
31
            $problem=$problem->problem;
32
            $tot+=$problem->problem_status['color']=='wemd-green-text';
33
        }
34
        return $tot>=$this->passline;
0 ignored issues
show
Bug introduced by
The property passline does not seem to exist on App\Models\Eloquent\Dojo\Dojo. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
35
    }
36
37
    public function getPassedAttribute()
38
    {
39
        return DojoPass::isPassed($this->id);
40
    }
41
42
    public function getAvailabilityAttribute()
43
    {
44
        foreach(explode(',', $this->precondition) as $dojo_id){
0 ignored issues
show
Bug introduced by
The property precondition does not seem to exist on App\Models\Eloquent\Dojo\Dojo. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
45
            if(blank($dojo_id)) continue;
46
            if(!DojoPass::isPassed($dojo_id)) return 'locked';
47
        }
48
        return $this->passed?'passed':'available';
49
    }
50
51
}
52