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.
Completed
Push — develop ( ae55c1...1664f7 )
by Baptiste
01:42
created

Transaction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client\Channel\Transaction;
5
6
use Innmind\AMQP\{
7
    Client\Channel\Transaction as TransactionInterface,
8
    Transport\Connection,
9
    Transport\Frame\Channel
10
};
11
12
final class Transaction implements TransactionInterface
13
{
14
    private $connection;
15
    private $channel;
16
17 4
    public function __construct(Connection $connection, Channel $channel)
18
    {
19 4
        $this->connection = $connection;
20 4
        $this->channel = $channel;
21 4
    }
22
23 3
    public function select(): TransactionInterface
24
    {
25
        $this
26 3
            ->connection
27 3
            ->send($this->connection->protocol()->transaction()->select(
28 3
                $this->channel
29
            ))
30 3
            ->wait('tx.select-ok');
31
32 3
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Client\Chan...Transaction\Transaction) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Transaction::select of type self.

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...
33
    }
34
35 1
    public function commit(): TransactionInterface
36
    {
37
        $this
38 1
            ->connection
39 1
            ->send($this->connection->protocol()->transaction()->commit(
40 1
                $this->channel
41
            ))
42 1
            ->wait('tx.commit-ok');
43
44 1
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Client\Chan...Transaction\Transaction) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Transaction::commit of type self.

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...
45
    }
46
47 1
    public function rollback(): TransactionInterface
48
    {
49
        $this
50 1
            ->connection
51 1
            ->send($this->connection->protocol()->transaction()->rollback(
52 1
                $this->channel
53
            ))
54 1
            ->wait('tx.rollback-ok');
55
56 1
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Client\Chan...Transaction\Transaction) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Transaction::rollback of type self.

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...
57
    }
58
}
59