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

Xhgui_Controller_Metrics::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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