GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

GetSchemasCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 40.63 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSql() 0 9 1
A execute() 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 Rentgen\Schema\Info;
3
4
use Rentgen\Database\Schema;
5
use Rentgen\Schema\Command;
6
7
class GetSchemasCommand extends Command
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function getSql()
13
    {
14
        $sql = 'SELECT schema_name
15
                FROM information_schema.schemata
16
                WHERE schema_name <> \'information_schema\'
17
                AND schema_name !~ \'^pg_\'';
18
19
        return $sql;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 View Code Duplication
    public function execute()
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...
26
    {
27
        $this->preExecute();
28
        $result = $this->connection->query($this->getSql());
29
        $this->postExecute();
30
31
        $schemas = array();
32
        foreach ($result as $row) {
33
            $schemas[] = new Schema($row['schema_name']);
34
        }
35
36
        return $schemas;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $schemas; (array) is incompatible with the return type of the parent method Rentgen\Schema\Command::execute of type integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
37
    }
38
}
39