Completed
Push — master ( ec1826...17149c )
by Taosikai
15:14
created

Controller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A renderView() 0 4 1
A render() 0 5 1
A get() 0 4 1
A json() 0 9 2
1
<?php
2
3
/*
4
 * This file is part of the jade/jade package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jade\Controller;
13
14
use Jade\ContainerAwareInterface;
15
use Jade\ContainerAwareTrait;
16
use Zend\Diactoros\Response;
17
18
class Controller implements ContainerAwareInterface
19
{
20
    use ContainerAwareTrait;
21
22
    /**
23
     * 渲染模板
24
     * @param string $view
25
     * @param array $parameters
26
     * @return string
27
     */
28
    protected function renderView($view, array $parameters = [])
29
    {
30
        return $this->container->get('twig')->render($view, $parameters);
31
    }
32
33
    /**
34
     * 渲染模板
35
     *
36
     * @param string $view
37
     * @param array $parameters
38
     * @return Response\HtmlResponse
39
     */
40
    protected function render($view, array $parameters = [])
41
    {
42
        $content = $this->renderView($view, $parameters);
43
        return new Response\HtmlResponse($content);
44
    }
45
46
    /**
47
     * @param string $id
48
     * @return mixed
49
     */
50
    protected function get($id)
51
    {
52
        return $this->container->get($id);
53
    }
54
55
    /**
56
     * Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
57
     *
58
     * @final
59
     */
60
    protected function json($data, int $status = 200, array $headers = [], array $context = [])
61
    {
62
        if ($this->container->has('serializer')) {
63
            $json = $this->container->get('serializer')->serialize($data, 'json', array_merge([
0 ignored issues
show
Unused Code introduced by
$json is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
64
                'json_encode_options' => Response\JsonResponse::DEFAULT_JSON_FLAGS,
65
            ], $context));
66
        }
67
        return new Response\JsonResponse($data, $status, $headers);
68
    }
69
}