Completed
Push — master ( ebee1b...83e9b5 )
by Samuel
02:50
created

ApiPresenter::actionDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 4
cts 7
cp 0.5714
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2.3149
1
<?php
2
3
namespace Kelemen\ApiNette\Presenter;
4
5
use Kelemen\ApiNette\Api;
6
use Kelemen\ApiNette\Exception\ApiNetteException;
7
use Nette\Application\UI\Presenter;
8
use Nette\Http\IResponse;
9
use Kelemen\ApiNette\Response\JsonApiResponse;
10
use Tracy\Debugger;
11
12
class ApiPresenter extends Presenter
13
{
14
    /** @var Api */
15
    private $api;
16
17
    /**
18
     * @param Api $api
19
     */
20 2
    public function __construct(Api $api)
21
    {
22 2
        parent::__construct();
23 2
        $this->api = $api;
24 2
    }
25
26
    /**
27
     * Run api handling
28
     * @param $params
29
     */
30 2
    public function actionDefault($params)
31
    {
32
        try {
33 2
            $response = $this->api->run($params);
34 1
        } catch (ApiNetteException $e) {
35
            Debugger::log($e, 'error');
36
            $response = new JsonApiResponse(IResponse::S500_INTERNAL_SERVER_ERROR, ['error' => 'Internal server error']);
37
        }
38 2
        $this->sendResponse($response);
39
    }
40
}
41