GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HttpMonitoring   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 45
rs 10
c 1
b 0
f 0
wmc 6
lcom 2
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMetric() 0 8 3
A getUnit() 0 4 1
A getAlarms() 0 8 1
1
<?php
2
namespace CloudWatchScript\Plugins;
3
4
use CloudWatchScript\AbstractMonitoring;
5
6
/**
7
 * Check Solr using ping URL.
8
 * Add and configure the folliwong lines to the config file
9
 * "Http" : {
10
 *         "name" : "Name of metric and alarm",
11
 *         "url": "http://localhost:8080/solr/collection1/admin/ping",
12
 *         "pattern": "ds",
13
 *         "namespace": "Metric/Namespace",
14
 *         "description": "Descrption"
15
 * }
16
 */
17
class HttpMonitoring extends AbstractMonitoring
18
{
19
    private $url;
20
    private $pattern;
21
    /**
22
     * @param array $config
23
     * @param String $name
24
     */
25
    public function __construct($config, $name)
26
    {
27
        parent::__construct($config, $name);
28
        $this->url = $this->config->url;
29
        $this->pattern = $this->config->pattern;
30
    }
31
    /**
32
     * Check solr ping url.
33
     * @return metric 0 Ok, 1 KO
34
     */
35
    public function getMetric()
36
    {
37
        $result = @file_get_contents($this->url);
38
        if ($result === false) {
39
            return 0;
40
        }
41
        return ereg($this->pattern, $result)==true?"1":"0";
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing ereg($this->pattern, $result) of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
42
    }
43
    /**
44
     * @return string "None"
45
     */
46
    public function getUnit()
47
    {
48
        return "None";
49
    }
50
    /**
51
     * @return integer 1
52
     */
53
    public function getAlarms()
54
    {
55
        return array(
56
                    array("ComparisonOperator" => "LessThanThreshold",
57
                          "Threshold" => 1,
58
                          "Name" => $this->name)
59
                    );
60
    }
61
}
62