Passed
Push — master ( 49e434...6c0612 )
by
unknown
04:29 queued 10s
created

Core::__construct()   D

Complexity

Conditions 10
Paths 512

Size

Total Lines 48
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 29
nc 512
nop 3
dl 0
loc 48
rs 4.1777
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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