Passed
Push — master ( 49f1ef...b2146d )
by John
05:49 queued 11s
created

Monitor::create()   A

Complexity

Conditions 5
Paths 14

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 13
c 1
b 0
f 1
nc 14
nop 1
dl 0
loc 15
rs 9.5222
1
<?php
2
3
namespace App\Babel\Monit;
4
5
use ErrorException;
6
use Exception;
7
use Throwable;
8
9
class Monitor
10
{
11
12
    /**
13
     * Initial
14
     *
15
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Babel\Monit\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)
18
    {
19
        $monitor=self::create($conf);
20
        if (!is_null($monitor) && isset($crawler)) $monitor->check();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $crawler seems to never exist and therefore isset should always be false.
Loading history...
21
    }
22
23
    public static function create($conf) {
24
        $name=$conf["name"];
25
        $monitorProvider="Monitor";
26
        try {
27
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$name/babel.json")), true);
28
            $monitorProvider=$BabelConfig["provider"]["monitor"];
29
        } catch(Throwable $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
30
        } catch(ErrorException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
31
        } catch(Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
32
        }
33
        $className = "App\\Babel\\Extension\\$name\\$monitorProvider";
34
        if(class_exists($className)) {
35
            return new $className();
36
        } else {
37
            return null;
38
        }
39
    }
40
}
41