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.

DropAllTablesCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSchemaName() 0 6 1
A getSql() 0 4 1
A execute() 0 21 2
1
<?php
2
namespace Rentgen\Schema\Manipulation;
3
4
use Rentgen\Schema\Command;
5
use Rentgen\Database\Table;
6
use Rentgen\Schema\Adapter\Postgres\Info\GetTablesCommand;
7
8
class DropAllTablesCommand extends Command
9
{
10
    private $schemaName = 'public';
11
    private $sql = '';
12
13
    /**
14
     * Sets a schema name.
15
     *
16
     * @param string $schemaName The schema name.
17
     *
18
     * @return DropAllTablesCommand
19
     */
20
    public function setSchemaName($schemaName)
21
    {
22
        $this->schemaName = $schemaName;
23
24
        return $this;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getSql()
31
    {
32
        return $this->sql;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function execute()
39
    {
40
        $getTablesCommand = new GetTablesCommand();
41
        $getTablesCommand->setConnection($this->connection);
42
        $tables = $getTablesCommand->execute();
43
44
        $this->preExecute();
45
        foreach ($tables as $table) {
46
            $dropTable = new DropTableCommand();
47
            $dropTable
48
                ->setTable($table)
49
                ->cascade()
50
                ->setConnection($this->connection)
51
                ->setEventDispatcher($this->dispatcher);
52
            $this->sql .= $dropTable->getSql();
53
            $dropTable->execute();
54
        }
55
        $this->postExecute();
56
57
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return true; (boolean) 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...
58
    }
59
}
60