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.
Completed
Push — master ( 0b4be3...13043e )
by Frédéric
02:24
created

MemoryMonitoring   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 8
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMetric() 0 10 1
A getUnit() 0 4 1
A getAlarms() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * "Memory" : {
10
 *         "name" : "Name of metric and alarm",
11
 *         "maxUsed": 90,
12
 *         "namespace": "Metric/Namespace",
13
 *         "description": "Description"
14
 * }
15
 */
16
class MemoryMonitoring extends AbstractMonitoring
17
{
18
    private $maxUsed;
19
20
    /**
21
     * @param array $config
22
     * @param String $name
23
     */
24
    public function __construct($config, $name)
25
    {
26
        parent::__construct($config, $name);
27
        $this->maxUsed = $this->config->maxUsed;
28
    }
29
30
    /**
31
     * @return integer Percentage of use memory
32
     */
33
    public function getMetric()
34
    {
35
        $free = shell_exec('free');
36
        $free = (string)trim($free);
37
        $free_arr = explode("\n", $free);
38
        $mem = explode(" ", $free_arr[1]);
39
        $mem = array_filter($mem);
40
        $mem = array_merge($mem);
41
        return ( $mem[2] - $mem[5] )/$mem[1]*100;
42
    }
43
44
    /**
45
     * @return string "None"
46
     */
47
    public function getUnit()
48
    {
49
        return "Percent";
50
    }
51
52
    /**
53
     * @return array Alarm max for memory used
54
     */
55 View Code Duplication
    public function getAlarms()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        return array(
58
                array("ComparisonOperator" => "GreaterThanThreshold",
59
                        "Threshold" => $this->maxUsed,
60
                        "Name" => $this->name . " exceed " . $this->config->maxUtil . " %")
61
        );
62
      }
63
  }
64