Completed
Push — master ( 395fb2...b0764c )
by he
10:48 queued 10s
created

JudgerRequest::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
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 getJudger()
14
    {
15
        if (!$this->judger) {
16
            $this->judger = app(JudgerService::class)->find($this->getJudgeId());
17
        }
18
19
        return $this->judger;
20
    }
21
22
    public function getJudgeId()
23
    {
24
        return $this->header('Judge-Id');
25
    }
26
27
    public function getToken()
28
    {
29
        return $this->header('Token');
30
    }
31
32
    public function validate()
33
    {
34
        parent::validate();
0 ignored issues
show
Bug introduced by
The method validate() does not exist on App\Http\Requests\Request. Did you maybe mean validateResolved()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        parent::/** @scrutinizer ignore-call */ 
35
                validate();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
36
        $origin = sprintf("%s-%d", $this->getJudger()->code, $this->input('ts'));
37
        if ($this->getToken() != md5($origin)) {
38
            throw new JudgerCodeInvalid();
39
        }
40
    }
41
}
42