diff --git a/composer.json b/composer.json index c3d596e87..770184deb 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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", diff --git a/src/Kernel/Contracts/Aes.php b/src/Kernel/Contracts/Aes.php index e72969f37..02c3e6076 100644 --- a/src/Kernel/Contracts/Aes.php +++ b/src/Kernel/Contracts/Aes.php @@ -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; } diff --git a/src/Kernel/Encryptor.php b/src/Kernel/Encryptor.php index 8e9d3c9b7..cbdf54cda 100644 --- a/src/Kernel/Encryptor.php +++ b/src/Kernel/Encryptor.php @@ -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; @@ -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); diff --git a/src/Kernel/Exceptions/HttpException.php b/src/Kernel/Exceptions/HttpException.php index 6dbae96a5..db27bd276 100644 --- a/src/Kernel/Exceptions/HttpException.php +++ b/src/Kernel/Exceptions/HttpException.php @@ -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); diff --git a/src/Kernel/Form/File.php b/src/Kernel/Form/File.php index 6f1db1152..120833bcf 100644 --- a/src/Kernel/Form/File.php +++ b/src/Kernel/Form/File.php @@ -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); @@ -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(); @@ -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()); } diff --git a/src/Kernel/HttpClient/AccessTokenAwareClient.php b/src/Kernel/HttpClient/AccessTokenAwareClient.php index 2cbcc6b88..cd639e2bf 100644 --- a/src/Kernel/HttpClient/AccessTokenAwareClient.php +++ b/src/Kernel/HttpClient/AccessTokenAwareClient.php @@ -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 diff --git a/src/Kernel/HttpClient/RequestWithPresets.php b/src/Kernel/HttpClient/RequestWithPresets.php index 79ac016ef..70a1de332 100644 --- a/src/Kernel/HttpClient/RequestWithPresets.php +++ b/src/Kernel/HttpClient/RequestWithPresets.php @@ -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, @@ -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); } diff --git a/src/Kernel/HttpClient/Response.php b/src/Kernel/HttpClient/Response.php index bb9cf9b3c..60d0eccbd 100644 --- a/src/Kernel/HttpClient/Response.php +++ b/src/Kernel/HttpClient/Response.php @@ -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; @@ -143,7 +143,7 @@ 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); } @@ -151,7 +151,7 @@ public function toJson(bool $throw = null): string|false /** * {@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); @@ -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; @@ -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); } @@ -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); } @@ -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]); } @@ -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; @@ -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; diff --git a/src/Kernel/HttpClient/RetryableClient.php b/src/Kernel/HttpClient/RetryableClient.php index 44b4e6c18..c43daa0ca 100644 --- a/src/Kernel/HttpClient/RetryableClient.php +++ b/src/Kernel/HttpClient/RetryableClient.php @@ -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); diff --git a/src/Kernel/HttpClient/ScopingHttpClient.php b/src/Kernel/HttpClient/ScopingHttpClient.php index 74c3ed54e..fad671052 100644 --- a/src/Kernel/HttpClient/ScopingHttpClient.php +++ b/src/Kernel/HttpClient/ScopingHttpClient.php @@ -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); } diff --git a/src/Kernel/Support/AesCbc.php b/src/Kernel/Support/AesCbc.php index 3b4e66447..b349b9c70 100644 --- a/src/Kernel/Support/AesCbc.php +++ b/src/Kernel/Support/AesCbc.php @@ -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); @@ -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), diff --git a/src/Kernel/Support/AesEcb.php b/src/Kernel/Support/AesEcb.php index b95ed85a9..f910f19d5 100644 --- a/src/Kernel/Support/AesEcb.php +++ b/src/Kernel/Support/AesEcb.php @@ -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); @@ -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) ?: '', diff --git a/src/Kernel/Support/AesGcm.php b/src/Kernel/Support/AesGcm.php index d7f90428c..5745b7b39 100644 --- a/src/Kernel/Support/AesGcm.php +++ b/src/Kernel/Support/AesGcm.php @@ -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, @@ -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); diff --git a/src/Kernel/Traits/RespondXmlMessage.php b/src/Kernel/Traits/RespondXmlMessage.php index 95307c866..99555e512 100644 --- a/src/Kernel/Traits/RespondXmlMessage.php +++ b/src/Kernel/Traits/RespondXmlMessage.php @@ -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'); @@ -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); diff --git a/src/OfficialAccount/AccessToken.php b/src/OfficialAccount/AccessToken.php index 7a9140bc5..1e8594409 100644 --- a/src/OfficialAccount/AccessToken.php +++ b/src/OfficialAccount/AccessToken.php @@ -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/']); diff --git a/src/OfficialAccount/Server.php b/src/OfficialAccount/Server.php index f6fcf6495..948c390c7 100644 --- a/src/OfficialAccount/Server.php +++ b/src/OfficialAccount/Server.php @@ -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(); @@ -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); } @@ -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); diff --git a/src/OpenPlatform/ComponentAccessToken.php b/src/OpenPlatform/ComponentAccessToken.php index eaa0cefbb..390efb05c 100644 --- a/src/OpenPlatform/ComponentAccessToken.php +++ b/src/OpenPlatform/ComponentAccessToken.php @@ -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)); diff --git a/src/OpenPlatform/Server.php b/src/OpenPlatform/Server.php index 45dba65b6..bc0616f5b 100644 --- a/src/OpenPlatform/Server.php +++ b/src/OpenPlatform/Server.php @@ -36,7 +36,7 @@ class Server implements ServerInterface */ public function __construct( protected Encryptor $encryptor, - ServerRequestInterface $request = null, + ?ServerRequestInterface $request = null, ) { $this->request = $request ?? RequestUtil::createDefaultServerRequest(); } @@ -146,7 +146,7 @@ protected function decryptRequestMessage(): 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); } @@ -155,7 +155,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); diff --git a/src/OpenPlatform/VerifyTicket.php b/src/OpenPlatform/VerifyTicket.php index 5692d7416..e97acf7be 100644 --- a/src/OpenPlatform/VerifyTicket.php +++ b/src/OpenPlatform/VerifyTicket.php @@ -21,7 +21,7 @@ class VerifyTicket implements VerifyTicketInterface public function __construct( protected string $appId, protected ?string $key = null, - CacheInterface $cache = null, + ?CacheInterface $cache = null, ) { $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); } diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php index 9ccbe694e..7a713b01b 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -220,7 +220,7 @@ public function setSuiteTicket(SuiteTicketInterface $suiteTicket): SuiteTicketIn public function getAuthorization( string $corpId, string $permanentCode, - AccessTokenInterface $suiteAccessToken = null + ?AccessTokenInterface $suiteAccessToken = null ): Authorization { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); @@ -252,7 +252,7 @@ public function getAuthorization( public function getAuthorizerAccessToken( string $corpId, string $permanentCode, - AccessTokenInterface $suiteAccessToken = null + ?AccessTokenInterface $suiteAccessToken = null ): AuthorizerAccessToken { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); @@ -283,7 +283,7 @@ public function createClient(): AccessTokenAwareClient * @throws DecodingExceptionInterface * @throws ClientExceptionInterface */ - public function getAuthorizerClient(string $corpId, string $permanentCode, AccessTokenInterface $suiteAccessToken = null): AccessTokenAwareClient + public function getAuthorizerClient(string $corpId, string $permanentCode, ?AccessTokenInterface $suiteAccessToken = null): AccessTokenAwareClient { return (new AccessTokenAwareClient( client: $this->getHttpClient(), @@ -301,7 +301,7 @@ public function getAuthorizerClient(string $corpId, string $permanentCode, Acces * @throws DecodingExceptionInterface * @throws ClientExceptionInterface */ - public function getJsApiTicket(string $corpId, string $permanentCode, AccessTokenInterface $suiteAccessToken = null): JsApiTicket + public function getJsApiTicket(string $corpId, string $permanentCode, ?AccessTokenInterface $suiteAccessToken = null): JsApiTicket { return new JsApiTicket( corpId: $corpId, @@ -312,7 +312,7 @@ public function getJsApiTicket(string $corpId, string $permanentCode, AccessToke public function getOAuth( string $suiteId, - AccessTokenInterface $suiteAccessToken = null + ?AccessTokenInterface $suiteAccessToken = null ): SocialiteProviderInterface { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); @@ -327,7 +327,7 @@ public function getOAuth( public function getCorpOAuth( string $corpId, - AccessTokenInterface $suiteAccessToken = null + ?AccessTokenInterface $suiteAccessToken = null ): SocialiteProviderInterface { $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken(); diff --git a/src/OpenWork/AuthorizerAccessToken.php b/src/OpenWork/AuthorizerAccessToken.php index 229c9e56c..7818600a8 100644 --- a/src/OpenWork/AuthorizerAccessToken.php +++ b/src/OpenWork/AuthorizerAccessToken.php @@ -32,8 +32,8 @@ public function __construct( protected string $permanentCodeOrAccessToken, protected ?AccessTokenInterface $suiteAccessToken = null, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null, + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null, ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/OpenWork/JsApiTicket.php b/src/OpenWork/JsApiTicket.php index 50ae2d381..492a12c62 100644 --- a/src/OpenWork/JsApiTicket.php +++ b/src/OpenWork/JsApiTicket.php @@ -30,8 +30,8 @@ class JsApiTicket public function __construct( protected string $corpId, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/OpenWork/ProviderAccessToken.php b/src/OpenWork/ProviderAccessToken.php index 06de80d0b..f8b447777 100644 --- a/src/OpenWork/ProviderAccessToken.php +++ b/src/OpenWork/ProviderAccessToken.php @@ -27,8 +27,8 @@ public function __construct( protected string $corpId, protected string $providerSecret, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null, + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null, ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/OpenWork/Server.php b/src/OpenWork/Server.php index 3a8f7f9b3..db0ede39f 100644 --- a/src/OpenWork/Server.php +++ b/src/OpenWork/Server.php @@ -37,7 +37,7 @@ class Server implements ServerInterface public function __construct( protected Encryptor $encryptor, protected Encryptor $providerEncryptor, - ServerRequestInterface $request = null, + ?ServerRequestInterface $request = null, ) { $this->request = $request ?? RequestUtil::createDefaultServerRequest(); } @@ -261,7 +261,7 @@ protected function decryptRequestMessage(): 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); } @@ -270,7 +270,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); diff --git a/src/OpenWork/SuiteAccessToken.php b/src/OpenWork/SuiteAccessToken.php index 1735b94b2..4065ae863 100644 --- a/src/OpenWork/SuiteAccessToken.php +++ b/src/OpenWork/SuiteAccessToken.php @@ -31,8 +31,8 @@ public function __construct( protected string $suiteSecret, protected ?SuiteTicketInterface $suiteTicket = null, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null, + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null, ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/OpenWork/SuiteTicket.php b/src/OpenWork/SuiteTicket.php index 7cdaff346..467b5b508 100644 --- a/src/OpenWork/SuiteTicket.php +++ b/src/OpenWork/SuiteTicket.php @@ -20,7 +20,7 @@ class SuiteTicket implements SuiteTicketInterface public function __construct( protected string $suiteId, - CacheInterface $cache = null, + ?CacheInterface $cache = null, protected ?string $key = null, ) { $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/Pay/Client.php b/src/Pay/Client.php index 13352faee..914658d88 100644 --- a/src/Pay/Client.php +++ b/src/Pay/Client.php @@ -78,7 +78,7 @@ class Client implements HttpClientInterface */ public function __construct( protected Merchant $merchant, - HttpClientInterface $client = null, + ?HttpClientInterface $client = null, array $defaultOptions = [] ) { $this->throw = (bool) ($defaultOptions['throw'] ?? true); @@ -182,7 +182,7 @@ public function __call(string $name, array $arguments): mixed * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException */ - public function uploadMedia(string $uri, string $pathOrContents, array $meta = null, string $filename = null): ResponseInterface + public function uploadMedia(string $uri, string $pathOrContents, ?array $meta = null, ?string $filename = null): ResponseInterface { $isFile = is_file($pathOrContents); diff --git a/src/Pay/Server.php b/src/Pay/Server.php index 5e02d8b70..4aacbe63f 100644 --- a/src/Pay/Server.php +++ b/src/Pay/Server.php @@ -111,7 +111,7 @@ public function handleRefunded(callable $handler): static * @throws InvalidArgumentException * @throws RuntimeException */ - public function getRequestMessage(ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message|Message + public function getRequestMessage(?ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message|Message { $originContent = (string) ($request ?? $this->request)->getBody(); @@ -189,7 +189,7 @@ protected function decodeJsonMessage(string $contents): array * @throws InvalidArgumentException * @throws RuntimeException */ - public function getDecryptedMessage(ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message|Message + public function getDecryptedMessage(?ServerRequestInterface $request = null): \EasyWeChat\Kernel\Message|Message { return $this->getRequestMessage($request); } diff --git a/src/Work/AccessToken.php b/src/Work/AccessToken.php index 760885e97..26597be49 100644 --- a/src/Work/AccessToken.php +++ b/src/Work/AccessToken.php @@ -36,8 +36,8 @@ public function __construct( protected string $corpId, protected string $secret, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/Work/JsApiTicket.php b/src/Work/JsApiTicket.php index f68bb4cd4..313cba7e0 100644 --- a/src/Work/JsApiTicket.php +++ b/src/Work/JsApiTicket.php @@ -31,8 +31,8 @@ class JsApiTicket public function __construct( protected string $corpId, protected ?string $key = null, - CacheInterface $cache = null, - HttpClientInterface $httpClient = null + ?CacheInterface $cache = null, + ?HttpClientInterface $httpClient = null ) { $this->httpClient = $httpClient ?? HttpClient::create(['base_uri' => 'https://qyapi.weixin.qq.com/']); $this->cache = $cache ?? new Psr16Cache(new FilesystemAdapter(namespace: 'easywechat', defaultLifetime: 1500)); diff --git a/src/Work/Server.php b/src/Work/Server.php index 1394dc588..ee9f29efc 100644 --- a/src/Work/Server.php +++ b/src/Work/Server.php @@ -33,7 +33,7 @@ class Server implements ServerInterface */ public function __construct( protected Encryptor $encryptor, - ServerRequestInterface $request = null, + ?ServerRequestInterface $request = null, ) { $this->request = $request ?? RequestUtil::createDefaultServerRequest(); } @@ -261,7 +261,7 @@ protected function decryptRequestMessage(): 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); } @@ -270,7 +270,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);