From e9dd3613eb9900dd82067758135a0e028a204106 Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 16 Dec 2025 16:25:36 +0100 Subject: [PATCH] Refactor: use `::class` or `get_debug_type` by Rector rules: Rector\Php80\Rector\FuncCall\ClassOnObjectRector; Rector\Php80\Rector\Ternary\GetDebugTypeRector; --- lib/Adapter/DTL/DTLArgumentResolver.php | 2 +- lib/Core/Command/CommandDispatcher.php | 2 +- lib/Core/Diagnostics/AggregateDiagnosticsProvider.php | 4 ++-- .../LanguageSeverProtocolParamsResolver.php | 6 +++--- .../Dispatcher/Factory/ClosureDispatcherFactory.php | 2 +- lib/Core/Handler/HandlerMethodResolver.php | 4 ++-- lib/Core/Handler/HandlerMethodRunner.php | 6 +++--- lib/Core/Server/Initializer/RequestInitializer.php | 2 +- lib/Core/Server/LanguageServer.php | 2 +- lib/Core/Server/Transmitter/TestMessageTransmitter.php | 4 ++-- lib/Core/Service/ServiceManager.php | 10 +++++----- lib/Middleware/ErrorHandlingMiddleware.php | 4 ++-- lib/Test/LanguageServerTester.php | 2 +- .../ListenerProvider/RecordingListenerProvider.php | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Adapter/DTL/DTLArgumentResolver.php b/lib/Adapter/DTL/DTLArgumentResolver.php index 383d9b1d..d80ade44 100644 --- a/lib/Adapter/DTL/DTLArgumentResolver.php +++ b/lib/Adapter/DTL/DTLArgumentResolver.php @@ -24,6 +24,6 @@ public function resolveArguments(object $object, string $method, Message $messag return []; } - return $this->dtlArgumnetResolver->resolveArguments(get_class($object), $method, $message->params ?? []); + return $this->dtlArgumnetResolver->resolveArguments($object::class, $method, $message->params ?? []); } } diff --git a/lib/Core/Command/CommandDispatcher.php b/lib/Core/Command/CommandDispatcher.php index 309bc41f..9e565080 100644 --- a/lib/Core/Command/CommandDispatcher.php +++ b/lib/Core/Command/CommandDispatcher.php @@ -56,7 +56,7 @@ private function addCommand(string $id, Command $invokable): void if (!is_callable($invokable)) { throw new RuntimeException(sprintf( 'Object "%s" is not invokable', - get_class($invokable) + $invokable::class )); } diff --git a/lib/Core/Diagnostics/AggregateDiagnosticsProvider.php b/lib/Core/Diagnostics/AggregateDiagnosticsProvider.php index be373d0b..e8f87731 100644 --- a/lib/Core/Diagnostics/AggregateDiagnosticsProvider.php +++ b/lib/Core/Diagnostics/AggregateDiagnosticsProvider.php @@ -42,12 +42,12 @@ public function provideDiagnostics(TextDocumentItem $textDocument, CancellationT $this->logger->debug(sprintf( 'Diagnostic finsihed in "%s" (%s)', number_format(microtime(true) - $start, 2), - get_class($provider) + $provider::class )); } catch (Throwable $throwable) { $this->logger->error(sprintf( 'Diagnostic error from provider "%s": %s', - get_class($provider), + $provider::class, $throwable->getMessage() ), [ 'trace' => $throwable->getTraceAsString() diff --git a/lib/Core/Dispatcher/ArgumentResolver/LanguageSeverProtocolParamsResolver.php b/lib/Core/Dispatcher/ArgumentResolver/LanguageSeverProtocolParamsResolver.php index 658ad6d9..5bdce38e 100644 --- a/lib/Core/Dispatcher/ArgumentResolver/LanguageSeverProtocolParamsResolver.php +++ b/lib/Core/Dispatcher/ArgumentResolver/LanguageSeverProtocolParamsResolver.php @@ -27,7 +27,7 @@ public function resolveArguments(object $object, string $method, Message $messag if (!$reflection->hasMethod($method)) { throw new CouldNotResolveArguments(sprintf( 'Class "%s" has no method "%s"', - get_class($object), + $object::class, $method )); } @@ -60,7 +60,7 @@ public function resolveArguments(object $object, string $method, Message $messag throw new CouldNotResolveArguments(sprintf( 'First argument of LSP class "%s" method "%s" must be the LSP param object, it is "%s"', - get_class($object), + $object::class, $method, $classFqn )); @@ -68,7 +68,7 @@ public function resolveArguments(object $object, string $method, Message $messag throw new CouldNotResolveArguments(sprintf( 'Class "%s" method "%s" is not a language server protocol-accepting method', - get_class($object), + $object::class, $method )); } diff --git a/lib/Core/Dispatcher/Factory/ClosureDispatcherFactory.php b/lib/Core/Dispatcher/Factory/ClosureDispatcherFactory.php index e561483d..9d33f57a 100644 --- a/lib/Core/Dispatcher/Factory/ClosureDispatcherFactory.php +++ b/lib/Core/Dispatcher/Factory/ClosureDispatcherFactory.php @@ -22,7 +22,7 @@ public function create(MessageTransmitter $transmitter, InitializeParams $initia if (!$dispatcher instanceof Dispatcher) { throw new RuntimeException(sprintf( 'Closure must return a "Dispatcher" instance got "%s"', - is_object($dispatcher) ? get_class($dispatcher) : gettype($dispatcher) + get_debug_type($dispatcher) )); } diff --git a/lib/Core/Handler/HandlerMethodResolver.php b/lib/Core/Handler/HandlerMethodResolver.php index 11f595d9..c040c560 100644 --- a/lib/Core/Handler/HandlerMethodResolver.php +++ b/lib/Core/Handler/HandlerMethodResolver.php @@ -13,7 +13,7 @@ public function resolveHandlerMethod(Handler $handler, string $languageServerMet if (!array_key_exists($languageServerMethod, $handlerMap)) { throw new RuntimeException(sprintf( 'Resolved handler "%s" has not declared support for LSP method "%s", it declared support for "%s"', - get_class($handler), + $handler::class, $languageServerMethod, implode('", "', $handlerMap) )); @@ -24,7 +24,7 @@ public function resolveHandlerMethod(Handler $handler, string $languageServerMet if (!method_exists($handler, $method)) { throw new RuntimeException(sprintf( 'Handler "%s" for method "%s" does not have the "%s" method defined, it has "%s"', - get_class($handler), + $handler::class, $languageServerMethod, $method, implode('", "', get_class_methods($handler)) diff --git a/lib/Core/Handler/HandlerMethodRunner.php b/lib/Core/Handler/HandlerMethodRunner.php index ccbd975d..5d548942 100644 --- a/lib/Core/Handler/HandlerMethodRunner.php +++ b/lib/Core/Handler/HandlerMethodRunner.php @@ -41,7 +41,7 @@ public function dispatch(Message $request): Promise ) { throw new RuntimeException(sprintf( 'Message must either be a Notification or a Request, got "%s"', - get_class($request) + $request::class )); } @@ -64,9 +64,9 @@ public function dispatch(Message $request): Promise if (!$promise instanceof Promise) { throw new RuntimeException(sprintf( 'Handler "%s:%s" must return instance of Amp\\Promise, got "%s"', - get_class($handler), + $handler::class, $method, - is_object($promise) ? get_class($promise) : gettype($promise) + get_debug_type($promise) )); } diff --git a/lib/Core/Server/Initializer/RequestInitializer.php b/lib/Core/Server/Initializer/RequestInitializer.php index 0b415294..fe753e76 100644 --- a/lib/Core/Server/Initializer/RequestInitializer.php +++ b/lib/Core/Server/Initializer/RequestInitializer.php @@ -15,7 +15,7 @@ public function provideInitializeParams(Message $request): InitializeParams if (!$request instanceof RequestMessage) { throw new RuntimeException(sprintf( 'First request must be a RequestMessage (to initialize), got "%s"', - get_class($request) + $request::class )); } diff --git a/lib/Core/Server/LanguageServer.php b/lib/Core/Server/LanguageServer.php index 3acc1213..c3bfe974 100644 --- a/lib/Core/Server/LanguageServer.php +++ b/lib/Core/Server/LanguageServer.php @@ -97,7 +97,7 @@ public function address(): ?string if (!$this->streamProvider instanceof SocketStreamProvider) { throw new RuntimeException(sprintf( 'Cannot get address on non-socket stream provider, using "%s"', - get_class($this->streamProvider) + $this->streamProvider::class )); } diff --git a/lib/Core/Server/Transmitter/TestMessageTransmitter.php b/lib/Core/Server/Transmitter/TestMessageTransmitter.php index 53792692..b3d1957c 100644 --- a/lib/Core/Server/Transmitter/TestMessageTransmitter.php +++ b/lib/Core/Server/Transmitter/TestMessageTransmitter.php @@ -55,7 +55,7 @@ public function shiftNotification(): ?NotificationMessage if (!$message instanceof NotificationMessage) { throw new RuntimeException(sprintf( 'Expected NotificationMessage, got "%s"', - get_class($message) + $message::class )); } @@ -73,7 +73,7 @@ public function shiftRequest(): ?RequestMessage if (!$message instanceof RequestMessage) { throw new RuntimeException(sprintf( 'Expected RequestMessage, got "%s"', - get_class($message) + $message::class )); } diff --git a/lib/Core/Service/ServiceManager.php b/lib/Core/Service/ServiceManager.php index 5c8c6ead..0ba74ec1 100644 --- a/lib/Core/Service/ServiceManager.php +++ b/lib/Core/Service/ServiceManager.php @@ -47,12 +47,12 @@ public function start(string $serviceName): void )); } - $this->logger->info(sprintf('Starting service: %s (%s)', $serviceName, get_class($provider))); + $this->logger->info(sprintf('Starting service: %s (%s)', $serviceName, $provider::class)); if (!method_exists($provider, $serviceName)) { throw new RuntimeException(sprintf( 'Service provider "%s" has no service method "%s"', - get_class($provider), + $provider::class, $serviceName )); } @@ -67,8 +67,8 @@ public function start(string $serviceName): void if (!$promise instanceof Promise) { throw new RuntimeException(sprintf( 'Service method "%s" must return a Promise, got "%s"', - get_class($provider) . '::' . $serviceName, - is_object($promise) ? get_class($promise) : gettype($promise) + $provider::class . '::' . $serviceName, + get_debug_type($promise) )); } @@ -78,7 +78,7 @@ public function start(string $serviceName): void $this->logger->error(sprintf( 'Error in service "%s" "%s:%s": %s', $serviceName, - get_class($provider), + $provider::class, __FUNCTION__, $error->getMessage() )); diff --git a/lib/Middleware/ErrorHandlingMiddleware.php b/lib/Middleware/ErrorHandlingMiddleware.php index 5c1c12f3..a78b1cf4 100644 --- a/lib/Middleware/ErrorHandlingMiddleware.php +++ b/lib/Middleware/ErrorHandlingMiddleware.php @@ -45,10 +45,10 @@ public function process(Message $request, RequestHandler $handler): Promise ) )); } catch (Throwable $error) { - $message = sprintf('Exception [%s] %s', get_class($error), $error->getMessage()); + $message = sprintf('Exception [%s] %s', $error::class, $error->getMessage()); $this->logger->error(sprintf( 'Error when handling "%s" (%s): %s', - get_class($request), + $request::class, json_encode($request), $message )); diff --git a/lib/Test/LanguageServerTester.php b/lib/Test/LanguageServerTester.php index c2bdc857..039fd469 100644 --- a/lib/Test/LanguageServerTester.php +++ b/lib/Test/LanguageServerTester.php @@ -148,7 +148,7 @@ public function initialize(): InitializeResult if (!$result instanceof InitializeResult) { throw new RuntimeException(sprintf( 'Initialize did not return an InitializeResult, got "%s"', - is_object($result) ? get_class($result) : gettype($result) + get_debug_type($result) )); } diff --git a/lib/Test/ListenerProvider/RecordingListenerProvider.php b/lib/Test/ListenerProvider/RecordingListenerProvider.php index b12e656e..df89ca13 100644 --- a/lib/Test/ListenerProvider/RecordingListenerProvider.php +++ b/lib/Test/ListenerProvider/RecordingListenerProvider.php @@ -39,7 +39,7 @@ public function shift(string $type): object throw new RuntimeException(sprintf( 'Expected event of type "%s" but got "%s"', $type, - get_class($next) + $next::class )); }