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.

SftpMonitoring   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getMetric() 0 15 4
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
 * "Sftp" : {
10
 *         "name" : "Name of metric and alarm",
11
 *         "addr": "127.0.0.1",
12
 *         "port": "22",
13
 *         "login": "login",
14
 *         "password": "password",
15
 *         "namespace": "Metric/Namespace",
16
 *         "description": "Descrption"
17
 * }
18
 */
19
class SftpMonitoring extends AbstractMonitoring
20
{
21
    private $addr;
22
    private $port;
23
    private $login;
24
    private $password;
25
    /**
26
     * @param array $config
27
     * @param String $name
28
     */
29
    public function __construct($config, $name)
30
    {
31
        parent::__construct($config, $name);
32
        $this->addr = $this->config->addr;
33
        $this->port = $this->config->port;
34
        $this->login = $this->config->login;
35
        $this->password = $this->config->password;
36
    }
37
    /**
38
     * Check solr ping url.
39
     * @return metric 0 KO, 1 OK
40
     */
41
    public function getMetric()
42
    {
43
        $connection = ssh2_connect($this->addr, $this->port);
44
        if ($connection === false) {
45
            return 0;
46
        }
47
        if (ssh2_auth_password($connection, $this->login, $this->password) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
48
            return 0;
49
        }
50
        $sftp = ssh2_sftp($connection);
51
        if ($sftp === false) {
52
            return 0;
53
        }
54
        return 1;
55
    }
56
    /**
57
     * @return string "None"
58
     */
59
    public function getUnit()
60
    {
61
        return "None";
62
    }
63
    /**
64
     * @return integer 1
65
     */
66
    public function getAlarms()
67
    {
68
        return array(
69
                    array("ComparisonOperator" => "LessThanThreshold",
70
                          "Threshold" => 1,
71
                          "Name" => $this->name)
72
                    );
73
    }
74
}
75