Skip to content

Commit

Permalink
Remove unnecessary exception comments
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Oct 9, 2024
1 parent 620346c commit dc35e03
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 119 deletions.
7 changes: 1 addition & 6 deletions src/Connection/AsyncTcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class AsyncTcpConnection extends TcpConnection
*
* @param string $remoteAddress
* @param array $socketContext
* @throws Exception
*/
public function __construct(string $remoteAddress, array $socketContext = [])
{
Expand Down Expand Up @@ -195,7 +194,7 @@ public function __construct(string $remoteAddress, array $socketContext = [])
if (!class_exists($this->protocol)) {
$this->protocol = "\\Workerman\\Protocols\\$scheme";
if (!class_exists($this->protocol)) {
throw new Exception("class \\Protocols\\$scheme not exist");
throw new RuntimeException("class \\Protocols\\$scheme not exist");
}
}
} else {
Expand All @@ -216,7 +215,6 @@ public function __construct(string $remoteAddress, array $socketContext = [])
*
* @param int $after
* @return void
* @throws Throwable
*/
public function reconnect(int $after = 0): void
{
Expand All @@ -236,7 +234,6 @@ public function reconnect(int $after = 0): void
* Do connect.
*
* @return void
* @throws Throwable
*/
public function connect(): void
{
Expand Down Expand Up @@ -302,7 +299,6 @@ public function connect(): void
* @param int $code
* @param mixed $msg
* @return void
* @throws Throwable
*/
protected function emitError(int $code, mixed $msg): void
{
Expand Down Expand Up @@ -351,7 +347,6 @@ public function getRemoteURI(): string
* Check connection is successfully established or failed.
*
* @return void
* @throws Throwable
*/
public function checkConnection(): void
{
Expand Down
9 changes: 3 additions & 6 deletions src/Connection/AsyncUdpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Workerman\Connection;

use Exception;
use RuntimeException;
use Throwable;
use Workerman\Protocols\ProtocolInterface;
use Workerman\Worker;
Expand Down Expand Up @@ -70,7 +71,7 @@ class AsyncUdpConnection extends UdpConnection
* Construct.
*
* @param string $remoteAddress
* @throws Exception
* @throws Throwable
*/
public function __construct($remoteAddress, $contextOption = [])
{
Expand All @@ -83,7 +84,7 @@ public function __construct($remoteAddress, $contextOption = [])
if (!class_exists($this->protocol)) {
$this->protocol = "\\Workerman\\Protocols\\$scheme";
if (!class_exists($this->protocol)) {
throw new Exception("class \\Protocols\\$scheme not exist");
throw new RuntimeException("class \\Protocols\\$scheme not exist");
}
}
}
Expand All @@ -97,7 +98,6 @@ public function __construct($remoteAddress, $contextOption = [])
*
* @param resource $socket
* @return void
* @throws Throwable
*/
public function baseRead($socket): void
{
Expand Down Expand Up @@ -127,7 +127,6 @@ public function baseRead($socket): void
* @param mixed $data
* @param bool $raw
* @return void
* @throws Throwable
*/
public function close(mixed $data = null, bool $raw = false): void
{
Expand All @@ -154,7 +153,6 @@ public function close(mixed $data = null, bool $raw = false): void
* @param mixed $sendBuffer
* @param bool $raw
* @return bool|null
* @throws Throwable
*/
public function send(mixed $sendBuffer, bool $raw = false): bool|null
{
Expand All @@ -176,7 +174,6 @@ public function send(mixed $sendBuffer, bool $raw = false): bool|null
* Connect.
*
* @return void
* @throws Throwable
*/
public function connect(): void
{
Expand Down
8 changes: 2 additions & 6 deletions src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ abstract public function isIpV6(): bool;
/**
* @param Throwable $exception
* @return void
* @throws Throwable
*/
public function error(Throwable $exception): void
{
Expand All @@ -181,11 +180,8 @@ public function error(Throwable $exception): void
try {
($this->errorHandler)($exception);
} catch (Throwable $exception) {
if ($this->eventLoop instanceof Event) {
echo $exception;
return;
}
throw $exception;
Worker::stopAll(250, $exception);
return;
}
}
}
12 changes: 1 addition & 11 deletions src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ public function getStatus(bool $rawOutput = true): int|string
* @param mixed $sendBuffer
* @param bool $raw
* @return bool|null
* @throws Throwable
*/
public function send(mixed $sendBuffer, bool $raw = false): bool|null
{
Expand All @@ -414,7 +413,7 @@ public function send(mixed $sendBuffer, bool $raw = false): bool|null
$parser = $this->protocol;
try {
$sendBuffer = $parser::encode($sendBuffer, $this);
} catch(\Throwable $e) {
} catch(Throwable $e) {
$this->error($e);
}
if ($sendBuffer === '') {
Expand Down Expand Up @@ -605,7 +604,6 @@ public function pauseRecv(): void
* Resumes reading after a call to pauseRecv.
*
* @return void
* @throws Throwable
*/
public function resumeRecv(): void
{
Expand All @@ -623,7 +621,6 @@ public function resumeRecv(): void
* @param resource $socket
* @param bool $checkEof
* @return void
* @throws Throwable
*/
public function baseRead($socket, bool $checkEof = true): void
{
Expand Down Expand Up @@ -764,7 +761,6 @@ public function baseRead($socket, bool $checkEof = true): void
* Base write handler.
*
* @return void
* @throws Throwable
*/
public function baseWrite(): void
{
Expand Down Expand Up @@ -811,7 +807,6 @@ public function baseWrite(): void
*
* @param resource $socket
* @return bool|int
* @throws Throwable
*/
public function doSslHandshake($socket): bool|int
{
Expand Down Expand Up @@ -898,7 +893,6 @@ public function consumeRecvBuffer(int $length): void
* @param mixed $data
* @param bool $raw
* @return void
* @throws Throwable
*/
public function close(mixed $data = null, bool $raw = false): void
{
Expand Down Expand Up @@ -964,7 +958,6 @@ public function getSocket()
* Check whether send buffer will be full.
*
* @return void
* @throws Throwable
*/
protected function checkBufferWillFull(): void
{
Expand All @@ -981,7 +974,6 @@ protected function checkBufferWillFull(): void
* Whether send buffer is full.
*
* @return bool
* @throws Throwable
*/
protected function bufferIsFull(): bool
{
Expand Down Expand Up @@ -1013,7 +1005,6 @@ public function bufferIsEmpty(): bool
* Destroy connection.
*
* @return void
* @throws Throwable
*/
public function destroy(): void
{
Expand Down Expand Up @@ -1101,7 +1092,6 @@ public function jsonSerialize(): array
* Destruct.
*
* @return void
* @throws Throwable
*/
public function __destruct()
{
Expand Down
19 changes: 10 additions & 9 deletions src/Events/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace Workerman\Events;

use SplPriorityQueue;
use Throwable;
use function count;
use function max;
use function microtime;
Expand Down Expand Up @@ -86,9 +88,9 @@ final class Select implements EventInterface
* Timer scheduler.
* {['data':timer_id, 'priority':run_timestamp], ..}
*
* @var \SplPriorityQueue
* @var SplPriorityQueue
*/
private \SplPriorityQueue $scheduler;
private SplPriorityQueue $scheduler;

/**
* All timer event listeners.
Expand Down Expand Up @@ -122,8 +124,8 @@ final class Select implements EventInterface
*/
public function __construct()
{
$this->scheduler = new \SplPriorityQueue();
$this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$this->scheduler = new SplPriorityQueue();
$this->scheduler->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
}

/**
Expand Down Expand Up @@ -299,7 +301,6 @@ public function offSignal(int $signal): bool
* Tick for timer.
*
* @return void
* @throws \Throwable
*/
protected function tick(): void
{
Expand Down Expand Up @@ -349,8 +350,8 @@ protected function tick(): void
*/
public function deleteAllTimer(): void
{
$this->scheduler = new \SplPriorityQueue();
$this->scheduler->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
$this->scheduler = new SplPriorityQueue();
$this->scheduler->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
$this->eventTimer = [];
}

Expand All @@ -367,7 +368,7 @@ public function run(): void
// Waiting read/write/signal/timeout events.
try {
@stream_select($read, $write, $except, 0, $this->selectTimeout);
} catch (\Throwable) {
} catch (Throwable) {
// do nothing
}
} else {
Expand Down Expand Up @@ -450,7 +451,7 @@ private function safeCall(callable $func, array $args = []): void
{
try {
$func(...$args);
} catch (\Throwable $e) {
} catch (Throwable $e) {
if ($this->errorHandler === null) {
echo $e;
} else {
Expand Down
5 changes: 1 addition & 4 deletions src/Protocols/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function requestClass(?string $className = null): string
*
* @param bool $value
*/
public static function enableCache(bool $value)
public static function enableCache(bool $value): void
{
static::$enableCache = $value;
}
Expand All @@ -97,7 +97,6 @@ public static function enableCache(bool $value)
* @param string $buffer
* @param TcpConnection $connection
* @return int
* @throws Throwable
*/
public static function input(string $buffer, TcpConnection $connection): int
{
Expand Down Expand Up @@ -194,7 +193,6 @@ public static function decode(string $buffer, TcpConnection $connection): Reques
* @param string|Response $response
* @param TcpConnection $connection
* @return string
* @throws Throwable
*/
public static function encode(mixed $response, TcpConnection $connection): string
{
Expand Down Expand Up @@ -266,7 +264,6 @@ public static function encode(mixed $response, TcpConnection $connection): strin
* @param resource $handler
* @param int $offset
* @param int $length
* @throws Throwable
*/
protected static function sendStream(TcpConnection $connection, $handler, int $offset = 0, int $length = 0): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Protocols/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function cookie(string $name = null, mixed $default = null): mixed
$mapped = array();

foreach ($cookies as $cookie) {
$cookie = explode('=', $cookie);
$cookie = explode('=', $cookie, 2);
if (count($cookie) !== 2) {
continue;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ protected function parseUploadFile(string $boundary, int $sectionStartOffset, st
break;

case "webkitrelativepath":
$file['full_path'] = \trim($value);
$file['full_path'] = trim($value);
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Protocols/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Workerman\Protocols\Http;

use Exception;
use Random\RandomException;
use RuntimeException;
use Workerman\Protocols\Http\Session\FileSessionHandler;
use Workerman\Protocols\Http\Session\SessionHandlerInterface;
Expand Down Expand Up @@ -153,7 +154,7 @@ class Session
*
* @var bool
*/
protected $isSafe = true;
protected bool $isSafe = true;

/**
* Session constructor.
Expand Down Expand Up @@ -437,7 +438,7 @@ public function __wakeup()
* __destruct.
*
* @return void
* @throws Exception
* @throws RandomException
*/
public function __destruct()
{
Expand Down
Loading

0 comments on commit dc35e03

Please sign in to comment.