Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

VersionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
ccs 0
cts 19
cp 0
rs 9.4285
cc 1
eloc 16
nc 1
nop 7
crap 2
1
<?php
2
/**
3
 * Controller for core/version endpoint
4
 */
5
6
namespace Graviton\CoreBundle\Controller;
7
8
use Graviton\CoreBundle\Service\CoreUtils;
9
use Graviton\RestBundle\Controller\RestController;
10
use Graviton\RestBundle\Service\RestUtilsInterface;
11
use Graviton\SchemaBundle\SchemaUtils;
12
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Bundle\FrameworkBundle\Routing\Router;
17
18
/**
19
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
20
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
21
 * @link     http://swisscom.ch
22
 */
23
class VersionController extends RestController
24
{
25
    /**
26
     * @var CoreUtils
27
     */
28
    private $coreUtils;
29
30
    /**
31
     * @param Response           $response    Response
32
     * @param RestUtilsInterface $restUtils   Rest utils
33
     * @param Router             $router      Router
34
     * @param EngineInterface    $templating  Templating
35
     * @param ContainerInterface $container   Container
36
     * @param SchemaUtils        $schemaUtils schema utils
37
     * @param CoreUtils          $coreUtils   coreUtils
38
     */
39
    public function __construct(
40
        Response $response,
41
        RestUtilsInterface $restUtils,
42
        Router $router,
43
        EngineInterface $templating,
44
        ContainerInterface $container,
45
        SchemaUtils $schemaUtils,
46
        CoreUtils $coreUtils
47
    ) {
48
        parent::__construct(
49
            $response,
50
            $restUtils,
51
            $router,
52
            $templating,
53
            $container,
54
            $schemaUtils
55
        );
56
        $this->coreUtils = $coreUtils;
57
    }
58
59
    /**
60
     * Returns all version numbers
61
     *
62
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
63
     */
64
    public function versionsAction()
65
    {
66
        $response = $this->getResponse()
67
            ->setStatusCode(Response::HTTP_OK);
68
        $response->headers->set('Content-Type', 'application/json');
69
        $versions = array();
70
        $versions['versions'] = $this->coreUtils->getVersion();
71
        return $this->render(
72
            'GravitonRestBundle:Main:index.json.twig',
73
            ['response' => json_encode($versions)],
74
            $response
75
        );
76
    }
77
78
    /**
79
     * Returns schema
80
     *
81
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
82
     */
83 View Code Duplication
    public function versionsSchemaAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $response = $this->getResponse()
86
            ->setStatusCode(Response::HTTP_OK);
87
        $response->headers->set('Content-Type', 'application/json');
88
        $schema = $this->getModel()->getSchema();
89
        return $this->render(
90
            'GravitonRestBundle:Main:index.json.twig',
91
            ['response' => json_encode($schema)],
92
            $response
93
        );
94
    }
95
}
96