Completed
Branch erdiko2 (40e193)
by John
04:03
created

Examples   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 56.58 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 43
loc 76
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 13 13 1
A getJohn() 13 13 1
A getMarkup() 13 13 1
B getGrid() 4 31 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
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
13
        $themeData['page'] = [
14
            'title' => "Erdiko Web Example"
15
            ];
16
17
        return $this->container->theme->render($response, $view, $themeData);
18
    }
19
20 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...
21
    {
22
        $view = 'pages/example.html';
23
24
        // Get erdiko config, this gets application.json and loads the theme specified
25
        $themeData = \erdiko\theme\Config::get();
26
        $themeData['args'] = $args; // optional
27
        $themeData['page'] = [
28
            'title' => "Erdiko Web Example"
29
            ];
30
31
        return $this->container->theme->render($response, $view, $themeData);
32
    }
33
34 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...
35
    {
36
        $view = 'examples/markup.html';
37
38
        // Get erdiko config, this gets application.json and loads the theme specified
39
        $themeData = \erdiko\theme\Config::get();
40
        $themeData['args'] = $args; // optional
41
        $themeData['page'] = [
42
            'title' => "Markup Example"
43
            ];
44
45
        return $this->container->theme->render($response, $view, $themeData);
46
    }
47
48
    public function getGrid($request, $response, $args)
49
    {
50
        $this->container->logger->debug("/controller");
51
        $view = 'examples/grid.html';
52
53
        // Get erdiko config, this gets application.json and loads the theme specified
54
        $themeData = \erdiko\theme\Config::get();
55
        // $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...
56
57
        $item = [
58
            'url' => "#",
59
            'image' => "/images/grid-item.png",
60
            'name' => "Item"
61
        ];
62
        $items = array();
63
        $max = (int)$args['param'];
64
        $this->container->logger->debug("param: ".$max);
65
66 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...
67
            $item['name'] = "Item $i";
68
            $items[] = $item;
69
        }
70
71
        $themeData['args'] = $args;
72
        $themeData['page'] = [
73
            'title' => "Grid Example",
74
            'items' => $items
75
            ];
76
    
77
        return $this->container->theme->render($response, $view, $themeData);
78
    }
79
}