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.

Connection::secureOk()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Protocol\v091;
5
6
use Innmind\AMQP\{
7
    Model\Connection\StartOk,
8
    Model\Connection\SecureOk,
9
    Model\Connection\TuneOk,
10
    Model\Connection\Open,
11
    Model\Connection\Close,
12
    Transport\Frame,
13
    Transport\Protocol\Connection as ConnectionInterface,
14
    Transport\Frame\Type,
15
    Transport\Frame\Channel,
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Innmind\AMQP\Transport\Protocol\v091\Channel. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
    Transport\Frame\Method,
17
    Transport\Frame\Value,
18
    Transport\Frame\Value\Table,
19
    Transport\Frame\Value\LongString,
20
    Transport\Frame\Value\Bits,
21
    Transport\Frame\Value\ShortString,
22
    Transport\Frame\Value\UnsignedShortInteger,
23
    Transport\Frame\Value\UnsignedLongInteger,
24
};
25
use Innmind\Url\Authority\UserInformation\{
26
    UserInterface,
27
    PasswordInterface,
28
};
29
use Innmind\Math\Algebra\Integer;
30
use Innmind\Immutable\{
31
    Str,
32
    Map,
33
};
34
35
final class Connection implements ConnectionInterface
36
{
37 92
    public function startOk(StartOk $command): Frame
38
    {
39 92
        $clientProperties = new Table(
40 92
            Map::of('string', Value::class)
41 92
                ('product', new LongString(new Str('InnmindAMQP')))
42 92
                ('platform', new LongString(new Str('PHP')))
43 92
                ('version', new LongString(new Str('1.0')))
44 92
                ('information', new LongString(new Str('')))
45 92
                ('copyright', new LongString(new Str('')))
46
                (
47 92
                    'capabilities',
48 92
                    new Table(
49 92
                        Map::of('string', Value::class)
50 92
                            ('authentication_failure_close', new Bits(true))
51 92
                            ('publisher_confirms', new Bits(true))
52 92
                            ('consumer_cancel_notify', new Bits(true))
53 92
                            ('exchange_exchange_bindings', new Bits(true))
54 92
                            ('connection.blocked', new Bits(true))
55
                    )
56
                )
57
        );
58
59 92
        return Frame::method(
60 92
            new Channel(0),
61 92
            Methods::get('connection.start-ok'),
62 46
            $clientProperties,
63 92
            new ShortString(new Str('AMQPLAIN')), //mechanism
64 92
            $this->response($command->user(), $command->password()),
65 92
            new ShortString(new Str('en_US')) //locale
66
        );
67
    }
68
69 2
    public function secureOk(SecureOk $command): Frame
70
    {
71 2
        return Frame::method(
72 2
            new Channel(0),
73 2
            Methods::get('connection.secure-ok'),
74 2
            $this->response($command->user(), $command->password())
75
        );
76
    }
77
78 92
    public function tuneOk(TuneOk $command): Frame
79
    {
80 92
        return Frame::method(
81 92
            new Channel(0),
82 92
            Methods::get('connection.tune-ok'),
83 92
            UnsignedShortInteger::of(new Integer($command->maxChannels())),
84 92
            UnsignedLongInteger::of(new Integer($command->maxFrameSize())),
85 92
            UnsignedShortInteger::of(new Integer(
86 92
                (int) ($command->heartbeat()->milliseconds() / 1000)
87
            ))
88
        );
89
    }
90
91 92
    public function open(Open $command): Frame
92
    {
93 92
        return Frame::method(
94 92
            new Channel(0),
95 92
            Methods::get('connection.open'),
96 92
            ShortString::of(new Str((string) $command->virtualHost())),
97 92
            new ShortString(new Str('')), //capabilities (reserved)
98 92
            new Bits(false) //insist (reserved)
99
        );
100
    }
101
102 78
    public function close(Close $command): Frame
103
    {
104 78
        $replyCode = 0;
105 78
        $replyText = '';
106 78
        $method = new Method(0, 0);
107
108 78
        if ($command->hasReply()) {
109 2
            $replyCode = $command->replyCode();
110 2
            $replyText = $command->replyText();
111
        }
112
113 78
        if ($command->causedKnown()) {
114 2
            $method = Methods::get($command->cause());
115
        }
116
117 78
        return Frame::method(
118 78
            new Channel(0),
119 78
            Methods::get('connection.close'),
120 78
            UnsignedShortInteger::of(new Integer($replyCode)),
121 78
            ShortString::of(new Str($replyText)),
122 78
            UnsignedShortInteger::of(new Integer($method->class())),
123 78
            UnsignedShortInteger::of(new Integer($method->method()))
124
        );
125
    }
126
127 4
    public function closeOk(): Frame
128
    {
129 4
        return Frame::method(
130 4
            new Channel(0),
131 4
            Methods::get('connection.close-ok')
132
        );
133
    }
134
135 94
    private function response(UserInterface $user, PasswordInterface $password): LongString
136
    {
137 94
        $response = new Table(
138 94
            Map::of('string', Value::class)
139 94
                ('LOGIN', LongString::of(new Str((string) $user)))
140 94
                ('PASSWORD', LongString::of(new Str((string) $password)))
141
        );
142 94
        $response = Str::of((string) $response)
143 94
            ->toEncoding('ASCII')
144 94
            ->substring(4); //skip the encoded table length integer
145
146 94
        return new LongString($response);
147
    }
148
}
149