Completed
Push — master ( 98a7a2...4b25fc )
by Elan
01:09
created

Xhgui_Controller_Metrics   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A metrics() 0 22 1
1
<?php
2
3
use Slim\Slim;
4
5
class Xhgui_Controller_Metrics extends Xhgui_Controller
6
{
7
    /**
8
     * @var Xhgui_Searcher_Interface
9
     */
10
    protected $searcher;
11
12
    public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
13
    {
14
        parent::__construct($app);
15
        $this->searcher = $searcher;
16
    }
17
18
    public function metrics()
19
    {
20
        $request = $this->app->request();
0 ignored issues
show
Unused Code introduced by
$request is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
        $response = $this->app->response();
22
23
        $stats = $this->searcher->stats();
24
25
        $body = "# HELP xhgui_profiles_total Number of profiles collected.\n";
26
        $body .= "# TYPE xhgui_profiles_total gauge\n";
27
        $body .= sprintf("xhgui_profiles_total %0.1F\n\n", $stats['profiles']);
28
29
        $body .= "# HELP xhgui_profile_bytes_total Size of profiles collected.\n";
30
        $body .= "# TYPE xhgui_profile_bytes_total gauge\n";
31
        $body .= sprintf("xhgui_profile_bytes_total %0.1F\n\n", $stats['bytes']);
32
33
        $body .= "# HELP xhgui_latest_profile_seconds UNIX timestamp of most recent profile.\n";
34
        $body .= "# TYPE xhgui_latest_profile_seconds gauge\n";
35
        $body .= sprintf("xhgui_latest_profile_seconds %0.1F\n", $stats['latest']);
36
37
        $response->body($body);
38
        $response['Content-Type'] = 'text/plain; version=0.0.4';
39
    }
40
}
41