Base::get()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace CaribouFute\LocaleRoute\Session;
4
5
use Illuminate\Session\Store;
6
7
abstract class Base
8
{
9
    protected $store;
10
    protected $key;
11
12 33
    public function __construct(Store $store)
13
    {
14 33
        $this->store = $store;
15
    }
16
17 5
    public function get()
18
    {
19 5
        return $this->store->get($this->key) ?: $this->setAndGetDefault();
20
    }
21
22 32
    public function set($value): void
23
    {
24 32
        $this->put($value);
25
    }
26
27 32
    public function put($value): void
28
    {
29 32
        $this->store->put($this->key, $value);
30
    }
31
32 2
    protected function setAndGetDefault()
33
    {
34 2
        $default = $this->getDefault();
35 2
        $this->set($default);
36 2
        return $default;
37
    }
38
39
    abstract protected function getDefault();
40
}
41