Completed
Pull Request — master (#17)
by
unknown
08:59 queued 07:53
created

DatabaseVisitor::getExperiment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ben182\AbTesting\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Ben182\AbTesting\Contracts\VisitorInterface;
7
8
class DatabaseVisitor extends Model implements VisitorInterface
9
{
10
    protected $primaryKey = 'visitor_id';
11
    protected $table = 'ab_visitors';
12
    protected $fillable = [
13
        'visitor_id',
14
        'experiment_id',
15
    ];
16
17 6
    public function experiment()
18
    {
19 6
        return $this->belongsTo(Experiment::class);
20
    }
21
22
    public function hasExperiment()
23
    {
24
        return ! is_null($this->experiment_id) && $this->experiment_id;
25
    }
26
27 6
    public function getExperiment()
28
    {
29 6
        return $this->experiment;
30
    }
31
32 6
    public function setExperiment(Experiment $next)
33
    {
34 6
        $this->experiment_id = $next->id;
35 6
        $this->save();
36 6
    }
37
}
38