Completed
Push — master ( c564cb...34935e )
by Mark
02:40
created

Xhgui_Controller_Import::import()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
use Slim\Slim;
4
5
class Xhgui_Controller_Import extends Xhgui_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * @var Xhgui_Saver_Mongo
9
     */
10
    private $saver;
11
12
    public function __construct(Slim $app, Xhgui_Saver_Mongo $saver)
13
    {
14
        $this->app = $app;
15
        $this->saver = $saver;
16
    }
17
18
    public function import()
19
    {
20
        $request = $this->app->request();
21
        $response = $this->app->response();
22
23
        $data = json_decode($request->getBody(), true);
24
        $this->saver->save($data);
25
26
        $response['Content-Type'] = 'application/json';
27
        $response->body(json_encode(['ok' => true]));
0 ignored issues
show
Bug introduced by
The method body cannot be called on $response (of type array<string,string,{"Content-Type":"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...
28
    }
29
}
30