Completed
Push — erdiko2 ( 117d91...a0a9d1 )
by John
02:07
created

Examples::getTheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
namespace app\controllers;
3
4
class Examples extends \erdiko\controllers\Web
5
{
6
    use \erdiko\theme\traits\Controller;
7
8 View Code Duplication
    public function get($request, $response, $args)
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...
9
    {
10
        $view = 'examples/list.html';
11
12
        // Get erdiko config, this gets application.json and loads the theme specified
13
        $themeData = \erdiko\theme\Config::get();
14
        // $themeData['args'] = $args; // optional
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
15
        $themeData['page'] = [
16
            'title' => "Erdiko Web Example",
17
            'hello' => "world"
18
            ];
19
20
        return $this->container->theme->render($response, $view, $themeData);
21
    }
22
23 View Code Duplication
    public function getJohn($request, $response, $args)
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...
24
    {
25
        $view = 'pages/example.html';
26
27
        // Get erdiko config, this gets application.json and loads the theme specified
28
        $themeData = \erdiko\theme\Config::get();
29
        $themeData['args'] = $args; // optional
30
        $themeData['page'] = [
31
            'title' => "Erdiko Web Example"
32
            ];
33
34
        return $this->container->theme->render($response, $view, $themeData);
35
    }
36
37 View Code Duplication
    public function getMarkup($request, $response, $args)
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...
38
    {
39
        $view = 'examples/markup.html';
40
41
        // Get erdiko config, this gets application.json and loads the theme specified
42
        $themeData = \erdiko\theme\Config::get();
43
        $themeData['args'] = $args; // optional
44
        $themeData['page'] = [
45
            'title' => "Markup Example"
46
            ];
47
48
        return $this->container->theme->render($response, $view, $themeData);
49
    }
50
51 View Code Duplication
    public function getCarousel($request, $response, $args)
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...
52
    {
53
        $view = 'examples/carousel.html';
54
55
        // Get erdiko config, this gets application.json and loads the theme specified
56
        $themeData = \erdiko\theme\Config::get();
57
        $themeData['page'] = [
58
            'title' => "Fullpage Example",
59
            'description' => "This is the description of the page."
60
            ];
61
62
        return $this->container->theme->render($response, $view, $themeData);
63
    }
64
65
    public function getTheme($request, $response, $args)
66
    {
67
        // $view = 'examples/theme.html';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
        $theme = new \erdiko\theme\Engine;
69
        $theme->title = "Theme Engine Example";
70
        $theme->description = "This page is rendered using the theme engine.  
71
            \\erdiko\\theme\\Engine";
72
73
        return $this->render($response, null, $theme);
74
    }
75
76
    public function getFlash($request, $response, $args)
77
    {
78
        $view = 'bootstrap.html';
79
80
        // Add some flash messages
81
        $this->container->flash->addMessage('success', 'This is a success message');
82
        $this->container->flash->addMessage('info', 'This is an info message');
83
        $this->container->flash->addMessage('warning', 'This is a warning message');
84
        $this->container->flash->addMessage('danger', 'This is a danger (error) message'); 
85
86
        // Get erdiko config, this gets application.json and loads the theme specified
87
        $themeData = \erdiko\theme\Config::get();
88
        $themeData['args'] = $args;
89
        $themeData['page'] = [
90
            'title' => "Flash Message Example"
91
            ];
92
93
        return $this->container->theme->render($response, $view, $themeData);
94
    }
95
96
    public function getGrid($request, $response, $args)
97
    {
98
        $this->container->logger->debug("/controller");
99
        $view = 'examples/grid.html';
100
101
        // Get erdiko config, this gets application.json and loads the theme specified
102
        $themeData = \erdiko\theme\Config::get();
103
        // $this->container->logger->debug("config: ".print_r($config, true));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
104
105
        // Generate data for grid
106
        $item = [
107
            'url' => "#",
108
            'image' => "/images/grid-item.png",
109
            'name' => "Item"
110
        ];
111
        $items = array();
112
        $max = (int)$args['param'];
113
        $this->container->logger->debug("param: ".$max);
114
115 View Code Duplication
        for($i = 0; $i < $max; $i++) {
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...
116
            $item['name'] = "Item $i";
117
            $items[] = $item;
118
        }
119
120
        $themeData['page'] = [
121
            'title' => "Grid Example",
122
            'items' => $items
123
            ];
124
    
125
        return $this->container->theme->render($response, $view, $themeData);
126
    }
127
128 View Code Duplication
    public function getFullpage($request, $response, $args)
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...
129
    {
130
        $view = 'fullpage.html';
131
132
        // Get erdiko config, this gets application.json and loads the theme specified
133
        $themeData = \erdiko\theme\Config::get();
134
        $themeData['page'] = [
135
            'title' => "Fullpage Example",
136
            'description' => "This is the description of the page."
137
            ];
138
139
        return $this->container->theme->render($response, $view, $themeData);
140
    }
141
142
    public function getException($request, $response, $args)
143
    {
144
        $view = 'fullpage.html';
0 ignored issues
show
Unused Code introduced by
$view is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
145
146
        throw new \Exception("This is an exception");
147
148
        // Get erdiko config, this gets application.json and loads the theme specified
149
        $themeData = \erdiko\theme\Config::get();
0 ignored issues
show
Unused Code introduced by
// Get erdiko config, th...ko\theme\Config::get(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
150
        $themeData['page'] = [
151
            'title' => "Fullpage Example",
152
            'description' => "This is the description of the page."
153
            ];
154
155
        return $this->container->theme->render($response, $view, $themeData);
156
    }
157
}