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

Grid   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 12.12 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 4
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 4 28 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 Grid extends \erdiko\Controller
5
{
6
	protected $container;
7
   
8
	public function __invoke($request, $response, $args) 
9
	{
10
        $this->container->logger->debug("/controller");
11
   		$view = 'pages/grid.html';
12
13
        // Get erdiko config, this gets application.json and loads the theme specified
14
        $config = \erdiko\theme\Config::get();        
15
16
        // $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...
17
        $config['name'] = $args['name'];
18
        $config['title'] = "Erdiko Controller Example";
19
        $config['args'] = $args;
20
21
        $item = [
22
            'url' => "#",
23
            'image' => "/images/grid-item.png",
24
            'name' => "Item"
25
        ];
26
27
        $items = array();
28 View Code Duplication
        for($i = 0; $i < $args['count']; $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...
29
            $item['name'] = "Item $i";
30
            $items[] = $item;
31
        }
32
        $config['items'] = $items;
33
34
   		return $this->container->theme->render($response, $view, $config);
35
  	}
36
}