Completed
Push — master ( 9bb285...104bd6 )
by Alexander
03:14
created

RestController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 2
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 24 2
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');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
        $this->response->setContentType($contentType, $encoding);
47
        $this->response->setContent($content);
48
49
        return $this->response->send();
50
    }
51
}
52