Crawler::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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