Skip to content

Commit

Permalink
update ExtendedPromiseInterface and resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Naneynonn committed Nov 19, 2024
1 parent 44e465f commit 4972b74
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 373 deletions.
6 changes: 3 additions & 3 deletions fakes/PromiseFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Fakes\Ragnarok\Fenrir;

use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;
use React\Promise\Promise;
use Throwable;

Expand All @@ -15,7 +15,7 @@ class PromiseFake
*
* @param mixed $return What the promise should resolve to
*/
public static function get(mixed $return = null): ExtendedPromiseInterface
public static function get(mixed $return = null): PromiseInterface
{
return new Promise(static function ($resolve) use ($return) {
$resolve($return);
Expand All @@ -27,7 +27,7 @@ public static function get(mixed $return = null): ExtendedPromiseInterface
*
* @param Throwable $e The exception
*/
public static function reject(Throwable $e): ExtendedPromiseInterface
public static function reject(Throwable $e): PromiseInterface
{
return new Promise(static function ($resolve, $reject) use ($e) {
$reject($e);
Expand Down
4 changes: 2 additions & 2 deletions fakes/RetrierFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Fakes\Ragnarok\Fenrir;

use Exan\Retrier\Retrier;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

class RetrierFake extends Retrier
{
public function retry(int $attempts, callable $action): ExtendedPromiseInterface
public function retry(int $attempts, callable $action): PromiseInterface
{
return PromiseFake::get($action(1));
}
Expand Down
16 changes: 5 additions & 11 deletions fakes/WebsocketFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@
use Evenement\EventEmitter;
use JsonSerializable;
use Ragnarok\Fenrir\WebsocketInterface;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

class WebsocketFake extends EventEmitter implements WebsocketInterface
{
public array $openings = [];

public function open(string $url): ExtendedPromiseInterface
public function open(string $url): PromiseInterface
{
$this->openings[] = $url;

return PromiseFake::get();
}

public function close(int $code, string $reason): void
{
}
public function close(int $code, string $reason): void {}

public function send(string $message, bool $useBucket = true): void
{
}
public function send(string $message, bool $useBucket = true): void {}

public function sendAsJson(array|JsonSerializable $item, bool $useBucket): void
{
}
public function sendAsJson(array|JsonSerializable $item, bool $useBucket): void {}
}
6 changes: 3 additions & 3 deletions src/Gateway/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Ratchet\RFC6455\Messaging\MessageInterface;
use React\EventLoop\LoopInterface;
use React\EventLoop\TimerInterface;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

/**
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
Expand Down Expand Up @@ -183,7 +183,7 @@ public function setSequence(int $sequence): void
$this->sequence = $sequence;
}

public function connect(string $url): ExtendedPromiseInterface
public function connect(string $url): PromiseInterface
{
$url .= '?' . http_build_query(self::QUERY_DATA);

Expand Down Expand Up @@ -309,7 +309,7 @@ public function resume(): void
], true);
}

public function open(): ExtendedPromiseInterface
public function open(): PromiseInterface
{
return $this->connect(self::DEFAULT_WEBSOCKET_URL);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Gateway/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Exan\Eventer\Eventer;
use Ragnarok\Fenrir\EventHandler;
use Ragnarok\Fenrir\Gateway\Helpers\PresenceUpdateBuilder;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

interface ConnectionInterface
{
Expand All @@ -16,7 +16,7 @@ public function getDefaultUrl(): string;
public function getSequence(): ?int;
public function setSequence(int $sequence);

public function connect(string $url): ExtendedPromiseInterface;
public function connect(string $url): PromiseInterface;
public function disconnect(int $code, string $reason): void;

public function setSessionId(string $sessionId): void;
Expand Down
8 changes: 3 additions & 5 deletions src/Interaction/ButtonInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
use Ragnarok\Fenrir\Discord;
use Ragnarok\Fenrir\Gateway\Events\InteractionCreate;
use Ragnarok\Fenrir\Interaction\Helpers\InteractionCallbackBuilder;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

class ButtonInteraction
{
public function __construct(public readonly InteractionCreate $interaction, private Discord $discord)
{
}
public function __construct(public readonly InteractionCreate $interaction, private Discord $discord) {}

public function createInteractionResponse(
InteractionCallbackBuilder $interactionCallbackBuilder
): ExtendedPromiseInterface {
): PromiseInterface {
return $this->discord->rest->webhook->createInteractionResponse(
$this->interaction->id,
$this->interaction->token,
Expand Down
14 changes: 7 additions & 7 deletions src/Interaction/CommandInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Ragnarok\Fenrir\Interaction\Helpers\InteractionCallbackBuilder;
use Ragnarok\Fenrir\Parts\ApplicationCommandInteractionDataOptionStructure as OptionStructure;
use Ragnarok\Fenrir\Rest\Helpers\Webhook\EditWebhookBuilder;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

use function Freezemage\ArrayUtils\find as array_find;

Expand All @@ -30,23 +30,23 @@ public function __construct(public readonly InteractionCreate $interaction, priv

public function createInteractionResponse(
InteractionCallbackBuilder $interactionCallbackBuilder
): ExtendedPromiseInterface {
): PromiseInterface {
return $this->discord->rest->webhook->createInteractionResponse(
$this->interaction->id,
$this->interaction->token,
$interactionCallbackBuilder
);
}

public function getInteractionResponse(): ExtendedPromiseInterface
public function getInteractionResponse(): PromiseInterface
{
return $this->discord->rest->webhook->getOriginalInteractionResponse(
$this->interaction->application_id,
$this->interaction->token
);
}

public function editInteractionResponse(EditWebhookBuilder $webhookBuilder): ExtendedPromiseInterface
public function editInteractionResponse(EditWebhookBuilder $webhookBuilder): PromiseInterface
{
return $this->discord->rest->webhook->editOriginalInteractionResponse(
$this->interaction->application_id,
Expand All @@ -55,7 +55,7 @@ public function editInteractionResponse(EditWebhookBuilder $webhookBuilder): Ext
);
}

public function deleteInteractionResponse(): ExtendedPromiseInterface
public function deleteInteractionResponse(): PromiseInterface
{
return $this->discord->rest->webhook->deleteOriginalInteractionResponse(
$this->interaction->application_id,
Expand All @@ -73,7 +73,7 @@ private function findOption(array $options, array $segments): ?OptionStructure
{
$currentSegment = array_shift($segments);

$option = array_find($options, fn (OptionStructure $option) => $option->name === $currentSegment);
$option = array_find($options, fn(OptionStructure $option) => $option->name === $currentSegment);

if (empty($segments)) {
return $option;
Expand Down Expand Up @@ -102,7 +102,7 @@ private function getSubCommandNameFromOptions(array $options): ?string
{
$subItem = array_values(array_filter(
$options,
static fn (OptionStructure $option) => in_array(
static fn(OptionStructure $option) => in_array(
$option->type,
[OptionTypes::SUB_COMMAND, OptionTypes::SUB_COMMAND_GROUP]
)
Expand Down
10 changes: 5 additions & 5 deletions src/Rest/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Ragnarok\Fenrir\Rest;

use Ragnarok\Fenrir\Parts\Application as PartsApplication;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

/**
* @see https://discord.com/developers/docs/resources/application
Expand All @@ -15,9 +15,9 @@ class Application extends HttpResource
/**
* @see https://discord.com/developers/docs/resources/application#get-current-application
*
* @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\Application>
* @return PromiseInterface<\Ragnarok\Fenrir\Parts\Application>
*/
public function getCurrent(): ExtendedPromiseInterface
public function getCurrent(): PromiseInterface
{
return $this->mapPromise(
$this->http->get(
Expand All @@ -30,9 +30,9 @@ public function getCurrent(): ExtendedPromiseInterface
/**
* @see https://discord.com/developers/docs/resources/application#edit-current-application
*
* @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\Application>
* @return PromiseInterface<\Ragnarok\Fenrir\Parts\Application>
*/
public function editCurrent(array $params): ExtendedPromiseInterface
public function editCurrent(array $params): PromiseInterface
{
return $this->mapPromise(
$this->http->patch(
Expand Down
10 changes: 5 additions & 5 deletions src/Rest/ApplicationRoleConnectionMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Discord\Http\Endpoint;
use Ragnarok\Fenrir\Parts\ApplicationRoleConnectionMetadata as PartsApplicationRoleConnectionMetadata;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

/**
* @see https://discord.com/developers/docs/resources/application-role-connection-metadata
Expand All @@ -16,9 +16,9 @@ class ApplicationRoleConnectionMetadata extends HttpResource
/**
* @see https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records
*
* @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\ApplicationRoleConnectionMetadata>
* @return PromiseInterface<\Ragnarok\Fenrir\Parts\ApplicationRoleConnectionMetadata>
*/
public function getRecords(): ExtendedPromiseInterface
public function getRecords(): PromiseInterface
{
return $this->mapPromise(
$this->http->get(
Expand All @@ -31,9 +31,9 @@ public function getRecords(): ExtendedPromiseInterface
/**
* @see https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records
*
* @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\ApplicationRoleConnectionMetadata>
* @return PromiseInterface<\Ragnarok\Fenrir\Parts\ApplicationRoleConnectionMetadata>
*/
public function updateRecords(array $params): ExtendedPromiseInterface
public function updateRecords(array $params): PromiseInterface
{
return $this->mapPromise(
$this->http->put(
Expand Down
6 changes: 3 additions & 3 deletions src/Rest/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Discord\Http\Endpoint;
use Ragnarok\Fenrir\Parts\AuditLog as PartsAuditLog;
use Ragnarok\Fenrir\Rest\Helpers\AuditLog\GetGuildAuditLogsBuilder;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\PromiseInterface;

/**
* @see https://discord.com/developers/docs/resources/audit-log
Expand All @@ -17,12 +17,12 @@ class AuditLog extends HttpResource
/**
* @see https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log
*
* @return ExtendedPromiseInterface<\Ragnarok\Fenrir\Parts\AuditLog>
* @return PromiseInterface<\Ragnarok\Fenrir\Parts\AuditLog>
*/
public function getGuildAuditLogs(
string $guildId,
GetGuildAuditLogsBuilder $getGuildAuditLogsBuilder
): ExtendedPromiseInterface {
): PromiseInterface {
return $this->mapPromise(
$this->http->get(
Endpoint::bind(
Expand Down
Loading

0 comments on commit 4972b74

Please sign in to comment.