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 ( 14a217...c3bf76 )
by Baptiste
03:06
created

Protocol::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Protocol\v091;
5
6
use Innmind\AMQP\{
7
    Transport\Protocol as ProtocolInterface,
8
    Transport\Protocol\Version,
9
    Transport\Protocol\Connection as ConnectionInterface,
10
    Transport\Protocol\Channel as ChannelInterface,
11
    Transport\Protocol\Exchange as ExchangeInterface,
12
    Transport\Protocol\Queue as QueueInterface,
13
    Transport\Protocol\Basic as BasicInterface,
14
    Transport\Protocol\Transaction as TransactionInterface,
15
    Transport\Frame\Method,
16
    Exception\VersionNotUsable
17
};
18
use Innmind\Immutable\{
19
    Str,
20
    StreamInterface
21
};
22
23
final class Protocol implements ProtocolInterface
24
{
25
    private $version;
26
    private $read;
27
    private $connection;
28
    private $channel;
29
    private $exchange;
30
    private $queue;
31
    private $basic;
32
    private $transaction;
33
34 63
    public function __construct()
35
    {
36 63
        $this->version = new Version(0, 9, 1);
37 63
        $this->read = new Reader;
38 63
        $this->connection = new Connection;
39 63
        $this->channel = new Channel;
40 63
        $this->exchange = new Exchange;
41 63
        $this->queue = new Queue;
42 63
        $this->basic = new Basic;
43 63
        $this->transaction = new Transaction;
44 63
    }
45
46 3
    public function version(): Version
47
    {
48 3
        return $this->version;
49
    }
50
51 5
    public function use(Version $version): ProtocolInterface
52
    {
53 5
        if (!$version->compatibleWith($this->version)) {
1 ignored issue
show
Documentation introduced by
$this->version is of type object<Innmind\AMQP\Transport\Protocol\Version>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54 2
            throw new VersionNotUsable($version);
55
        }
56
57 3
        return $this;
1 ignored issue
show
Bug Best Practice introduced by
The return type of return $this; (Innmind\AMQP\Transport\Protocol\v091\Protocol) is incompatible with the return type declared by the interface Innmind\AMQP\Transport\Protocol::use 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...
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public function read(Method $method, Str $arguments): StreamInterface
64
    {
65 3
        return ($this->read)($method, $arguments);
66
    }
67
68 55
    public function method(string $name): Method
69
    {
70 55
        return Methods::get($name);
71
    }
72
73 3
    public function connection(): ConnectionInterface
74
    {
75 3
        return $this->connection;
76
    }
77
78 3
    public function channel(): ChannelInterface
79
    {
80 3
        return $this->channel;
81
    }
82
83 1
    public function exchange(): ExchangeInterface
84
    {
85 1
        return $this->exchange;
86
    }
87
88 1
    public function queue(): QueueInterface
89
    {
90 1
        return $this->queue;
91
    }
92
93 1
    public function basic(): BasicInterface
94
    {
95 1
        return $this->basic;
96
    }
97
98 1
    public function transaction(): TransactionInterface
99
    {
100 1
        return $this->transaction;
101
    }
102
}
103