Completed
Pull Request — master (#302)
by Elan
01:07
created

Xhgui_Controller_Export::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
use Slim\Slim;
4
use Tideways\Xhprof\CachegrindConverter;
5
6
class Xhgui_Controller_Export extends Xhgui_Controller
7
{
8
    /** @var CachegrindConverter */
9
    private $converter;
10
11
    /** @var Xhgui_Searcher_Interface */
12
    private $searcher;
13
14
    public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
15
    {
16
        parent::__construct($app);
17
        $this->searcher = $searcher;
18
        $this->converter = new CachegrindConverter();
19
    }
20
21
    public function cachegrind()
22
    {
23
        $request = $this->app->request();
24
        $id = $request->get('id');
25
26
        $profile = $this->searcher->get($id);
27
        $output = $this->converter->convertToCachegrind($profile->toArray()['profile']);
28
29
        $response = $this->app->response();
30
        $response['Content-Type'] = 'application/octet-stream';
31
        $response['Cache-Control'] = 'public, max-age=60, must-revalidate';
32
        $response['Content-Disposition'] = sprintf('attachment; filename=cachegrind-%s.out', $id);
33
        $response->body($output);
0 ignored issues
show
Bug introduced by
The method body cannot be called on $response (of type array<string,string,{"Co...Disposition":"string"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
    }
35
}
36