Passed
Push — master ( d700b0...2a2eb6 )
by Thomas
12:55 queued 10s
created

PeriodSelection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Traits;
4
5
use App\Models\Period;
6
use Illuminate\Http\Request;
7
8
trait PeriodSelection
9
{
10
    public $currentPeriod;
11
12
    public function __construct()
13
    {
14
        $this->currentPeriod = Period::get_default_period()->id;
15
    }
16
17
    protected function selectPeriod(Request $request)
18
    {
19
        $period_id = $request->query('period', null);
20
        if ($period_id == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $period_id of type array|null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
21
            $period = Period::get_default_period();
22
        } else {
23
            $period = Period::find($period_id);
24
        }
25
26
        return $period;
27
    }
28
}
29