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

DatabaseVisitor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 30
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A experiment() 0 4 1
A hasExperiment() 0 4 2
A getExperiment() 0 4 1
A setExperiment() 0 5 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