JudgerRequest::getJudger()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Http\Requests\Judger;
4
5
use App\Exceptions\Judger\JudgerCodeInvalid;
6
use App\Http\Requests\Request;
7
use App\Services\JudgerService;
8
9
class JudgerRequest extends Request
10
{
11
    private $judger;
12
13
    public function validate()
14
    {
15
        $origin = sprintf('%s-%d', $this->getJudger()->code, $this->input('ts'));
16
        if ($this->getToken() != md5($origin)) {
17
            throw new JudgerCodeInvalid();
18
        }
19
    }
20
21
    public function getJudger()
22
    {
23
        if (! $this->judger) {
24
            $this->judger = app(JudgerService::class)->find($this->getJudgeId());
25
        }
26
27
        return $this->judger;
28
    }
29
30
    public function getJudgeId()
31
    {
32
        return $this->header('Judge-Id');
33
    }
34
35
    public function getToken()
36
    {
37
        return $this->header('Token');
38
    }
39
}
40