From 31af60990352d415d7a7552951ef0add06c84b15 Mon Sep 17 00:00:00 2001 From: yaozm Date: Tue, 30 Jan 2024 11:30:52 +0800 Subject: [PATCH] refactor(UpdateHasHttpClientDocCommentRector): Update createMethodPhpDocTagNode method - Add the 'mixin' parameter to the createMethodPhpDocTagNode method - Update the return type of the method based on the 'mixin' parameter - Update the PhpDocTagNode creation to include the return type in the method signature --- .../UpdateHasHttpClientDocCommentRector.php | 21 +++++++++-- src/Foundation/Traits/HasHttpClient.php | 36 ++++++++++--------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php b/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php index a9669c2c..42ac4f27 100644 --- a/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php +++ b/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php @@ -40,6 +40,7 @@ class UpdateHasHttpClientDocCommentRector extends AbstractRector implements Conf 'create', 'hasHandler', 'resolve', + 'getConfig', ]; private array $mixins = [ @@ -126,7 +127,12 @@ public function refactor(Node $node) } } - $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('', new GenericTagValueNode(''))); + $phpDocInfo->addPhpDocTagNode($this->createEmptyDocTagNode()); + foreach ($this->mixins as $mixin) { + $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@see', new GenericTagValueNode('\\'.$mixin))); + } + + $phpDocInfo->addPhpDocTagNode($this->createEmptyDocTagNode()); $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@mixin', new GenericTagValueNode('\\'.self::MAIN_CLASS))); $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); @@ -134,10 +140,21 @@ public function refactor(Node $node) return $node; } + private function createEmptyDocTagNode(): PhpDocTagNode + { + return new PhpDocTagNode('', new GenericTagValueNode('')); + } + private function createMethodPhpDocTagNode(\ReflectionMethod $reflectionMethod): PhpDocTagNode { $static = $reflectionMethod->isStatic() ? 'static ' : ''; + $returnType = 'self '; + if (HandlerStack::class !== $reflectionMethod->class) { + $returnType = $reflectionMethod->getReturnType(); + $returnType and ($returnType->isBuiltin() or $returnType = "\\$returnType "); + } + $name = $reflectionMethod->getName(); $parameters = rtrim( @@ -172,6 +189,6 @@ static function (string $carry, \ReflectionParameter $reflectionParameter) { ', ' ); - return new PhpDocTagNode('@method', new GenericTagValueNode("{$static}self $name($parameters)")); + return new PhpDocTagNode('@method', new GenericTagValueNode("$static$returnType$name($parameters)")); } } diff --git a/src/Foundation/Traits/HasHttpClient.php b/src/Foundation/Traits/HasHttpClient.php index cea7a4f1..9547643b 100644 --- a/src/Foundation/Traits/HasHttpClient.php +++ b/src/Foundation/Traits/HasHttpClient.php @@ -24,23 +24,25 @@ * @method self before(string $findName, callable $middleware, string $withName = '') * @method self after(string $findName, callable $middleware, string $withName = '') * @method self remove($remove) - * @method self sendAsync(\Psr\Http\Message\RequestInterface $request, array $options = []) - * @method self sendRequest(\Psr\Http\Message\RequestInterface $request) - * @method self requestAsync(string $method, $uri = '', array $options = []) - * @method self request(string $method, $uri = '', array $options = []) - * @method self getConfig(string $option = null) - * @method self get($uri, array $options = []) - * @method self head($uri, array $options = []) - * @method self put($uri, array $options = []) - * @method self post($uri, array $options = []) - * @method self patch($uri, array $options = []) - * @method self delete($uri, array $options = []) - * @method self getAsync($uri, array $options = []) - * @method self headAsync($uri, array $options = []) - * @method self putAsync($uri, array $options = []) - * @method self postAsync($uri, array $options = []) - * @method self patchAsync($uri, array $options = []) - * @method self deleteAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface sendAsync(\Psr\Http\Message\RequestInterface $request, array $options = []) + * @method \Psr\Http\Message\ResponseInterface sendRequest(\Psr\Http\Message\RequestInterface $request) + * @method \GuzzleHttp\Promise\PromiseInterface requestAsync(string $method, $uri = '', array $options = []) + * @method \Psr\Http\Message\ResponseInterface request(string $method, $uri = '', array $options = []) + * @method \Psr\Http\Message\ResponseInterface get($uri, array $options = []) + * @method \Psr\Http\Message\ResponseInterface head($uri, array $options = []) + * @method \Psr\Http\Message\ResponseInterface put($uri, array $options = []) + * @method \Psr\Http\Message\ResponseInterface post($uri, array $options = []) + * @method \Psr\Http\Message\ResponseInterface patch($uri, array $options = []) + * @method \Psr\Http\Message\ResponseInterface delete($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface getAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface headAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface putAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface postAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface patchAsync($uri, array $options = []) + * @method \GuzzleHttp\Promise\PromiseInterface deleteAsync($uri, array $options = []) + * + * @see \GuzzleHttp\HandlerStack + * @see \GuzzleHttp\Client * * @mixin \Guanguans\Notify\Foundation\Client */