Passed
Pull Request — master (#235)
by John
05:34
created

Monitor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 32
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 5
A __construct() 0 5 3
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)) {
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
            $monitor->check();
22
        }
23
    }
24
25
    public static function create($conf)
26
    {
27
        $name=$conf["name"];
28
        $monitorProvider="Monitor";
29
        try {
30
            $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$name/babel.json")), true);
31
            $monitorProvider=$BabelConfig["provider"]["monitor"];
32
        } catch (Throwable $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
33
        } catch (ErrorException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
34
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
35
        }
36
        $className = "App\\Babel\\Extension\\$name\\$monitorProvider";
37
        if (class_exists($className)) {
38
            return new $className();
39
        } else {
40
            return null;
41
        }
42
    }
43
}
44