Passed
Branch feature/babel (9a8402)
by John
03:52
created

Judger::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Babel\Judge;
4
5
use App\Models\SubmissionModel;
6
use App\Models\JudgerModel;
7
use App\Models\ContestModel;
8
use App\Babel\Submit\Curl;
9
use Auth;
10
use Requests;
11
use Exception;
12
use Log;
13
14
class Judger extends Curl
15
{
16
    public $data=null;
17
    private $judger=[];
18
    public $ret=[];
19
20
    /**
21
     * Initial
22
     *
23
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Babel\Judge\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
24
     */
25
    public function __construct()
26
    {
27
        $submissionModel=new SubmissionModel();
28
29
        $result=$submissionModel->getWaitingSubmission();
30
        foreach ($result as $row) {
31
            $ocode=$row["ocode"];
32
            if(!isset($this->judger[$ocode]) || is_null($this->judger[$ocode])) {
33
                $this->judger[$ocode]=self::create($ocode);
34
            }
35
            $this->judger[$ocode]->judge($row);
36
        }
37
    }
38
39
    public static function create($ocode) {
40
        $name=$ocode;
41
        $className = "App\\Babel\\Extension\\$name\\Judger";
42
        if(class_exists($className)) {
43
            return new $className();
44
        } else {
45
            return null;
46
        }
47
    }
48
}
49