Completed
Pull Request — develop (#337)
by Bastian
06:24
created

VersionController::versionsSchemaAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1
Metric Value
dl 12
loc 12
ccs 9
cts 9
cp 1
rs 9.4286
cc 1
eloc 9
nc 1
nop 0
crap 1
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\DocumentBundle\Form\Type\DocumentType;
10
use Graviton\RestBundle\Controller\RestController;
11
use Graviton\RestBundle\Service\RestUtilsInterface;
12
use Graviton\SchemaBundle\SchemaUtils;
13
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
use Symfony\Component\Form\FormFactory;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Bundle\FrameworkBundle\Routing\Router;
19
use Symfony\Component\Validator\Validator\ValidatorInterface;
20
21
/**
22
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
23
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
24
 * @link     http://swisscom.ch
25
 */
26
class VersionController extends RestController
27
{
28
    /**
29
     * @var CoreUtils
30
     */
31
    private $coreUtils;
32
33
    /**
34
     * @param Response           $response    Response
35
     * @param RestUtilsInterface $restUtils   Rest utils
36
     * @param Router             $router      Router
37
     * @param ValidatorInterface $validator   Validator
38
     * @param EngineInterface    $templating  Templating
39
     * @param FormFactory        $formFactory form factory
40
     * @param DocumentType       $formType    generic form
41
     * @param ContainerInterface $container   Container
42
     * @param SchemaUtils        $schemaUtils schema utils
43
     * @param CoreUtils          $coreUtils   coreUtils
44
     */
45 2 View Code Duplication
    public function __construct(
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
        Response $response,
47
        RestUtilsInterface $restUtils,
48
        Router $router,
49
        ValidatorInterface $validator,
50
        EngineInterface $templating,
51
        FormFactory $formFactory,
52
        DocumentType $formType,
53
        ContainerInterface $container,
54
        SchemaUtils $schemaUtils,
55
        CoreUtils $coreUtils
56
    ) {
57 2
        parent::__construct(
58 2
            $response,
59 2
            $restUtils,
60 2
            $router,
61 2
            $validator,
62 2
            $templating,
63 2
            $formFactory,
64 2
            $formType,
65 2
            $container,
66
            $schemaUtils
67 2
        );
68 2
        $this->coreUtils = $coreUtils;
69 2
    }
70
71
    /**
72
     * Returns all version numbers
73
     *
74
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
75
     */
76 1 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...
77
    {
78 1
        $response = $this->getResponse()
79 1
            ->setStatusCode(Response::HTTP_OK);
80 1
        $response->headers->set('Content-Type', 'application/json');
81 1
        $versions = array();
82 1
        $versions['versions'] = $this->coreUtils->getVersion();
83 1
        return $this->render(
84 1
            'GravitonRestBundle:Main:index.json.twig',
85 1
            ['response' => json_encode($versions)],
86
            $response
87 1
        );
88
    }
89
90
    /**
91
     * Returns schema
92
     *
93
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
94
     */
95 1 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...
96
    {
97 1
        $response = $this->getResponse()
98 1
            ->setStatusCode(Response::HTTP_OK);
99 1
        $response->headers->set('Content-Type', 'application/json');
100 1
        $schema = $this->getModel()->getSchema();
101 1
        return $this->render(
102 1
            'GravitonRestBundle:Main:index.json.twig',
103 1
            ['response' => json_encode($schema)],
104
            $response
105 1
        );
106
    }
107
}
108