Completed
Pull Request — develop (#605)
by
unknown
14:48
created

DefaultController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 55
loc 55
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A indexAction() 7 7 1
A optionsAction() 7 7 1
A proxyAction() 4 4 1
A schemaAction() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Entry point controller.
4
 */
5
namespace Graviton\ProxyApiBundle\Controller;
6
7
use Graviton\ProxyApiBundle\Manager\ServiceManager;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16 View Code Duplication
class DefaultController
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
    /** @var ServiceManager */
19
    private $serviceManager;
20
21
    /**
22
     * DefaultController constructor.
23
     * @param ServiceManager $serviceManager Parsing the requested date
24
     */
25
    public function __construct(
26
        ServiceManager $serviceManager
27
    ) {
28
        $this->serviceManager = $serviceManager;
29
    }
30
31
    /**
32
     * @return JsonResponse
33
     */
34
    public function indexAction()
35
    {
36
37
        $data = $this->serviceManager->getServices();
38
39
        return new JsonResponse($data);
40
    }
41
42
    /**
43
     * @return Response
44
     */
45
    public function optionsAction()
46
    {
47
        $resp = new Response();
48
        $resp->setStatusCode(Response::HTTP_NO_CONTENT);
49
        $resp->headers->set("Access-Control-Allow-Methods", "GET, OPTIONS, POST");
50
        return $resp;
51
    }
52
53
    /**
54
     * @return Response
55
     */
56
    public function proxyAction()
57
    {
58
        return $this->serviceManager->processRequest();
59
    }
60
61
    /**
62
     * @return JsonResponse
63
     */
64
    public function schemaAction()
65
    {
66
        $data = $this->serviceManager->getSchema();
0 ignored issues
show
Bug introduced by
The method getSchema() does not seem to exist on object<Graviton\ProxyApi...Manager\ServiceManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        return new JsonResponse($data);
69
    }
70
}
71