Skip to content

Commit 84bb743

Browse files
committed
Use strict types everywhere
1 parent 6f15659 commit 84bb743

File tree

11 files changed

+65
-190
lines changed

11 files changed

+65
-190
lines changed

src/Common/PublishAckPacket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client\Common;
46

57
use BinSoul\Net\Mqtt\Packet\PublishAckPacket as BasePublishAckPacket;

src/Json.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client;
46

57
class Json
68
{
79
/**
810
* Special decoder to keep big numbers on x86 PHP builds.
911
*
10-
* @param string $json
11-
*
1212
* @return mixed
1313
*/
14-
public static function decode($json)
14+
public static function decode(string $json)
1515
{
1616
$flags = 0;
1717
if (PHP_INT_SIZE === 4) {

src/Lite/ConnectRequestPacket.php

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<?php
22

3-
/*
4-
* This file is part of net-mqtt.
5-
*
6-
* Copyright (c) 2015 Sebastian Mößler [email protected]
7-
*
8-
* This source file is subject to the MIT license.
9-
*/
3+
declare(strict_types=1);
104

115
namespace Fbns\Client\Lite;
126

@@ -66,22 +60,16 @@ public function write(PacketStream $stream): void
6660

6761
/**
6862
* Returns the protocol level.
69-
*
70-
* @return int
7163
*/
72-
public function getProtocolLevel()
64+
public function getProtocolLevel(): int
7365
{
7466
return $this->protocolLevel;
7567
}
7668

7769
/**
7870
* Sets the protocol level.
79-
*
80-
* @param int $value
81-
*
82-
* @throws \InvalidArgumentException
8371
*/
84-
public function setProtocolLevel($value)
72+
public function setProtocolLevel(int $value): void
8573
{
8674
if ($value != 3) {
8775
throw new \InvalidArgumentException(sprintf('Unknown protocol level %d.', $value));
@@ -92,42 +80,32 @@ public function setProtocolLevel($value)
9280

9381
/**
9482
* Returns the payload.
95-
*
96-
* @return string
9783
*/
98-
public function getPayload()
84+
public function getPayload(): string
9985
{
10086
return $this->payload;
10187
}
10288

10389
/**
10490
* Sets the payload.
105-
*
106-
* @param string $value
10791
*/
108-
public function setPayload($value)
92+
public function setPayload(string $value)
10993
{
11094
$this->payload = $value;
11195
}
11296

11397
/**
11498
* Returns the flags.
115-
*
116-
* @return int
11799
*/
118-
public function getFlags()
100+
public function getFlags(): int
119101
{
120102
return $this->flags;
121103
}
122104

123105
/**
124106
* Sets the flags.
125-
*
126-
* @param int $value
127-
*
128-
* @throws \InvalidArgumentException
129107
*/
130-
public function setFlags($value)
108+
public function setFlags(int $value)
131109
{
132110
if ($value > 255) {
133111
throw new \InvalidArgumentException(sprintf('Expected a flags lower than 255 but got %d.', $value));
@@ -138,22 +116,16 @@ public function setFlags($value)
138116

139117
/**
140118
* Returns the keep alive time in seconds.
141-
*
142-
* @return int
143119
*/
144-
public function getKeepAlive()
120+
public function getKeepAlive(): int
145121
{
146122
return $this->keepAlive;
147123
}
148124

149125
/**
150126
* Sets the keep alive time in seconds.
151-
*
152-
* @param int $value
153-
*
154-
* @throws \InvalidArgumentException
155127
*/
156-
public function setKeepAlive($value)
128+
public function setKeepAlive(int $value): void
157129
{
158130
if ($value > 65535) {
159131
throw new \InvalidArgumentException(sprintf('Expected a keep alive time lower than 65535 but got %d.', $value));
@@ -164,22 +136,16 @@ public function setKeepAlive($value)
164136

165137
/**
166138
* Returns the protocol name.
167-
*
168-
* @return string
169139
*/
170-
public function getProtocolName()
140+
public function getProtocolName(): string
171141
{
172142
return $this->protocolName;
173143
}
174144

175145
/**
176146
* Sets the protocol name.
177-
*
178-
* @param string $value
179-
*
180-
* @throws \InvalidArgumentException
181147
*/
182-
public function setProtocolName($value)
148+
public function setProtocolName(string $value): void
183149
{
184150
$this->assertValidStringLength($value, false);
185151

src/Lite/ConnectResponsePacket.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?php
22

3-
/*
4-
* This file is part of net-mqtt.
5-
*
6-
* Copyright (c) 2015 Sebastian Mößler [email protected]
7-
*
8-
* This source file is subject to the MIT license.
9-
*/
3+
declare(strict_types=1);
104

115
namespace Fbns\Client\Lite;
126

137
use BinSoul\Net\Mqtt\Packet;
148
use BinSoul\Net\Mqtt\Packet\BasePacket;
159
use BinSoul\Net\Mqtt\PacketStream;
1610

17-
/**
18-
* Represents the CONNACK packet.
19-
*/
2011
class ConnectResponsePacket extends BasePacket
2112
{
2213
/** @var string[][] */
@@ -81,7 +72,7 @@ public function write(PacketStream $stream): void
8172
$data->writeByte($this->flags);
8273
$data->writeByte($this->returnCode);
8374

84-
if ($this->auth !== null && strlen($this->auth)) {
75+
if ($this->auth !== null && $this->auth !== '') {
8576
$data->writeString($this->auth);
8677
}
8778

@@ -93,40 +84,32 @@ public function write(PacketStream $stream): void
9384

9485
/**
9586
* Returns the return code.
96-
*
97-
* @return int
9887
*/
99-
public function getReturnCode()
88+
public function getReturnCode(): int
10089
{
10190
return $this->returnCode;
10291
}
10392

10493
/**
10594
* Indicates if the connection was successful.
106-
*
107-
* @return bool
10895
*/
109-
public function isSuccess()
96+
public function isSuccess(): bool
11097
{
11198
return $this->returnCode === 0;
11299
}
113100

114101
/**
115102
* Indicates if the connection failed.
116-
*
117-
* @return bool
118103
*/
119-
public function isError()
104+
public function isError(): bool
120105
{
121106
return $this->returnCode > 0;
122107
}
123108

124109
/**
125110
* Returns a string representation of the returned error code.
126-
*
127-
* @return int
128111
*/
129-
public function getErrorName()
112+
public function getErrorName(): string
130113
{
131114
if (isset(self::$returnCodes[$this->returnCode])) {
132115
return self::$returnCodes[$this->returnCode][0];
@@ -135,10 +118,7 @@ public function getErrorName()
135118
return 'Error '.$this->returnCode;
136119
}
137120

138-
/**
139-
* @return string
140-
*/
141-
public function getAuth()
121+
public function getAuth(): string
142122
{
143123
return $this->auth;
144124
}

src/Lite/FlowFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client\Lite;
46

57
use BinSoul\Net\Mqtt\ClientIdentifierGenerator;

src/Lite/OutgoingConnectFlow.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client\Lite;
46

57
use BinSoul\Net\Mqtt\ClientIdentifierGenerator;
@@ -8,9 +10,6 @@
810
use BinSoul\Net\Mqtt\Packet;
911
use BinSoul\Net\Mqtt\PacketFactory;
1012

11-
/**
12-
* Represents a flow starting with an outgoing CONNECT packet.
13-
*/
1413
class OutgoingConnectFlow extends BaseOutgoingConnectFlow
1514
{
1615
const PROTOCOL_LEVEL = 3;

src/Lite/PacketFactory.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client\Lite;
46

57
use BinSoul\Net\Mqtt\Exception\UnknownPacketTypeException;
68
use BinSoul\Net\Mqtt\Packet;
79
use BinSoul\Net\Mqtt\PacketFactory as PacketFactoryInterface;
810
use Fbns\Client\Common\PublishAckPacket;
911

10-
/**
11-
* Builds instances of the {@see Packet} interface.
12-
*/
1312
class PacketFactory implements PacketFactoryInterface
1413
{
15-
/**
16-
* Map of packet types to packet classes.
17-
*
18-
* @var string[]
19-
*/
2014
private static $mapping = [
2115
Packet::TYPE_CONNECT => ConnectRequestPacket::class,
2216
Packet::TYPE_CONNACK => ConnectResponsePacket::class,

src/Mqtt/FbnsConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client\Mqtt;
46

57
use BinSoul\Net\Mqtt\Message;

src/Network.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Fbns\Client;
46

57
use Fbns\Client\Network\NetworkSubtype;

0 commit comments

Comments
 (0)