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

ApiPresenter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 29
ccs 8
cts 11
cp 0.7272
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A actionDefault() 0 10 2
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