Test Setup Failed
Push — master ( e2b9fb...698287 )
by
unknown
04:27
created

Judge::get_last_spoj()   B

Complexity

Conditions 10
Paths 67

Size

Total Lines 54
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 33
nc 67
nop 1
dl 0
loc 54
rs 7.6666
c 0
b 0
f 0

How to fix   Long Method    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\Http\Controllers\VirtualJudge\Core;
7
use Requests, Exception;
8
9
class Judge extends Core
10
{
11
    private $MODEL;
12
    public $ret=[];
13
    public function __construct()
14
    {
15
        $this->MODEL=new SubmissionModel();
16
        $ret=[];
17
18
        $uva_v=[
0 ignored issues
show
Unused Code introduced by
The assignment to $uva_v is dead and can be removed.
Loading history...
19
            'Wrong answer'=>"Wrong Answer",
20
            'Accepted'=>"Accepted",
21
            'Runtime error'=>"Runtime Error",
22
            'Time limit exceeded'=>"Time Limit Exceed",
23
            'Presentation error'=>"Presentation Error",
24
            'Submission error'=>'Submission Error',
25
            'Compilation error'=>"Compile Error",
26
            'Output Limit Exceeded'=>"Output Limit Exceeded",
27
        ];
28
29
        $codeforces_v=[
30
            "COMPILATION_ERROR"=>"Compile Error",
31
            "RUNTIME_ERROR"=> "Runtime Error",
32
            "WRONG_ANSWER"=> "Wrong Answer",
33
            "TIME_LIMIT_EXCEEDED"=>"Time Limit Exceed" ,
34
            "OK"=>"Accepted" ,
35
            "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed",
36
            "PRESENTATION_ERROR"=>"Presentation Error"];
37
38
        $spoj_v=[
0 ignored issues
show
Unused Code introduced by
The assignment to $spoj_v is dead and can be removed.
Loading history...
39
            "compilation error"=>"Compile Error",
40
            "runtime error"=> "Runtime Error",
41
            "wrong answer"=> "Wrong Answer",
42
            "time limit exceeded"=>"Time Limit Exceed",
43
            "accepted"=>"Accepted"
44
        ];
45
46
        $contesthunter_v=[
47
            '正确'=>"Accepted",
48
            '答案错误'=>"Wrong Answer",
49
            '超出时间限制'=>"Time Limit Exceed",
50
            '运行时错误'=>"Runtime Error",
51
            "超出内存限制"=>"Memory Limit Exceed",
52
            '比较器错误'=>'Submission Error',
53
            '超出输出限制'=>"Output Limit Exceeded",
54
            '编译错误'=>"Compile Error",
55
        ];
56
57
        $poj_v=[
58
            'Accepted'=>"Accepted",
59
            "Presentation Error"=>"Presentation Error",
60
            'Time Limit Exceeded'=>"Time Limit Exceed",
61
            "Memory Limit Exceeded"=>"Memory Limit Exceed",
62
            'Wrong Answer'=>"Wrong Answer",
63
            'Runtime Error'=>"Runtime Error",
64
            'Output Limit Exceeded'=>"Output Limit Exceeded",
65
            'Compile Error'=>"Compile Error",
66
        ];
67
68
        $vijos_v=[
69
            'Accepted'=>"Accepted",
70
            'Wrong Answer'=>"Wrong Answer",
71
            'Time Exceeded'=>"Time Limit Exceed",
72
            "Memory Exceeded"=>"Memory Limit Exceed",
73
            'Runtime Error'=>"Runtime Error",
74
            'Compile Error'=>"Compile Error",
75
            'System Error'=>"Submission Error",
76
            'Canceled'=>"Submission Error",
77
            'Unknown Error'=>"Submission Error",
78
            'Ignored'=>"Submission Error",
79
        ];
80
81
        $pta_v=[
82
            'ACCEPTED'=>"Accepted",
83
            'COMPILE_ERROR'=>"Compile Error",
84
            'FLOAT_POINT_EXCEPTION'=>"Runtime Error",
85
            'INTERNAL_ERROR'=>"Submission Error",
86
            "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed",
87
            'MULTIPLE_ERROR'=>"Runtime Error",
88
            'NON_ZERO_EXIT_CODE'=>"Runtime Error",
89
            'NO_ANSWER'=>"Compile Error",
90
            'OUTPUT_LIMIT_EXCEEDED'=>"Output Limit Exceeded",
91
            'OVERRIDDEN'=>"Submission Error",
92
            'PARTIAL_ACCEPTED'=>"Partially Accepted",
93
            "PRESENTATION_ERROR"=>"Presentation Error",
94
            'RUNTIME_ERROR'=>"Runtime Error",
95
            'SAMPLE_ERROR'=>"Wrong Answer",
96
            'SEGMENTATION_FAULT'=>"Runtime Error",
97
            'SKIPPED'=>"Submission Error",
98
            'TIME_LIMIT_EXCEEDED'=>"Time Limit Exceed",
99
            'WRONG_ANSWER'=>"Wrong Answer",
100
        ];
101
102
        $result=$this->MODEL->get_wating_submission();
103
        $judger=new JudgerModel();
104
        $curl = new Curl();
105
106
        $cf=$this->get_last_codeforces($this->MODEL->count_wating_submission(2));
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $cf is correct as $this->get_last_codeforc...t_wating_submission(2)) targeting App\Http\Controllers\Vir...::get_last_codeforces() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
107
        $poj=[];
108
109
        $pojJudgerList=$judger->list(4);
110
        $pojJudgerName=urlencode($pojJudgerList[0]["handle"]);
111
        if ($this->MODEL->count_wating_submission(5)) $this->appendPOJStatus($poj, $pojJudgerName);
112
        // $uva=$this->get_last_uva($this->MODEL->count_wating_submission('Uva'));
113
        // $uval=$this->get_last_uvalive($this->MODEL->count_wating_submission('UvaLive'));
114
        // $sj=$this->get_last_spoj($this->MODEL->count_wating_submission('Spoj'));
115
116
        $i=0;
117
        $j=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $j is dead and can be removed.
Loading history...
118
        $k=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $k is dead and can be removed.
Loading history...
119
        $l=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $l is dead and can be removed.
Loading history...
120
        foreach ($result as $row) {
121
            if ($row['oid']==2) {
122
                if (isset($codeforces_v[$cf[$i][2]])) {
123
124
                    $sub['verdict'] = $codeforces_v[$cf[$i][2]];
125
                    $sub["score"]=$sub['verdict']=="Accepted"?1:0;
126
                    $sub['time'] = $cf[$i][0];
127
                    $sub['memory'] = $cf[$i][1];
128
                    $sub['remote_id'] = $cf[$i][3];
129
130
                    $ret[$row['sid']] = [
131
                        "verdict"=>$sub['verdict']
132
                    ];
133
134
                    $this->MODEL->update_submission($row['sid'], $sub);
135
                }
136
                $i++;
137
            } else if ($row['oid'] == 3) {
138
                try {
139
                    $res = Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']);
140
                    preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match);
141
                    $status = $match[1];
142
                    if (!array_key_exists($status, $contesthunter_v)) continue;
143
                    $sub['verdict'] = $contesthunter_v[$status];
144
                    $sub["score"]=$sub['verdict']=="Accepted"?1:0;
145
                    $sub['remote_id'] = $row['remote_id'];
146
                    if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") {
147
                        preg_match('/占用内存[\s\S]*?(\d+).*?KiB/m', $res->body, $match);
148
                        $sub['memory'] = $match[1];
149
                        $maxtime = 0;
150
                        preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches);
151
                        foreach ($matches[1] as $time) {
152
                            if ($time < $maxtime) $maxtime = $time;
153
                        }
154
                        $sub['time'] = $maxtime;
155
                    } else {
156
                        $sub['memory'] = 0;
157
                        $sub['time'] = 0;
158
                    }
159
160
                    $ret[$row['sid']] = [
161
                        "verdict"=>$sub['verdict']
162
                    ];
163
                    $this->MODEL->update_submission($row['sid'], $sub);
164
                }
165
                catch(Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
166
            } else if ($row['oid'] == 4) {
167
                if (!isset($poj[$row['remote_id']])) {
168
                    $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']);
169
                    if (!isset($poj[$row['remote_id']])) continue;
170
                }
171
                $status = $poj[$row['remote_id']];
172
                $sub['verdict'] = $poj_v[$status['verdict']];
173
                $sub["score"]=$sub['verdict']=="Accepted"?1:0;
174
                $sub['time'] = $status['time'];
175
                $sub['memory'] = $status['memory'];
176
                $sub['remote_id'] = $row['remote_id'];
177
178
                $ret[$row['sid']] = [
179
                    "verdict"=>$sub['verdict']
180
                ];
181
                $this->MODEL->update_submission($row['sid'], $sub);
182
            } else if ($row['oid'] == 5) {
183
                try {
184
                    $res = Requests::get('https://vijos.org/records/'.$row['remote_id']);
185
                    preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match);
186
                    $status = $match[1];
187
                    if (!array_key_exists($status, $vijos_v)) continue;
188
                    $sub['verdict'] = $vijos_v[$status];
189
                    preg_match('/<dt>分数<\/dt>\s*<dd>(\d+)<\/dd>/', $res->body, $match);
190
                    $sub['score'] = $match[1];
191
                    if ($sub['verdict'] == "Wrong Answer" && $sub['score'] != 0) $sub['verdict'] = 'Partially Accepted';
192
                    $sub['remote_id'] = $row['remote_id'];
193
                    if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") {
194
                        $maxtime = 0;
195
                        preg_match_all('/<td class="col--time">(?:&ge;)?(\d+)ms<\/td>/', $res->body, $matches);
196
                        foreach ($matches as $match) {
197
                            if ($match[1] > $maxtime) $maxtime = $match[1];
198
                        }
199
                        $sub['time'] = $maxtime;
200
                        preg_match('/<dt>峰值内存<\/dt>\s*<dd>(?:&ge;)?([\d.]+) ([KM])iB<\/dd>/', $res->body, $match);
201
                        $memory = $match[1];
202
                        if ($match[2] == 'M') $memory *= 1024;
203
                        $sub['memory'] = intval($memory);
204
                    } else {
205
                        $sub['memory'] = 0;
206
                        $sub['time'] = 0;
207
                    }
208
209
                    $ret[$row['sid']] = [
210
                        "verdict"=>$sub['verdict']
211
                    ];
212
                    $this->MODEL->update_submission($row['sid'], $sub);
213
                }
214
                catch(Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
215
            } else if ($row['oid'] == 6) {
216
                try {
217
                    $remoteId = explode('|', $row['remote_id']);
218
                    $response = $curl->grab_page("https://pintia.cn/api/problem-sets/$remoteId[0]/submissions/".$remoteId[1], 'pta');
219
                    $data = json_decode($response, true);
220
                    if (!isset($pta_v[$data['submission']['status']])) continue;
221
                    $sub['verdict'] = $pta_v[$data['submission']['status']];
222
                    $sub['score'] = $data['submission']['score'];
223
                    $sub['remote_id'] = $row['remote_id'];
224
                    $sub['memory'] = $data['submission']['memory'] / 1024;
225
                    $sub['time'] = $data['submission']['time'] * 1000;
226
227
                    $ret[$row['sid']] = [
228
                        "verdict"=>$sub['verdict']
229
                    ];
230
                    $this->MODEL->update_submission($row['sid'], $sub);
231
                }
232
                catch(Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
233
            }
234
            // if ($row['oid']=='Spoj') {
235
            //     if (isset($spoj_v[$sj[$j][2]])) {
236
            //         $sub['verdict']=$spoj_v[$sj[$j][2]];
237
            //         $sub['time']=$sj[$j][0];
238
            //         $sub['memory']=$sj[$j][1];
239
            //         $v=$sub['verdict'];
240
            //         $ret[$row['sid']]="<div style='color:{$color[$v]};'>"  .$sub['Verdict']. "</div>";
241
            //         $this->MODEL->update_submission($row['sid'], $sub);
242
            //     }
243
            //     $j++;
244
            // }
245
            // if ($row['oid']=='Uva') {
246
            //     if (isset($uva_v[$uva[$k][2]])) {
247
            //         $sub['verdict']=$uva_v[$uva[$k][2]];
248
            //         $sub['time']=$uva[$k][0];
249
            //         $sub['memory']=$uva[$k][1];
250
            //         $v=$sub['verdict'];
251
            //         $ret[$row['sid']]="<div style='color:{$color[$v]};'>"  .$sub['Verdict']. "</div>";
252
            //         $this->MODEL->update_submission($row['sid'], $sub);
253
            //     }
254
            //     $k++;
255
            // }
256
            // if ($row['oid']=='UvaLive') {
257
            //     if (isset($uva_v[$uval[$l][2]])) {
258
            //         $sub['verdict']=$uva_v[$uval[$l][2]];
259
            //         $sub['time']=$uval[$l][0];
260
            //         $sub['memory']=$uval[$l][1];
261
            //         $v=$sub['verdict'];
262
            //         $ret[$row['sid']]="<div style='color:{$color[$v]};'>"  .$sub['Verdict']. "</div>";
263
            //         $this->MODEL->update_submission($row['sid'], $sub);
264
            //     }
265
            //     $l++;
266
            // }
267
        }
268
        $this->ret=$ret;
269
    }
270
    /**
271
     * [Not Finished] Get last time UVa submission by using API.
272
     *
273
     * @param integer $num
274
     *
275
     * @return void
276
     */
277
    private function get_last_uva($num)
0 ignored issues
show
Unused Code introduced by
The method get_last_uva() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
278
    {
279
        $ret=array();
280
        if ($num==0) {
281
            return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type array which is incompatible with the documented return type void.
Loading history...
282
        }
283
        $response=$this->grab_page('https://uva.onlinejudge.org', 'uva');
284
        if (!(strpos($response, 'UVa Online Judge - Offline') !== false)) {
285
            $this->uva_live_login('https://uva.onlinejudge.org', 'https://uva.onlinejudge.org/index.php?option=com_comprofiler&task=login', 'uva');
286
        } else {
287
            return $ret;
288
        }
289
290
        $i=0;
291
        while (true) {
292
            $response=$this->grab_page("https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9&limit=50&limitstart={$i}", 'uva');
293
294
            $exploded = explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response);
295
            $table = explode('</table>', $exploded[1])[0];
296
297
            $table = explode('<tr class="sectiontableentry', $table);
298
299
            for ($j=1;$j<count($table);$j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
300
                $num--;
301
                $sub=$table[$j];
302
303
                $sub = explode('<td>', $sub);
304
                $verdict=explode('</td>', $sub[3])[0];
305
                $time=explode('</td>', $sub[5])[0];
306
307
                if ((strpos($verdict, '<a href=') !== false)) {
308
                    $verdict=explode('</a', explode('>', explode('<a href=', $verdict)[1])[1])[0];
309
                }
310
311
                array_push($ret, array($time*1000,-1,$verdict));
312
313
                if ($num==0) {
314
                    return array_reverse($ret);
315
                }
316
            }
317
            $i+=50;
318
        }
319
    }
320
321
    /**
322
     * [Not Finished] Get last time UVa Live submission by using API.
323
     *
324
     * @param integer $num
325
     *
326
     * @return void
327
     */
328
    private function get_last_uvalive($num)
0 ignored issues
show
Unused Code introduced by
The method get_last_uvalive() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
329
    {
330
        $ret=array();
331
        if ($num==0) {
332
            return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type array which is incompatible with the documented return type void.
Loading history...
333
        }
334
335
        $this->uva_live_login('https://icpcarchive.ecs.baylor.edu', 'https://icpcarchive.ecs.baylor.edu/index.php?option=com_comprofiler&task=login', 'uvalive');
0 ignored issues
show
Bug introduced by
The method uva_live_login() does not exist on App\Http\Controllers\VirtualJudge\Judge. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

335
        $this->/** @scrutinizer ignore-call */ 
336
               uva_live_login('https://icpcarchive.ecs.baylor.edu', 'https://icpcarchive.ecs.baylor.edu/index.php?option=com_comprofiler&task=login', 'uvalive');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
336
337
        $i=0;
338
        while (true) {
339
            $response=$this->grab_page("https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=9&limit=50&limitstart={$i}", 'uvalive');
340
341
            $exploded = explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response);
342
            $table = explode('</table>', $exploded[1])[0];
343
344
            $table = explode('<tr class="sectiontableentry', $table);
345
346
            for ($j=1;$j<count($table);$j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
347
                $num--;
348
                $sub=$table[$j];
349
350
                $sub = explode('<td>', $sub);
351
                $verdict=explode('</td>', $sub[3])[0];
352
                $time=explode('</td>', $sub[5])[0];
353
354
                if ((strpos($verdict, '<a href=') !== false)) {
355
                    $verdict=explode('</a', explode('>', explode('<a href=', $verdict)[1])[1])[0];
356
                }
357
358
                array_push($ret, array($time*1000,-1,$verdict));
359
360
                if ($num==0) {
361
                    return array_reverse($ret);
362
                }
363
            }
364
            $i+=50;
365
        }
366
    }
367
368
369
    /**
370
     * [Not Finished] Get last time CodeForces submission by using API.
371
     *
372
     * @param integer $num
373
     *
374
     * @return void
375
     */
376
    private function get_last_codeforces($num)
377
    {
378
        $ret=array();
379
        if ($num==0) {
380
            return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type array which is incompatible with the documented return type void.
Loading history...
381
        }
382
383
        $ch=curl_init();
384
        $url="http://codeforces.com/api/user.status?handle=codemaster4&from=1&count={$num}";
385
        curl_setopt($ch, CURLOPT_URL, $url);
386
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
387
        $response=curl_exec($ch);
388
        curl_close($ch);
389
        $result=json_decode($response, true);
390
        if ($result["status"]=="OK") {
391
            for ($i=0;$i<$num;$i++) {
392
                if (!isset($result["result"][$i]["verdict"])) {
393
                    return array_reverse($ret);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_reverse($ret) returns the type array which is incompatible with the documented return type void.
Loading history...
394
                }
395
                array_push($ret, array($result["result"][$i]["timeConsumedMillis"],$result["result"][$i]["memoryConsumedBytes"]/1000,$result["result"][$i]["verdict"],$result["result"][$i]["id"]));
396
            }
397
        }
398
        return array_reverse($ret);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_reverse($ret) returns the type array which is incompatible with the documented return type void.
Loading history...
399
    }
400
401
    /**
402
     * [Not Finished] Get last time SPOJ submission by using API.
403
     *
404
     * @param integer $num
405
     *
406
     * @return void
407
     */
408
    private function get_last_spoj($num)
0 ignored issues
show
Unused Code introduced by
The method get_last_spoj() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
409
    {
410
        $ret=array();
411
        if ($num==0) {
412
            return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type array which is incompatible with the documented return type void.
Loading history...
413
        }
414
415
        $i=0;
416
        while (true) {
417
            $response=file_get_contents("http://www.spoj.com/status/our_judge/all/start={$i}");
418
419
420
            $exploded = explode('<table class="problems table newstatus">', $response);
421
            $table = explode('</table>', $exploded[1])[0];
422
423
            $table = explode('<td class="statustext text-center">', $table);
424
425
            for ($j=1;$j<count($table);$j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
426
                $num--;
427
                $sub=$table[$j];
428
429
430
                $verdict=explode('</td>', explode('manual="0">', explode('<td class="statusres text-center"', $sub)[1])[1])[0];
431
                if ((strpos($verdict, '<strong>') !== false)) {
432
                    $verdict=explode('</strong>', explode('<strong>', $verdict)[1])[0];
433
                }
434
435
                if ((strpos($verdict, '(') !== false)) {
436
                    $verdict=explode('(', $verdict)[0];
437
                }
438
                if (is_numeric(trim($verdict))) {
439
                    $verdict='accepted';
440
                }
441
442
                $time=explode('</a>', explode('title="See the best solutions">', $sub)[1])[0];
443
                $time=trim($time);
444
                if ($time=='-') {
445
                    $time=0;
446
                }
447
448
                $memory=explode('</td', explode('>', explode('<td class="smemory statustext text-center"', $sub)[1])[1])[0];
449
                $memory=trim($memory);
450
                if ($memory=='-') {
451
                    $memory=0;
452
                } else {
453
                    $memory=substr($memory, 0, strlen($memory)-1);
454
                }
455
456
                array_push($ret, array($time*1000,$memory*1000,trim($verdict)));
457
                if ($num==0) {
458
                    return array_reverse($ret);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_reverse($ret) returns the type array which is incompatible with the documented return type void.
Loading history...
459
                }
460
            }
461
            $i+=20;
462
        }
463
    }
464
465
    private function appendPOJStatus(&$results, $judger, $first = null)
466
    {
467
        if ($first !== null) $first++;
468
        $res = Requests::get("http://poj.org/status?user_id={$judger}&top={$first}");
469
        $rows = preg_match_all('/<tr align=center><td>(\d+)<\/td><td>.*?<\/td><td>.*?<\/td><td>.*?<font color=.*?>(.*?)<\/font>.*?<\/td><td>(\d*)K?<\/td><td>(\d*)(?:MS)?<\/td>/', $res->body, $matches);
470
        for ($i = 0; $i < $rows; $i++) {
471
            $results[$matches[1][$i]] = [
472
                'verdict'=>$matches[2][$i],
473
                'memory'=>$matches[3][$i] ? $matches[3][$i] : 0,
474
                'time'=>$matches[4][$i] ? $matches[4][$i] : 0,
475
            ];
476
        }
477
    }
478
}
479