Passed
Pull Request — master (#182)
by John
04:01
created

Submitter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
nc 2
nop 1
dl 0
loc 22
rs 9.8333
c 2
b 0
f 0
1
<?php
2
3
namespace App\Babel\Submit;
4
5
use App\Models\SubmissionModel;
6
use App\Babel\Submit\Core;
0 ignored issues
show
Bug introduced by
The type App\Babel\Submit\Core was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Support\Facades\Validator;
8
use Auth;
9
10
class Submitter
11
{
12
    public $post_data=[];
13
14
    /**
15
     * Initial
16
     *
17
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Babel\Submit\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
18
     */
19
    public function __construct($all_data)
20
    {
21
        $this->post_data=$all_data;
22
23
        set_time_limit(0);
24
25
        $sub=[
26
            'time'=>'0',
27
            'verdict'=>'Waiting',
28
            'memory'=>'0',
29
            'remote_id'=>'',
30
            'score'=>0,
31
            'compile_info'=>'',
32
        ];
33
34
        $submitter=self::create($this->post_data["oj"], $sub, $all_data);
35
        if(!is_null($submitter)) $submitter->submit();
36
37
        // insert submission
38
39
        $submission=new SubmissionModel();
40
        $submission->updateSubmission($this->post_data["sid"], $sub);
41
    }
42
43
    public static function create($oj,& $sub, $all_data) {
44
        $submitterProvider="Submitter";
45
        try {
46
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
47
            $submitterProvider=$BabelConfig["provider"]["submitter"];
48
        } catch(ErrorException $e) {
0 ignored issues
show
Bug introduced by
The type App\Babel\Submit\ErrorException was not found. Did you mean ErrorException? If so, make sure to prefix the type with \.
Loading history...
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
49
        } catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The type App\Babel\Submit\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
50
        }
51
        $className = "App\\Babel\\Extension\\$oj\\$submitterProvider";
52
        if(class_exists($className)) {
53
            return new $className($sub, $all_data);
54
        } else {
55
            return null;
56
        }
57
    }
58
}
59