Skip to content

Commit

Permalink
refactor(UpdateHasHttpClientDocCommentRector): Update createMethodPhp…
Browse files Browse the repository at this point in the history
…DocTagNode 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
  • Loading branch information
guanguans committed Jan 30, 2024
1 parent 3701631 commit 31af609
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
21 changes: 19 additions & 2 deletions src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class UpdateHasHttpClientDocCommentRector extends AbstractRector implements Conf
'create',
'hasHandler',
'resolve',
'getConfig',
];

private array $mixins = [
Expand Down Expand Up @@ -126,18 +127,34 @@ 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);

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(
Expand Down Expand Up @@ -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)"));
}
}
36 changes: 19 additions & 17 deletions src/Foundation/Traits/HasHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 31af609

Please sign in to comment.