Completed
Push — erdiko2 ( 719271...84f584 )
by John
05:49
created

Database   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 32.5 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 13
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 1
A getSession() 13 13 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\examples;
3
4
class Database extends \erdiko\controllers\Web
5
{
6
    use \erdiko\theme\traits\Controller; // Add theme engine suport (for convenience)
7
    use \erdiko\doctrine\controllers\EntityTrait;
8
9
    public function get($request, $response, $args)
10
    {
11
        $this->getThemeEngine();
12
        $this->theme->title = "Database Test";
13
14
        // Inject in controller
15
        // $tests = $this->getRepository('app\entities\Test')->findAll();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
16
        // $this->theme->description = "<pre>Tests: ".print_r($tests, true)."</pre>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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
18
        // Inject EntityManager into the model
19
        $test = new \app\models\Test($this->container->em);
20
        $tests = $test->getTests();
21
        $this->theme->description = "<pre>Tests: ".print_r($tests, true)."</pre>";
22
23
        return $this->render($response, null, $theme);
0 ignored issues
show
Bug introduced by
The variable $theme does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
24
    }
25
26
    /**
27
     * Test the session
28
     */
29 View Code Duplication
    public function getSession($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...
Coding Style introduced by
getSession uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
30
    {
31
        $this->getThemeEngine();
32
        $this->theme->title = "Session Test";
33
34
        $value = (isset($_GET["index"])) ? $_GET["index"] : \erdiko\session\Session::get('index');
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $expired.

This check looks for function calls that miss required arguments.

Loading history...
35
        \erdiko\session\Session::set('index', $value);
36
37
        // $this->container->logger->debug("session::index = ".\erdiko\session\Session::get('index'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
38
        $this->theme->description = "Session value: ".\erdiko\session\Session::get('index');
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $expired.

This check looks for function calls that miss required arguments.

Loading history...
39
40
        return $this->render($response, null, $theme);
0 ignored issues
show
Bug introduced by
The variable $theme does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
41
    }
42
43
}
44