Completed
Push — master ( 8fd009...775c14 )
by Christian
06:04
created

AbstractFOSRestController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 8
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getViewHandler() 8 8 2
A getSubscribedServices() 0 7 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
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\Controller;
13
14
use FOS\RestBundle\View\ViewHandlerInterface;
15
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
16
17
/**
18
 * Controllers using the View functionality of FOSRestBundle.
19
 */
20
abstract class AbstractFOSRestController extends AbstractController
21
{
22
    use ControllerTrait;
23
24
    /**
25
     * Get the ViewHandler.
26
     *
27
     * @return ViewHandlerInterface
28
     */
29 View Code Duplication
    protected function getViewHandler()
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...
30
    {
31
        if (!$this->viewhandler instanceof ViewHandlerInterface) {
32
            $this->viewhandler = $this->container->get('fos_rest.view_handler');
33
        }
34
35
        return $this->viewhandler;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @return array
42
     */
43
    public static function getSubscribedServices()
44
    {
45
        $subscribedServices = parent::getSubscribedServices();
46
        $subscribedServices['fos_rest.view_handler'] = ViewHandlerInterface::class;
47
48
        return $subscribedServices;
49
    }
50
}
51