Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed May 14, 2024
1 parent 9d68941 commit 621a3b7
Show file tree
Hide file tree
Showing 31 changed files with 77 additions and 106 deletions.
29 changes: 0 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"thenorthmemory/xml": "^1.0"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.8",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.4.4",
"phpstan/phpstan": "^1.0",
Expand All @@ -56,36 +55,8 @@
"EasyWeChat\\Tests\\": "tests/"
}
},
"extra": {
"hooks": {
"pre-commit": [
"composer check-style",
"composer phpstan",
"composer test"
],
"pre-push": [
"composer check-style"
],
"config": {
"stop-on-failure": [
"pre-commit",
"pre-push"
]
}
}
},
"scripts": {
"post-update-cmd": [
"cghooks remove",
"cghooks add --ignore-lock",
"cghooks update"
],
"post-merge": "composer install",
"post-install-cmd": [
"cghooks remove",
"cghooks add --ignore-lock",
"cghooks update"
],
"phpstan": "phpstan analyse --memory-limit=-1",
"check-style": "vendor/bin/pint --test",
"fix-style": "vendor/bin/pint",
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Contracts/Aes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface Aes
{
public static function encrypt(string $plaintext, string $key, string $iv = null): string;
public static function encrypt(string $plaintext, string $key, ?string $iv = null): string;

public static function decrypt(string $ciphertext, string $key, string $iv = null): string;
public static function decrypt(string $ciphertext, string $key, ?string $iv = null): string;
}
4 changes: 2 additions & 2 deletions src/Kernel/Encryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Encryptor

protected ?string $receiveId = null;

public function __construct(string $appId, string $token, string $aesKey, string $receiveId = null)
public function __construct(string $appId, string $token, string $aesKey, ?string $receiveId = null)
{
$this->appId = $appId;
$this->token = $token;
Expand All @@ -82,7 +82,7 @@ public function getToken(): string
* @throws RuntimeException
* @throws Exception
*/
public function encrypt(string $plaintext, string $nonce = null, int|string $timestamp = null): string
public function encrypt(string $plaintext, ?string $nonce = null, int|string|null $timestamp = null): string
{
try {
$plaintext = Pkcs7::padding(random_bytes(16).pack('N', strlen($plaintext)).$plaintext.$this->appId, 32);
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HttpException extends Exception
/**
* HttpException constructor.
*/
public function __construct(string $message, ResponseInterface $response = null, int $code = 0)
public function __construct(string $message, ?ResponseInterface $response = null, int $code = 0)
{
parent::__construct($message, $code);

Expand Down
18 changes: 9 additions & 9 deletions src/Kernel/Form/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class File extends DataPart
*/
public static function from(
string $pathOrContents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
if (file_exists($pathOrContents)) {
return static::fromPath($pathOrContents, $filename, $contentType);
Expand All @@ -38,9 +38,9 @@ public static function from(
*/
public static function fromContents(
string $contents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
if ($contentType === null) {
$mimeTypes = new MimeTypes();
Expand Down Expand Up @@ -70,9 +70,9 @@ public static function fromContents(
*/
public static function withContents(
string $contents,
string $filename = null,
string $contentType = null,
string $encoding = null
?string $filename = null,
?string $contentType = null,
?string $encoding = null
): DataPart {
return self::fromContents(...func_get_args());

Check failure on line 77 in src/Kernel/Form/File.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $contents of static method EasyWeChat\Kernel\Form\File::fromContents() expects string, mixed given.
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/HttpClient/AccessTokenAwareClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AccessTokenAwareClient implements AccessTokenAwareHttpClientInterface
use RetryableClient;

public function __construct(
HttpClientInterface $client = null,
?HttpClientInterface $client = null,
protected ?AccessTokenInterface $accessToken = null,
protected ?Closure $failureJudge = null,
protected bool $throw = true
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/HttpClient/RequestWithPresets.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ 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
public function withFile(string $pathOrContents, string $formName = 'file', ?string $filename = null): static
{
$file = is_file($pathOrContents) ? File::fromPath(
$pathOrContents,
Expand All @@ -111,7 +111,7 @@ public function withFile(string $pathOrContents, string $formName = 'file', stri
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function withFileContents(string $contents, string $formName = 'file', string $filename = null): static
public function withFileContents(string $contents, string $formName = 'file', ?string $filename = null): static
{
return $this->withFile($contents, $formName, $filename);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Kernel/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function isFailed(): bool
* @throws ClientExceptionInterface
* @throws BadResponseException
*/
public function toArray(bool $throw = null): array
public function toArray(?bool $throw = null): array
{
$throw ??= $this->throw;

Expand Down Expand Up @@ -143,15 +143,15 @@ public function toArray(bool $throw = null): array
* @throws ClientExceptionInterface
* @throws BadResponseException
*/
public function toJson(bool $throw = null): string|false
public function toJson(?bool $throw = null): string|false
{
return json_encode($this->toArray($throw), JSON_UNESCAPED_UNICODE);
}

/**
* {@inheritdoc}
*/
public function toStream(bool $throw = null)
public function toStream(?bool $throw = null)
{
if ($this->response instanceof StreamableInterface) {
return $this->response->toStream($throw ?? $this->throw);
Expand All @@ -175,7 +175,7 @@ public function toDataUrl(): string
return 'data:'.$this->getHeaderLine('content-type').';base64,'.base64_encode($this->getContent());
}

public function toPsrResponse(ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null): \Psr\Http\Message\ResponseInterface
public function toPsrResponse(?ResponseFactoryInterface $responseFactory = null, ?StreamFactoryInterface $streamFactory = null): \Psr\Http\Message\ResponseInterface
{
$streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;

Expand Down Expand Up @@ -290,12 +290,12 @@ public function getStatusCode(): int
return $this->response->getStatusCode();
}

public function getHeaders(bool $throw = null): array
public function getHeaders(?bool $throw = null): array
{
return $this->response->getHeaders($throw ?? $this->throw);
}

public function getContent(bool $throw = null): string
public function getContent(?bool $throw = null): string
{
return $this->response->getContent($throw ?? $this->throw);
}
Expand All @@ -305,7 +305,7 @@ public function cancel(): void
$this->response->cancel();
}

public function getInfo(string $type = null): mixed
public function getInfo(?string $type = null): mixed
{
return $this->response->getInfo($type);
}
Expand All @@ -329,7 +329,7 @@ public function __toString(): string
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function hasHeader(string $name, bool $throw = null): bool
public function hasHeader(string $name, ?bool $throw = null): bool
{
return isset($this->getHeaders($throw)[$name]);
}
Expand All @@ -342,7 +342,7 @@ public function hasHeader(string $name, bool $throw = null): bool
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function getHeader(string $name, bool $throw = null): array
public function getHeader(string $name, ?bool $throw = null): array
{
$name = strtolower($name);
$throw ??= $this->throw;
Expand All @@ -356,7 +356,7 @@ public function getHeader(string $name, bool $throw = null): array
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
public function getHeaderLine(string $name, bool $throw = null): string
public function getHeaderLine(string $name, ?bool $throw = null): string
{
$name = strtolower($name);
$throw ??= $this->throw;
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/HttpClient/RetryableClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function retry(array $config = []): static
public function retryUsing(
RetryStrategyInterface $strategy,
int $maxRetries = 3,
LoggerInterface $logger = null
?LoggerInterface $logger = null
): static {
$this->client = new RetryableHttpClient($this->client, $strategy, $maxRetries, $logger);

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/HttpClient/ScopingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function request(string $method, string $url, array $options = []): Respo
return $this->client->request($method, $url, $options);
}

public function stream(ResponseInterface|iterable $responses, float $timeout = null): ResponseStreamInterface
public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
{
return $this->client->stream($responses, $timeout);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Support/AesCbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AesCbc implements Aes
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function encrypt(string $plaintext, string $key, string $iv = null): string
public static function encrypt(string $plaintext, string $key, ?string $iv = null): string
{
$ciphertext = \openssl_encrypt($plaintext, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, (string) $iv);

Expand All @@ -30,7 +30,7 @@ public static function encrypt(string $plaintext, string $key, string $iv = null
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function decrypt(string $ciphertext, string $key, string $iv = null): string
public static function decrypt(string $ciphertext, string $key, ?string $iv = null): string
{
$plaintext = openssl_decrypt(
base64_decode($ciphertext),
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Support/AesEcb.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AesEcb implements Aes
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function encrypt(string $plaintext, string $key, string $iv = null): string
public static function encrypt(string $plaintext, string $key, ?string $iv = null): string
{
$ciphertext = \openssl_encrypt($plaintext, 'aes-256-ecb', $key, OPENSSL_RAW_DATA, (string) $iv);

Expand All @@ -30,7 +30,7 @@ public static function encrypt(string $plaintext, string $key, string $iv = null
/**
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public static function decrypt(string $ciphertext, string $key, string $iv = null): string
public static function decrypt(string $ciphertext, string $key, ?string $iv = null): string
{
$plaintext = openssl_decrypt(
base64_decode($ciphertext, true) ?: '',
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Support/AesGcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AesGcm implements Aes
/**
* @throws InvalidArgumentException
*/
public static function encrypt(string $plaintext, string $key, string $iv = null, string $aad = ''): string
public static function encrypt(string $plaintext, string $key, ?string $iv = null, string $aad = ''): string
{
$ciphertext = openssl_encrypt(
$plaintext,
Expand All @@ -43,7 +43,7 @@ public static function encrypt(string $plaintext, string $key, string $iv = null
/**
* @throws InvalidArgumentException
*/
public static function decrypt(string $ciphertext, string $key, string $iv = null, string $aad = ''): string
public static function decrypt(string $ciphertext, string $key, ?string $iv = null, string $aad = ''): string
{
$ciphertext = base64_decode($ciphertext);

Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Traits/RespondXmlMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait RespondXmlMessage
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function transformToReply(mixed $response, Message $message, Encryptor $encryptor = null): ResponseInterface
public function transformToReply(mixed $response, Message $message, ?Encryptor $encryptor = null): ResponseInterface
{
if (empty($response)) {
return new Response(200, [], 'success');
Expand Down Expand Up @@ -79,7 +79,7 @@ protected function normalizeResponse(mixed $response): array
*
* @throws RuntimeException
*/
protected function createXmlResponse(array $attributes, Encryptor $encryptor = null): ResponseInterface
protected function createXmlResponse(array $attributes, ?Encryptor $encryptor = null): ResponseInterface
{
$xml = Xml::build($attributes);

Expand Down
4 changes: 2 additions & 2 deletions src/OfficialAccount/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function __construct(
protected string $appId,
protected string $secret,
protected ?string $key = null,
CacheInterface $cache = null,
HttpClientInterface $httpClient = null,
?CacheInterface $cache = null,
?HttpClientInterface $httpClient = null,
protected ?bool $stable = false
) {
$this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://api.weixin.qq.com/']);
Expand Down
6 changes: 3 additions & 3 deletions src/OfficialAccount/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Server implements ServerInterface
* @throws Throwable
*/
public function __construct(
ServerRequestInterface $request = null,
?ServerRequestInterface $request = null,
protected ?Encryptor $encryptor = null,
) {
$this->request = $request ?? RequestUtil::createDefaultServerRequest();
Expand Down Expand Up @@ -122,7 +122,7 @@ protected function decryptRequestMessage(array $query): Closure
/**
* @throws BadRequestException
*/
public function getRequestMessage(ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message
public function getRequestMessage(?ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message
{
return Message::createFromRequest($request ?? $this->request);
}
Expand All @@ -131,7 +131,7 @@ public function getRequestMessage(ServerRequestInterface $request = null): \Easy
* @throws BadRequestException
* @throws RuntimeException
*/
public function getDecryptedMessage(ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message
public function getDecryptedMessage(?ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message
{
$request = $request ?? $this->request;
$message = $this->getRequestMessage($request);
Expand Down
4 changes: 2 additions & 2 deletions src/OpenPlatform/ComponentAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct(
protected string $secret,
protected VerifyTicketInterface $verifyTicket,
protected ?string $key = null,
CacheInterface $cache = null,
HttpClientInterface $httpClient = null,
?CacheInterface $cache = null,
?HttpClientInterface $httpClient = null,
) {
$this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://api.weixin.qq.com/']);
$this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500));
Expand Down
Loading

0 comments on commit 621a3b7

Please sign in to comment.