Judger::create()   A
last analyzed

Complexity

Conditions 4
Paths 10

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
c 0
b 0
f 0
nc 10
nop 1
dl 0
loc 15
rs 9.8666
1
<?php
2
3
namespace App\Babel\Judge;
4
5
use App\Models\Submission\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 ErrorException;
12
use Exception;
13
use Throwable;
14
use Log;
15
16
class Judger extends Curl
17
{
18
    public $data=null;
19
    private $judger=[];
20
    public $ret=[];
21
22
    /**
23
     * Initial
24
     *
25
     * @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...
26
     */
27
    public function __construct()
28
    {
29
        $submissionModel=new SubmissionModel();
30
31
        $result=$submissionModel->getWaitingSubmission();
32
33
        $submissionCount = count($result);
34
35
        Log::channel('babel_judge_sync')->info("Currently $submissionCount submission(s) awaiting", [$result]);
36
37
        foreach ($result as $row) {
38
            $ocode=$row["ocode"];
39
            try {
40
                if (!isset($this->judger[$ocode]) || is_null($this->judger[$ocode])) {
41
                    $this->judger[$ocode]=self::create($ocode);
42
                }
43
                $this->judger[$ocode]->judge($row);
44
            } catch (Throwable $e) {
45
                Log::channel('babel_judge_sync')->alert("Exception Occurs While Processing $ocode's Submission {$row['sid']}\n".$e->getMessage()."\nAt ".$e->getFile().":".$e->getLine());
46
            } catch (Exception $e) {
47
                Log::channel('babel_judge_sync')->alert("Exception Occurs While Processing $ocode's Submission {$row['sid']}\n".$e->getMessage()."\nAt ".$e->getFile().":".$e->getLine());
48
            }
49
        }
50
    }
51
52
    public static function create($ocode)
53
    {
54
        $name=$ocode;
55
        $judgerProvider="Judger";
56
        try {
57
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$ocode/babel.json")), true);
58
            $judgerProvider=$BabelConfig["provider"]["judger"];
59
        } catch (ErrorException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
60
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
        }
62
        $className="App\\Babel\\Extension\\$name\\$judgerProvider";
63
        if (class_exists($className)) {
64
            return new $className();
65
        } else {
66
            return null;
67
        }
68
    }
69
}
70