Completed
Push — master ( 714f13...e82fa0 )
by Korotkov
02:11
created

HttpController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 67.01 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 5
dl 65
loc 97
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A before() 0 4 1
A after() 0 6 1
B templateEngine() 41 41 2
A error404() 8 8 1
A error503() 8 8 1
A error500() 8 8 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
namespace App\Http;
4
5
use Rudra\Container;
6
use Rudra\ContainerInterface;
7
use Rudra\Controller;
8
9
/**
10
 * Class Module
11
 *
12
 * @package Http
13
 */
14
class HttpController extends Controller
15
{
16
17
    /**
18
     * @param ContainerInterface $container
19
     * @param string             $templateEngine
20
     */
21
    public function init(ContainerInterface $container, string $templateEngine)
22
    {
23
        parent::init($container, $templateEngine);
24
        $this->setData('Rudra', 'title');
25
    }
26
27
    /**
28
     * Метод выполняется перед вызовом контроллера
29
     */
30
    public function before()
31
    {
32
        $this->container()->get('auth')->check();
33
    }
34
35
    public function after()
36
    {
37
        // Очищаем сессию от alert
38
        $this->container()->unsetSession('value');
39
        $this->container()->unsetSession('alert');
40
    }
41
42 View Code Duplication
    public function templateEngine(string $config): void
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...
43
    {
44
        parent::templateEngine($config);
45
46
        $d = new \Twig_SimpleFunction('d', function ($var) {
47
            return d($var);
48
        });
49
50
        $this->getTwig()->addFunction($d);
51
52
        $date = new \Twig_SimpleFunction('date', function ($var) {
53
            return date($var);
54
        });
55
56
        $this->getTwig()->addFunction($date);
57
58
        $auth = new \Twig_SimpleFunction('auth', function () {
59
            return $this->container()->get('auth')->regularAccess();
60
        });
61
62
        $this->getTwig()->addFunction($auth);
63
64
65
        $active = new \Twig_SimpleFunction('active', function ($var) {
66
            return $this->container()->get('pagination')->activeClass($var);
67
        });
68
69
        $this->getTwig()->addFunction($active);
70
71
        $strstr = new \Twig_SimpleFunction('strstr', function ($var) {
72
            return strstr($var, '<a id="strstr" name="strstr"></a>', true);
73
        });
74
75
        $this->getTwig()->addFunction($strstr);
76
77
        if (DEV) {
78
            $debugbarRenderer = Container::$app->get('debugbar')->getJavascriptRenderer();
79
            $this->getTwig()->addGlobal('debugbar', $debugbarRenderer);
80
        }
81
82
    }
83
84 View Code Duplication
    public function error404()
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...
85
    {
86
        $this->container()->get('redirect')->responseCode('404');
87
88
        return $this->twig('errors/error.html.twig', [
89
            'title'  => '404 Page Not Found :: ' . $this->getData('title'),
0 ignored issues
show
Bug introduced by
The method getData() does not seem to exist on object<App\Http\HttpController>.

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...
90
        ]);
91
    }
92
93 View Code Duplication
    public function error503()
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...
94
    {
95
        $this->container()->get('redirect')->responseCode('503');
96
97
        return $this->twig('errors/error.html.twig', [
98
            'title'  => '503 Service Unavailable :: ' . $this->getData('title'),
0 ignored issues
show
Bug introduced by
The method getData() does not seem to exist on object<App\Http\HttpController>.

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...
99
        ]);
100
    }
101
102 View Code Duplication
    public function error500()
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...
103
    {
104
        $this->container()->get('redirect')->responseCode('503');
105
106
        return $this->twig('errors/503.html.twig', [
107
            'title'  => '503 Service Unavailable :: ' . $this->getData('title'),
0 ignored issues
show
Bug introduced by
The method getData() does not seem to exist on object<App\Http\HttpController>.

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...
108
        ]);
109
    }
110
}
111