Completed
Push — master ( d6c0d3...fbf2bc )
by Sergi Tur
03:14
created

Controller   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 4.65 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 0
dl 2
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A controller() 0 8 3
A controllerWithoutMethod() 1 5 2
A controllerMethod() 1 5 2

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
namespace Acacha\AdminLTETemplateLaravel\Console\Routes;
4
5
/**
6
 * Class Controller.
7
 *
8
 * @package Acacha\AdminLTETemplateLaravel\Console\Routes
9
 */
10
trait Controller
11
{
12
    /**
13
     * Obtain controller.
14
     *
15
     * @param $controllername
16
     * @return string
17
     */
18
    protected function controller($controllername)
19
    {
20
        if (str_contains($controllername, '/')) {
21
            $controllername = str_replace('/', '\\', $controllername);
22
        }
23
        if (str_contains($controllername, '@')) return ucfirst(preg_quote($controllername));
24
        return ucfirst(preg_quote($controllername) . '@index');
25
    }
26
27
    /**
28
     * Obtain controller.
29
     *
30
     * @param $controllername
31
     * @return string
32
     */
33
    protected function controllerWithoutMethod($controllername)
34
    {
35 View Code Duplication
        if (str_contains($controller = $controllername, '@')) return ucfirst(substr($controllername, 0, strpos($controllername,'@')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
        return ucfirst($controllername);
37
    }
38
39
    /**
40
     * Get method from controller name.
41
     *
42
     * @param $controllername
43
     * @return string
44
     */
45
    protected function controllerMethod($controllername)
46
    {
47 View Code Duplication
        if (str_contains($controller = $controllername, '@')) return substr($controllername, strpos($controllername,'@')+1, strlen($controllername)  );
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
        return 'index';
49
    }
50
51
52
}