Completed
Push — master ( a4261d...fc5e52 )
by John
14s
created

Crawler::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Babel\Crawl;
4
5
use App\Models\ProblemModel;
6
use Auth;
7
8
class Crawler
9
{
10
    public $data=null;
11
12
    /**
13
     * Initial
14
     *
15
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Babel\Crawl\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
16
     */
17
    public function __construct($conf, $commandLineObject=null)
18
    {
19
        $crawler=self::create($conf, $commandLineObject);
20
        if (!is_null($crawler) && isset($crawler)) $crawler->start($conf);
21
    }
22
23
    public static function create($conf, $commandLineObject=null) {
24
        $name=$conf["name"];
25
        $crawlerProvider="Crawler";
26
        try {
27
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$name/babel.json")), true);
28
            $crawlerProvider=$BabelConfig["provider"]["crawler"];
29
        } catch(ErrorException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The type App\Babel\Crawl\ErrorException was not found. Did you mean ErrorException? If so, make sure to prefix the type with \.
Loading history...
30
        } catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The type App\Babel\Crawl\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...
31
        }
32
        $className = "App\\Babel\\Extension\\$name\\$crawlerProvider";
33
        if(class_exists($className)) {
34
            $temp=new $className();
35
            $temp->importCommandLine($commandLineObject);
36
            return $temp;
37
        } else {
38
            return null;
39
        }
40
    }
41
}
42