Completed
Push — master ( b1b281...32f961 )
by Sergi Tur
15s
created

Controller::controller()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 11
loc 11
rs 9.4285
c 1
b 0
f 1
cc 3
eloc 6
nc 4
nop 1
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 View Code Duplication
    protected function controller($controllername)
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...
19
    {
20
        if (str_contains($controllername, '/')) {
21
            $controllername = str_replace('/', '\\', $controllername);
22
        }
23
24
        if (str_contains($controllername, '@')) {
25
            return ucfirst($controllername);
26
        }
27
        return ucfirst($controllername . '@index');
28
    }
29
30
    /**
31
     * Obtain controller.
32
     *
33
     * @param $controllername
34
     * @return string
35
     */
36 View Code Duplication
    protected function controllerWithoutMethod($controllername)
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...
37
    {
38
        if (str_contains($controller = $controllername, '@')) {
39
            return ucfirst(substr($controllername, 0, strpos($controllername, '@')));
40
        }
41
        return ucfirst($controllername);
42
    }
43
44
    /**
45
     * Get method from controller name.
46
     *
47
     * @param $controllername
48
     * @return string
49
     */
50
    protected function controllerMethod($controllername)
51
    {
52
        if (str_contains($controller = $controllername, '@')) {
53
            return substr($controllername, strpos($controllername, '@')+1, strlen($controllername));
54
        }
55
        return 'index';
56
    }
57
}
58