Completed
Push — erdiko2 ( 1d6025...117d91 )
by John
02:14
created

Examples::getException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
namespace app\controllers;
3
4
class Examples extends \erdiko\controllers\Web
5
{
6 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...
7
    {
8
        $view = 'examples/list.html';
9
10
        // Get erdiko config, this gets application.json and loads the theme specified
11
        $themeData = \erdiko\theme\Config::get();
12
        // $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...
13
        $themeData['page'] = [
14
            'title' => "Erdiko Web Example",
15
            'hello' => "world"
16
            ];
17
18
        return $this->container->theme->render($response, $view, $themeData);
19
    }
20
21 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...
22
    {
23
        $view = 'pages/example.html';
24
25
        // Get erdiko config, this gets application.json and loads the theme specified
26
        $themeData = \erdiko\theme\Config::get();
27
        $themeData['args'] = $args; // optional
28
        $themeData['page'] = [
29
            'title' => "Erdiko Web Example"
30
            ];
31
32
        return $this->container->theme->render($response, $view, $themeData);
33
    }
34
35 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...
36
    {
37
        $view = 'examples/markup.html';
38
39
        // Get erdiko config, this gets application.json and loads the theme specified
40
        $themeData = \erdiko\theme\Config::get();
41
        $themeData['args'] = $args; // optional
42
        $themeData['page'] = [
43
            'title' => "Markup Example"
44
            ];
45
46
        return $this->container->theme->render($response, $view, $themeData);
47
    }
48
49 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...
50
    {
51
        $view = 'examples/carousel.html';
52
53
        // Get erdiko config, this gets application.json and loads the theme specified
54
        $themeData = \erdiko\theme\Config::get();
55
        $themeData['page'] = [
56
            'title' => "Fullpage Example",
57
            'description' => "This is the description of the page."
58
            ];
59
60
        return $this->container->theme->render($response, $view, $themeData);
61
    }
62
63
    public function getFlash($request, $response, $args)
64
    {
65
        $view = 'bootstrap.html';
66
67
        // Add some flash messages
68
        $this->container->flash->addMessage('success', 'This is a success message');
69
        $this->container->flash->addMessage('info', 'This is an info message');
70
        $this->container->flash->addMessage('warning', 'This is a warning message');
71
        $this->container->flash->addMessage('danger', 'This is a danger (error) message'); 
72
73
        // Get erdiko config, this gets application.json and loads the theme specified
74
        $themeData = \erdiko\theme\Config::get();
75
        $themeData['args'] = $args;
76
        $themeData['page'] = [
77
            'title' => "Flash Message Example"
78
            ];
79
80
        return $this->container->theme->render($response, $view, $themeData);
81
    }
82
83
    public function getGrid($request, $response, $args)
84
    {
85
        $this->container->logger->debug("/controller");
86
        $view = 'examples/grid.html';
87
88
        // Get erdiko config, this gets application.json and loads the theme specified
89
        $themeData = \erdiko\theme\Config::get();
90
        // $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...
91
92
        // Generate data for grid
93
        $item = [
94
            'url' => "#",
95
            'image' => "/images/grid-item.png",
96
            'name' => "Item"
97
        ];
98
        $items = array();
99
        $max = (int)$args['param'];
100
        $this->container->logger->debug("param: ".$max);
101
102 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...
103
            $item['name'] = "Item $i";
104
            $items[] = $item;
105
        }
106
107
        $themeData['page'] = [
108
            'title' => "Grid Example",
109
            'items' => $items
110
            ];
111
    
112
        return $this->container->theme->render($response, $view, $themeData);
113
    }
114
115 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...
116
    {
117
        $view = 'fullpage.html';
118
119
        // Get erdiko config, this gets application.json and loads the theme specified
120
        $themeData = \erdiko\theme\Config::get();
121
        $themeData['page'] = [
122
            'title' => "Fullpage Example",
123
            'description' => "This is the description of the page."
124
            ];
125
126
        return $this->container->theme->render($response, $view, $themeData);
127
    }
128
129
    public function getException($request, $response, $args)
130
    {
131
        $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...
132
133
        throw new \Exception("This is an exception");
134
135
        // Get erdiko config, this gets application.json and loads the theme specified
136
        $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...
137
        $themeData['page'] = [
138
            'title' => "Fullpage Example",
139
            'description' => "This is the description of the page."
140
            ];
141
142
        return $this->container->theme->render($response, $view, $themeData);
143
    }
144
}