PeriodSelection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A selectPeriod() 0 10 2
A __construct() 0 4 2
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