PeriodSelection::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
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
        if (Period::count() > 0) {
15
            $this->currentPeriod = Period::get_default_period()->id;
16
        }
17
    }
18
19
    protected function selectPeriod(Request $request)
20
    {
21
        $period_id = $request->query('period');
22
        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...
23
            $period = Period::get_default_period();
24
        } else {
25
            $period = Period::find($period_id);
26
        }
27
28
        return $period;
29
    }
30
}
31