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

Queue::bind()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Client\Channel\Queue;
5
6
use Innmind\AMQP\{
7
    Client\Channel\Queue as QueueInterface,
8
    Model\Queue\Declaration,
9
    Model\Queue\DeclareOk,
10
    Model\Queue\Deletion,
11
    Model\Queue\DeleteOk,
12
    Model\Queue\Binding,
13
    Model\Queue\Unbinding,
14
    Model\Queue\Purge,
15
    Model\Queue\PurgeOk,
16
    Model\Count,
17
    Transport\Connection,
18
    Transport\Frame\Channel
19
};
20
21
final class Queue implements QueueInterface
22
{
23
    private $connection;
24
    private $channel;
25
26 6
    public function __construct(Connection $connection, Channel $channel)
27
    {
28 6
        $this->connection = $connection;
29 6
        $this->channel = $channel;
30 6
    }
31
32 5
    public function declare(Declaration $command): ?DeclareOk
1 ignored issue
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
33
    {
34 5
        $this->connection->send(
35 5
            $this->connection->protocol()->queue()->declare(
36 5
                $this->channel,
37 5
                $command
38
            )
39
        );
40
41 5
        if (!$command->shouldWait()) {
42 1
            return null;
43
        }
44
45 5
        $frame = $this->connection->wait('queue.declare-ok');
46
47 5
        return new DeclareOk(
1 ignored issue
show
Bug Best Practice introduced by
The return type of return new \Innmind\AMQP...>original()->value())); (Innmind\AMQP\Model\Queue\DeclareOk) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Queue::declare of type DeclareOk|null.

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...
48 5
            (string) $frame->values()->get(0)->original(),
49 5
            new Count($frame->values()->get(1)->original()->value()),
50 5
            new Count($frame->values()->get(2)->original()->value())
51
        );
52
    }
53
54 1
    public function delete(Deletion $command): ?DeleteOk
55
    {
56 1
        $this->connection->send(
57 1
            $this->connection->protocol()->queue()->delete(
58 1
                $this->channel,
59 1
                $command
60
            )
61
        );
62
63 1
        if (!$command->shouldWait()) {
64 1
            return null;
65
        }
66
67 1
        $frame = $this->connection->wait('queue.delete-ok');
68
69 1
        return new DeleteOk(new Count(
70 1
            $frame->values()->first()->original()->value()
71
        ));
72
    }
73
74 1
    public function bind(Binding $command): QueueInterface
75
    {
76 1
        $this->connection->send(
77 1
            $this->connection->protocol()->queue()->bind(
78 1
                $this->channel,
79 1
                $command
80
            )
81
        );
82
83 1
        if ($command->shouldWait()) {
84 1
            $this->connection->wait('queue.bind-ok');
85
        }
86
87 1
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Client\Channel\Queue\Queue) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Queue::bind 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...
88
    }
89
90 1
    public function unbind(Unbinding $command): QueueInterface
91
    {
92
        $this
93 1
            ->connection
94 1
            ->send($this->connection->protocol()->queue()->unbind(
95 1
                $this->channel,
96 1
                $command
97
            ))
98 1
            ->wait('queue.unbind-ok');
99
100 1
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Client\Channel\Queue\Queue) is incompatible with the return type declared by the interface Innmind\AMQP\Client\Channel\Queue::unbind 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...
101
    }
102
103 1
    public function purge(Purge $command): ?PurgeOk
104
    {
105 1
        $this->connection->send(
106 1
            $this->connection->protocol()->queue()->purge(
107 1
                $this->channel,
108 1
                $command
109
            )
110
        );
111
112 1
        if (!$command->shouldWait()) {
113 1
            return null;
114
        }
115
116 1
        $frame = $this->connection->wait('queue.purge-ok');
117
118 1
        return new PurgeOk(new Count(
119 1
            $frame->values()->first()->original()->value()
120
        ));
121
    }
122
}
123