Completed
Push — master ( 8cb42d...e9bfab )
by
unknown
19:56
created

VersionController::setCoreUtils()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
     * Build core utils
32
     * @param CoreUtils $coreUtils coreUtils
33
     * @return void
34
     */
35
    public function setCoreUtils(CoreUtils $coreUtils)
36
    {
37
        $this->coreUtils = $coreUtils;
38
    }
39
40
    /**
41
     * Returns all version numbers
42
     *
43
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
44
     */
45 View Code Duplication
    public function versionsAction()
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...
46
    {
47
        $response = $this->getResponse()
48
            ->setStatusCode(Response::HTTP_OK);
49
        $response->headers->set('Content-Type', 'application/json');
50
        $versions = array();
51
        $versions['versions'] = $this->coreUtils->getVersion();
52
        return $this->render(
53
            'GravitonRestBundle:Main:index.json.twig',
54
            ['response' => json_encode($versions)],
55
            $response
56
        );
57
    }
58
59
    /**
60
     * Returns schema
61
     *
62
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
63
     */
64 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...
65
    {
66
        $response = $this->getResponse()
67
            ->setStatusCode(Response::HTTP_OK);
68
        $response->headers->set('Content-Type', 'application/json');
69
        $schema = $this->getModel()->getSchema();
70
        return $this->render(
71
            'GravitonRestBundle:Main:index.json.twig',
72
            ['response' => json_encode($schema)],
73
            $response
74
        );
75
    }
76
}
77