Skip to content

Commit

Permalink
fix: resolved #2833
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Aug 19, 2024
1 parent 595fb5a commit 10571f5
Show file tree
Hide file tree
Showing 64 changed files with 131 additions and 166 deletions.
16 changes: 8 additions & 8 deletions src/Kernel/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,25 @@ public function all(): array
}

#[Pure]
public function offsetExists(mixed $key): bool
public function offsetExists(mixed $offset): bool
{
return $this->has(strval($key));
return $this->has(strval($offset));
}

#[Pure]
public function offsetGet(mixed $key): mixed
public function offsetGet(mixed $offset): mixed
{
return $this->get(strval($key));
return $this->get(strval($offset));
}

public function offsetSet(mixed $key, mixed $value): void
public function offsetSet(mixed $offset, mixed $value): void
{
$this->set(strval($key), $value);
$this->set(strval($offset), $value);
}

public function offsetUnset(mixed $key): void
public function offsetUnset(mixed $offset): void
{
$this->set(strval($key), null);
$this->set(strval($offset), null);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/BadMethodCallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class BadMethodCallException extends Exception
{
}
class BadMethodCallException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class BadRequestException extends Exception
{
}
class BadRequestException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class BadResponseException extends Exception
{
}
class BadResponseException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/DecryptException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class DecryptException extends Exception
{
}
class DecryptException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Exception as BaseException;

class Exception extends BaseException
{
}
class Exception extends BaseException {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class InvalidArgumentException extends Exception
{
}
class InvalidArgumentException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/InvalidConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class InvalidConfigException extends Exception
{
}
class InvalidConfigException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class RuntimeException extends Exception
{
}
class RuntimeException extends Exception {}
4 changes: 1 addition & 3 deletions src/Kernel/Exceptions/ServiceNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\Kernel\Exceptions;

class ServiceNotFoundException extends Exception
{
}
class ServiceNotFoundException extends Exception {}
2 changes: 1 addition & 1 deletion src/Kernel/Form/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function fromContents(
?string $encoding = null
): DataPart {
if ($contentType === null) {
$mimeTypes = new MimeTypes();
$mimeTypes = new MimeTypes;

if ($filename) {
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
Expand Down
4 changes: 1 addition & 3 deletions src/Kernel/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class Form
/**
* @param array<string|array|DataPart> $fields
*/
public function __construct(protected array $fields)
{
}
public function __construct(protected array $fields) {}

/**
* @param array<string|array|DataPart> $fields
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/HttpClient/AccessTokenExpiredRetryStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function shouldRetry(
?string $responseContent,
?TransportExceptionInterface $exception
): ?bool {
if ((bool) $responseContent && $this->decider && ($this->decider)($context, $responseContent, $exception)) {
if ($responseContent && $this->decider && ($this->decider)($context, $responseContent, $exception)) {
if ($this->accessToken instanceof RefreshableAccessTokenInterface) {
return (bool) $this->accessToken->refresh();
}
Expand Down
12 changes: 5 additions & 7 deletions src/Kernel/HttpClient/RequestUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public static function formatOptions(array $options, string $method): array
}

/**
* @param array<string, array<string,mixed>|mixed> $options
* @return array<string, array|mixed>
* @param array{headers?:array<string, string>, xml?:array|string, body?:array|string, json?:array|string} $options
* @return array{headers?:array<string, string|array<string, string>|array<string>>, xml?:array|string, body?:array|string}
*/
public static function formatBody(array $options): array
{
Expand All @@ -121,8 +121,7 @@ public static function formatBody(array $options): array
}

if (! $contentType) {
/** @phpstan-ignore-next-line */
$options['headers']['Content-Type'] = [$options['headers'][] = 'Content-Type: text/xml'];
$options['headers']['Content-Type'] = 'text/xml';
}

$options['body'] = $options['xml'];
Expand All @@ -143,8 +142,7 @@ public static function formatBody(array $options): array
}

if (! $contentType) {
/** @phpstan-ignore-next-line */
$options['headers']['Content-Type'] = [$options['headers'][] = 'Content-Type: application/json'];
$options['headers']['Content-Type'] = 'application/json';
}

$options['body'] = $options['json'];
Expand All @@ -156,7 +154,7 @@ public static function formatBody(array $options): array

public static function createDefaultServerRequest(): ServerRequestInterface
{
$psr17Factory = new Psr17Factory();
$psr17Factory = new Psr17Factory;

$creator = new ServerRequestCreator(
serverRequestFactory: $psr17Factory,
Expand Down
7 changes: 2 additions & 5 deletions src/Kernel/HttpClient/RequestWithPresets.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ public function with(string|array $key, mixed $value = null): static

/**
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFile(string $pathOrContents, string $formName = 'file', ?string $filename = null): static
{
$file = is_file($pathOrContents) ? File::fromPath(
$pathOrContents,
$filename
) : File::withContents($pathOrContents, $filename);
) : File::fromContents($pathOrContents, $filename);

/**
* @var array{headers: array<string, string>, body: string}
* @var array{headers: array<string, string>, body: string} $options
*/
$options = Form::create([$formName => $file])->toOptions();

Expand All @@ -109,7 +108,6 @@ public function withFile(string $pathOrContents, string $formName = 'file', ?str

/**
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFileContents(string $contents, string $formName = 'file', ?string $filename = null): static
{
Expand All @@ -118,7 +116,6 @@ public function withFileContents(string $contents, string $formName = 'file', ?s

/**
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFiles(array $files): static
{
Expand Down
7 changes: 3 additions & 4 deletions src/Kernel/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public function __construct(
protected ResponseInterface $response,
protected ?Closure $failureJudge = null,
protected bool $throw = true
) {
}
) {}

public function throw(bool $throw = true): static
{
Expand Down Expand Up @@ -161,7 +160,7 @@ public function toStream(?bool $throw = null)
throw new BadMethodCallException(sprintf('%s does\'t implements %s', \get_class($this->response), StreamableInterface::class));
}

return StreamWrapper::createResource(new MockResponse());
return StreamWrapper::createResource(new MockResponse);
}

/**
Expand All @@ -185,7 +184,7 @@ public function toPsrResponse(?ResponseFactoryInterface $responseFactory = null,
}

try {
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory : null;
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); /** @phpstan-ignore-line */
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); /** @phpstan-ignore-line */

Expand Down
2 changes: 0 additions & 2 deletions src/Kernel/ServerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use const PHP_OUTPUT_HANDLER_FLUSHABLE;
use const PHP_OUTPUT_HANDLER_REMOVABLE;

use JetBrains\PhpStorm\Pure;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

Expand All @@ -25,7 +24,6 @@ public function __construct(protected ResponseInterface $response)
$this->response->getBody()->rewind();
}

#[Pure]
public static function make(ResponseInterface $response): ServerResponse
{
if ($response instanceof ServerResponse) {
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Traits/InteractWithHandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function makeClosure(callable|string $handler): callable
*
* @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/5867
*/
return fn (): mixed => (new $handler())(...func_get_args());
return fn (): mixed => (new $handler)(...func_get_args());
}

throw new InvalidArgumentException(sprintf('Invalid handler: %s.', $handler));
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Traits/InteractWithServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setRequest(ServerRequestInterface $request): static

public function setRequestFromSymfonyRequest(Request $symfonyRequest): static
{
$psr17Factory = new Psr17Factory();
$psr17Factory = new Psr17Factory;
$psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$this->request = $psrHttpFactory->createRequest($symfonyRequest);
Expand Down
4 changes: 2 additions & 2 deletions src/MiniApp/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function createClient(): AccessTokenAwareClient
{
$httpClient = $this->getHttpClient();

if ((bool) $this->config->get('http.retry', false)) {
if ($this->config->get('http.retry', false)) {
$httpClient = new RetryableHttpClient(
$httpClient,
$this->getRetryStrategy(),
Expand All @@ -169,7 +169,7 @@ public function createClient(): AccessTokenAwareClient
accessToken: $this->getAccessToken(),
failureJudge: fn (
Response $response
) => (bool) ($response->toArray()['errcode'] ?? 0) || ! is_null($response->toArray()['error'] ?? null),
) => ($response->toArray()['errcode'] ?? 0) || ! is_null($response->toArray()['error'] ?? null),
throw: (bool) $this->config->get('http.throw', true),
))->setPresets($this->config->all());
}
Expand Down
4 changes: 1 addition & 3 deletions src/MiniApp/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace EasyWeChat\MiniApp;

class Server extends \EasyWeChat\OfficialAccount\Server
{
}
class Server extends \EasyWeChat\OfficialAccount\Server {}
4 changes: 1 addition & 3 deletions src/MiniApp/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

class Utils
{
public function __construct(protected Application $app)
{
}
public function __construct(protected Application $app) {}

/**
* @throws HttpException
Expand Down
2 changes: 1 addition & 1 deletion src/OfficialAccount/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getToken(): string
{
$token = $this->cache->get($this->getKey());

if ((bool) $token && is_string($token)) {
if ($token && is_string($token)) {
return $token;
}

Expand Down
3 changes: 1 addition & 2 deletions src/OfficialAccount/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function __construct(
protected ?string $secret,
protected ?string $token = null,
protected ?string $aesKey = null
) {
}
) {}

public function getAppId(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/OfficialAccount/JsApiTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getTicket(): string
$key = $this->getKey();
$ticket = $this->cache->get($key);

if ((bool) $ticket && \is_string($ticket)) {
if ($ticket && \is_string($ticket)) {
return $ticket;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OfficialAccount/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
*/
public function serve(): ResponseInterface
{
if ((bool) ($str = $this->request->getQueryParams()['echostr'] ?? '')) {
if ($str = $this->request->getQueryParams()['echostr'] ?? '') {
return new Response(200, [], $str);
}

Expand Down
4 changes: 1 addition & 3 deletions src/OfficialAccount/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

class Utils
{
public function __construct(protected Application $app)
{
}
public function __construct(protected Application $app) {}

/**
* @param array<string> $jsApiList
Expand Down
3 changes: 1 addition & 2 deletions src/OpenPlatform/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public function __construct(
protected string $secret,
protected string $token,
protected string $aesKey
) {
}
) {}

public function getAppId(): string
{
Expand Down
4 changes: 1 addition & 3 deletions src/OpenPlatform/AuthorizerAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

class AuthorizerAccessToken implements AccessToken, Stringable
{
public function __construct(protected string $appId, protected string $accessToken)
{
}
public function __construct(protected string $appId, protected string $accessToken) {}

public function getAppId(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenPlatform/ComponentAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getToken(): string
{
$token = $this->cache->get($this->getKey());

if ((bool) $token && \is_string($token)) {
if ($token && \is_string($token)) {
return $token;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OpenPlatform/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
*/
public function serve(): ResponseInterface
{
if ((bool) ($str = $this->request->getQueryParams()['echostr'] ?? '')) {
if ($str = $this->request->getQueryParams()['echostr'] ?? '') {
return new Response(200, [], $str);
}

Expand Down
Loading

0 comments on commit 10571f5

Please sign in to comment.