RestController::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: djavolak
5
 * Date: 10.9.16.
6
 * Time: 16.11
7
 */
8
9
namespace Api\Controller;
10
11
/**
12
 * Class RestController.
13
 * Base class for all controllers for REST API.
14
 *
15
 * @package Api\Controller
16
 */
17
class RestController extends \Application\Mvc\Controller
18
{
19
20
    /**
21
     * Render data from payload
22
     *
23
     * @throws \Api\Exception\NotImplementedException
24
     *
25
     * @return \Phalcon\Http\ResponseInterface
26
     */
27
    protected function render(\Api\Model\Payload $payload)
28
    {
29
        $format = $this->request->getQuery('format', null, 'json');
30
31
        switch ($format)
32
        {
33
            case 'json':
34
                $contentType = 'application/json';
35
                $encoding = 'UTF-8';
36
                $content = json_encode($payload->toArray());
37
                break;
38
            default:
39
                throw new \Api\Exception\NotImplementedException(
40
                    sprintf('Requested format %s is not supported yet.', $format)
41
                );
42
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
43
        }
44
45
//        $this->response->setStatusCode(200, 'OK');
46
        $this->response->setContentType($contentType, $encoding);
47
        $this->response->setContent($content);
48
49
        return $this->response->send();
50
    }
51
}
52