Skip to content

Commit 1572c75

Browse files
authored
Format code (#5172)
1 parent 0323477 commit 1572c75

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

src/CoreMiddleware.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
use Hyperf\Rpc\Protocol;
2020
use Hyperf\Rpc\Response as RPCResponse;
2121
use Hyperf\RpcMultiplex\Contract\HttpMessageBuilderInterface;
22+
use InvalidArgumentException;
2223
use Psr\Container\ContainerInterface;
2324
use Psr\Http\Message\ResponseInterface;
2425
use Psr\Http\Message\ServerRequestInterface;
26+
use Throwable;
2527

2628
class CoreMiddleware extends \Hyperf\RpcServer\CoreMiddleware
2729
{
@@ -53,14 +55,14 @@ protected function handleFound(Dispatched $dispatched, ServerRequestInterface $r
5355

5456
try {
5557
$parameters = $this->parseMethodParameters($controller, $action, $request->getParsedBody());
56-
} catch (\InvalidArgumentException $exception) {
58+
} catch (InvalidArgumentException $exception) {
5759
$data = $this->buildErrorData($request, 400, 'The params is invalid.', $exception);
5860
return $this->responseBuilder->buildResponse($request, $data);
5961
}
6062

6163
try {
6264
$response = $controllerInstance->{$action}(...$parameters);
63-
} catch (\Throwable $exception) {
65+
} catch (Throwable $exception) {
6466
$data = $this->buildErrorData($request, 500, $exception->getMessage(), $exception);
6567
$response = $this->responseBuilder->buildResponse($request, $data);
6668
$this->responseBuilder->persistToContext($response);
@@ -88,7 +90,7 @@ protected function transferToResponse($response, ServerRequestInterface $request
8890
return $this->responseBuilder->buildResponse($request, $response);
8991
}
9092

91-
protected function buildErrorData(ServerRequestInterface $request, int $code, string $message = null, \Throwable $throwable = null): array
93+
protected function buildErrorData(ServerRequestInterface $request, int $code, string $message = null, Throwable $throwable = null): array
9294
{
9395
$id = $request->getAttribute(Constant::REQUEST_ID);
9496

src/DataFormatter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Hyperf\RpcClient\Exception\RequestException;
2020
use Hyperf\RpcMultiplex\Contract\DataFetcherInterface;
2121
use Hyperf\Utils\Codec\Json;
22+
use Throwable;
2223

2324
class DataFormatter implements DataFormatterInterface, DataFetcherInterface
2425
{
@@ -51,7 +52,7 @@ public function formatResponse(Response $response): array
5152
public function formatErrorResponse(ErrorResponse $response): array
5253
{
5354
$exception = $response->getException();
54-
if ($exception instanceof \Throwable) {
55+
if ($exception instanceof Throwable) {
5556
$exception = [
5657
'class' => get_class($exception),
5758
'code' => $exception->getCode(),

src/Exception/NoAvailableNodesException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
namespace Hyperf\RpcMultiplex\Exception;
1313

14-
class NoAvailableNodesException extends \RuntimeException
14+
use RuntimeException;
15+
16+
class NoAvailableNodesException extends RuntimeException
1517
{
1618
}

src/Exception/NotSupportException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
namespace Hyperf\RpcMultiplex\Exception;
1313

14-
class NotSupportException extends \RuntimeException
14+
use RuntimeException;
15+
16+
class NotSupportException extends RuntimeException
1517
{
1618
}

src/Transporter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Multiplex\Exception\ChannelClosedException;
1919
use Multiplex\Exception\ClientConnectFailedException;
2020
use Psr\Container\ContainerInterface;
21+
use Throwable;
2122

2223
class Transporter implements TransporterInterface
2324
{
@@ -48,7 +49,7 @@ public function send(string $data)
4849
$result = retry($retryCount, function () use ($data) {
4950
try {
5051
return $this->factory->get()->request($data);
51-
} catch (\Throwable $exception) {
52+
} catch (Throwable $exception) {
5253
if ($this->shouldBeRetry($exception)) {
5354
throw $exception;
5455
}
@@ -80,7 +81,7 @@ public function setLoadBalancer(LoadBalancerInterface $loadBalancer): Transporte
8081
return $this;
8182
}
8283

83-
protected function shouldBeRetry(\Throwable $throwable): bool
84+
protected function shouldBeRetry(Throwable $throwable): bool
8485
{
8586
return $throwable instanceof ClientConnectFailedException
8687
|| $throwable instanceof ChannelClosedException;

tests/Cases/AbstractTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Mockery;
1515
use PHPUnit\Framework\TestCase;
16+
use ReflectionClass;
1617

1718
/**
1819
* Class AbstractTestCase.
@@ -26,7 +27,7 @@ protected function tearDown(): void
2627

2728
protected function invoke($class, string $method)
2829
{
29-
$ref = new \ReflectionClass($class);
30+
$ref = new ReflectionClass($class);
3031
$method = $ref->getMethod($method);
3132
$method->setAccessible(true);
3233
return $method->invoke($method);

tests/Cases/SocketFactoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Hyperf\RpcMultiplex\SocketFactory;
2121
use Hyperf\Utils\Reflection\ClassInvoker;
2222
use HyperfTest\RpcMultiplex\Stub\ContainerStub;
23+
use Mockery;
2324

2425
/**
2526
* @internal
@@ -42,7 +43,7 @@ public function testSocketConfig()
4243
'client_count' => 4,
4344
]);
4445

45-
$balancer = \Mockery::mock(LoadBalancerInterface::class);
46+
$balancer = Mockery::mock(LoadBalancerInterface::class);
4647
$balancer->shouldReceive('isAutoRefresh')->andReturnFalse();
4748
$factory->setLoadBalancer($balancer);
4849
$balancer->shouldReceive('getNodes')->andReturn([
@@ -168,7 +169,7 @@ public function testSocketRefreshInMoreThanOneCoroutine()
168169
]);
169170

170171
go(function () use ($factory) {
171-
$balancer = \Mockery::mock(LoadBalancerInterface::class);
172+
$balancer = Mockery::mock(LoadBalancerInterface::class);
172173
$balancer->shouldReceive('isAutoRefresh')->andReturnFalse();
173174
$factory->setLoadBalancer($balancer);
174175
$balancer->shouldReceive('getNodes')->andReturn([

0 commit comments

Comments
 (0)