Passed
Push — master ( 609799...41987d )
by John
04:18
created

Core::__construct()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 23
nc 128
nop 3
dl 0
loc 38
rs 8.2111
c 0
b 0
f 0
1
<?php
2
namespace App\Babel\Judger;
3
4
use App\Models\SubmissionModel;
5
use App\Models\JudgerModel;
6
use App\Models\ProblemModel;
7
use App\Http\Controllers\VirtualJudge\Curl;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, App\Babel\Judger\Curl. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use App\Http\Controllers\VirtualJudge\NOJ\NOJ;
9
use App\Http\Controllers\VirtualJudge\CodeForces\CodeForces;
10
use App\Http\Controllers\VirtualJudge\ContestHunter\ContestHunter;
11
use App\Http\Controllers\VirtualJudge\POJ\POJ;
12
use App\Http\Controllers\VirtualJudge\Vijos\Vijos;
13
use App\Http\Controllers\VirtualJudge\PTA\PTA;
14
use App\Http\Controllers\VirtualJudge\UVa\UVa;
15
use Requests;
16
17
class Core extends Curl
18
{
19
    private $sub;
20
    public $post_data=[];
21
22
    public function __construct(& $sub, $oj, $all_data)
23
    {
24
        $this->sub=& $sub;
25
        $this->post_data=$all_data;
26
27
        if ($oj=='noj') {
28
            $NOJ=new NOJ($sub, $all_data);
29
            $NOJ->submit();
30
        }
31
32
        if ($oj=='codeforces') {
33
            $CodeForces=new CodeForces($sub, $all_data);
34
            $CodeForces->submit();
35
        }
36
37
        if ($oj=='contesthunter') {
38
            $ContestHunter=new ContestHunter($sub, $all_data);
39
            $ContestHunter->submit();
40
        }
41
42
        if ($oj=='poj') {
43
            $POJ=new POJ($sub, $all_data);
44
            $POJ->submit();
45
        }
46
47
        if ($oj=='vijos') {
48
            $Vijos=new Vijos($sub, $all_data);
49
            $Vijos->submit();
50
        }
51
52
        if ($oj=='pta') {
53
            $PTA=new PTA($sub, $all_data);
54
            $PTA->submit();
55
        }
56
57
        if ($oj=='uva') {
58
            $UVa=new UVa($sub, $all_data);
59
            $UVa->submit();
60
        }
61
    }
62
}
63
64
65
66
67
68
69
70
    // protected function uva_live_login($url1, $url2, $oj)
71
    // {
72
    //     $response=$this->grab_page($url1, $oj);
73
    //     if (!(strpos($response, 'Logout') !== false)&&(strpos($response, 'Login') !== false)) {
74
    //         $exploded = explode('<input type="hidden" name="cbsecuritym3" value="', $response);
75
    //         $cbsecuritym3 = explode('"', $exploded[1])[0];
76
77
    //         $exploded = explode('<input type="hidden" name="return" value="', $response);
78
    //         $return = explode('"', $exploded[1])[0];
79
80
    //         $exploded = explode('<input type="hidden" name="cbsecuritym3" value="', $response);
81
    //         $exploded = explode('<input type="hidden" name="', $exploded[1]);
82
    //         $any = explode('"', $exploded[1])[0];
83
84
85
    //         $params = [
86
    //             'username' => 'codemaster_uva',
87
    //             'passwd' => '123456',
88
    //             'op2' => 'login',
89
    //             'lang' => 'english',
90
    //             'force_session' => '1',
91
    //             'return' => $return,
92
    //             'message' => '0',
93
    //             'loginfrom' => 'loginmodule',
94
    //             'cbsecuritym3' =>  $cbsecuritym3,
95
    //             $any => '1',
96
    //             'remember' => 'yes',
97
    //             'Submit' => 'Login',
98
    //         ];
99
100
    //         $data=http_build_query($params);
101
    //         $this->login($url2, http_build_query($params), $oj);
102
    //     }
103
    // }
104
    // public function uva_live_submit($url, $oj)
105
    // {
106
    //     $this->sub['language']=substr($this->post_data["lang"], 1, 50);
107
    //     $this->sub['solution']=$this->post_data["solution"];
108
    //     $this->sub['pid']=$this->post_data["pid"];
109
110
    //     $code=$this->post_data["solution"];
111
    //     $lang=substr($this->post_data["lang"], 0, 1);
112
    //     $pro_id=$this->post_data['iid'];
113
114
    //     $params = [
115
    //         'problemid' => $pro_id,
116
    //         'category' => '',
117
    //         'language' => $lang,
118
    //         'code' => $code,
119
    //         'codeupl' => '',
120
    //     ];
121
    //     $data=http_build_query($params);
122
    //     $response=$this->post_data($url, $data, $oj, true);
123
    //     if (substr_count($response, 'Submission+received+with+ID')==0) {
124
    //         $exploded = explode('mosmsg=', $response);
125
    //         $this->sub['verdict'] = urldecode(explode('"', $exploded[2])[0]);
126
    //     }
127
    // }
128
    // private function uva()
129
    // {
130
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
131
    //         redirect("/");
132
    //     }
133
    //     $response=$this->grab_page('https://uva.onlinejudge.org', 'uva');
134
    //     if (!(strpos($response, 'UVa Online Judge - Offline') !== false)&&strlen($response)!=0) {
135
    //         $this->uva_live_login('https://uva.onlinejudge.org', 'https://uva.onlinejudge.org/index.php?option=com_comprofiler&task=login', 'uva');
136
    //         $this->uva_live_submit('https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=save_submission', 'uva');
137
    //     } else {
138
    //         $this->sub['language']=substr($this->post_data["lang"], 1, 50);
139
    //         $this->sub['solution']=$this->post_data["solution"];
140
    //         $this->sub['pid']=$this->post_data["pid"];
141
    //         $this->sub['verdict']="Judge Error";
142
    //     }
143
    // }
144
    // private function uvalive()
145
    // {
146
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
147
    //         redirect("/");
148
    //     }
149
    //     $this->uva_live_login('https://icpcarchive.ecs.baylor.edu', 'https://icpcarchive.ecs.baylor.edu/index.php?option=com_comprofiler&task=login', 'uvalive');
150
    //     $this->uva_live_submit('https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=save_submission', 'uvalive');
151
    // }
152
    // public function spoj_login()
153
    // {
154
    //     $response=$this->grab_page('http://www.spoj.com', 'spoj');
155
    //     if (!(strpos($response, 'sign-out') !== false)) {
156
    //         $params = [
157
    //             'next_raw' => "/",
158
    //             'autologin' => '1',
159
    //             'login_user' => 'codemaster_spoj',
160
    //             'password' => '123456'
161
    //         ];
162
163
    //         $data=http_build_query($params);
164
    //         $this->login('http://www.spoj.com/login', $data, 'spoj');
165
    //     }
166
    // }
167
    // public function multiexplode($delimiters, $string)
168
    // {
169
    //     $ready = str_replace($delimiters, $delimiters[0], $string);
170
    //     $launch = explode($delimiters[0], $ready);
171
    //     return  $launch;
172
    // }
173
    // public function spoj_submit()
174
    // {
175
    //     $x=0;
176
    //     for ($i=0;$i<strlen($this->post_data["lang"]);$i++) {
177
    //         if (is_numeric($this->post_data["lang"][$i])) {
178
    //             $x++;
179
    //         } else {
180
    //             break;
181
    //         }
182
    //     }
183
    //     $this->sub['language']=substr($this->post_data["lang"], $x, strlen($this->post_data["lang"]));
184
    //     $this->sub['solution']=$this->post_data["solution"];
185
    //     $this->sub['pid']=$this->post_data["pid"]; // 500A
186
    //     $lang=substr($this->post_data["lang"], 0, $x);
187
188
    //     $params = [
189
    //         'subm_file' => '',
190
    //         'file' => $this->post_data["solution"],
191
    //         'lang' => $lang,
192
    //         'problemcode' => $this->post_data['iid'],
193
    //         'submit' => 'Submit!',
194
    //     ];
195
196
    //     $data=http_build_query($params);
197
    //     $response=$this->post_data('http://www.spoj.com/submit/complete/', $data, 'spoj', true);
198
    //     if (substr_count($response, 'Solution submitted!')==0) {
199
    //         $exploded = explode('<p align="center">', $response);
200
    //         $this->sub['verdict'] = $this->multiexplode(["!","."], $exploded[1])[0];
201
    //     }
202
    // }
203
204
    // private function spoj()
205
    // {
206
    //     if (!isset($this->post_data["pid"])||!isset($this->post_data["iid"])||!isset($this->post_data["iid"])||!isset($_COOKIE["user_handle"])&&!isset($this->post_data["solution"])) {
207
    //         redirect("/");
208
    //     }
209
    //     $this->spoj_login();
210
    //     $this->spoj_submit();
211
    // }
212
213