diff --git a/composer.json b/composer.json index 56b42439b..c3d596e87 100644 --- a/composer.json +++ b/composer.json @@ -28,11 +28,11 @@ "overtrue/socialite": "^3.5.4|^4.0.1", "psr/simple-cache": "^1.0|^2.0|^3.0", "psr/http-client": "^1.0", - "symfony/cache": "^5.4|^6.0", - "symfony/http-foundation": "^5.4|^6.0", + "symfony/cache": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", "symfony/psr-http-message-bridge": "^2.1.2|^6.4.0", - "symfony/http-client": "^5.4|^6.0", - "symfony/mime": "^5.4|^6.0", + "symfony/http-client": "^5.4|^6.0|^7.0", + "symfony/mime": "^5.4|^6.0|^7.0", "symfony/polyfill-php81": "^1.25", "thenorthmemory/xml": "^1.0" }, @@ -93,7 +93,8 @@ }, "config": { "allow-plugins": { - "composer/package-versions-deprecated": true + "composer/package-versions-deprecated": true, + "php-http/discovery": true } } } diff --git a/src/Kernel/Config.php b/src/Kernel/Config.php index 36d087a9c..26baa590a 100644 --- a/src/Kernel/Config.php +++ b/src/Kernel/Config.php @@ -54,7 +54,7 @@ public function get(array|string $key, mixed $default = null): mixed /** * @param array $keys - * @return array + * @return array */ #[Pure] public function getMany(array $keys): array @@ -78,7 +78,7 @@ public function set(string $key, mixed $value = null): void } /** - * @return array + * @return array */ public function all(): array { 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 ae29f9d19..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,11 +38,11 @@ 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 (null === $contentType) { + if ($contentType === null) { $mimeTypes = new MimeTypes(); if ($filename) { @@ -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/Form/Form.php b/src/Kernel/Form/Form.php index 32cdca3c4..1a3bc582f 100644 --- a/src/Kernel/Form/Form.php +++ b/src/Kernel/Form/Form.php @@ -24,7 +24,7 @@ public static function create(array $fields): Form } /** - * @return array + * @return array */ #[ArrayShape(['headers' => 'array', 'body' => 'string'])] public function toArray(): array diff --git a/src/Kernel/HttpClient/AccessTokenAwareClient.php b/src/Kernel/HttpClient/AccessTokenAwareClient.php index 80c3e829e..cd639e2bf 100644 --- a/src/Kernel/HttpClient/AccessTokenAwareClient.php +++ b/src/Kernel/HttpClient/AccessTokenAwareClient.php @@ -27,12 +27,12 @@ class AccessTokenAwareClient implements AccessTokenAwareHttpClientInterface { use AsyncDecoratorTrait; use HttpClientMethods; - use RetryableClient; use MockableHttpClient; use RequestWithPresets; + 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 b84268358..60d0eccbd 100644 --- a/src/Kernel/HttpClient/Response.php +++ b/src/Kernel/HttpClient/Response.php @@ -41,7 +41,7 @@ * * @see \Symfony\Contracts\HttpClient\ResponseInterface */ -class Response implements Jsonable, Arrayable, ArrayAccess, ResponseInterface, StreamableInterface +class Response implements Arrayable, ArrayAccess, Jsonable, ResponseInterface, StreamableInterface { public function __construct( protected ResponseInterface $response, @@ -98,7 +98,7 @@ public function isFailed(): bool } try { - return 400 <= $this->getStatusCode(); + return $this->getStatusCode() >= 400; } catch (Throwable $e) { return true; } @@ -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,11 +175,11 @@ 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; - if (null === $responseFactory || null === $streamFactory) { + if ($responseFactory === null || $streamFactory === null) { if (! class_exists(Psr17Factory::class) && ! class_exists(Psr17FactoryDiscovery::class)) { throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".'); } @@ -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 ca432d3e9..fad671052 100644 --- a/src/Kernel/HttpClient/ScopingHttpClient.php +++ b/src/Kernel/HttpClient/ScopingHttpClient.php @@ -12,11 +12,12 @@ use Symfony\Contracts\HttpClient\ResponseStreamInterface; use Symfony\Contracts\Service\ResetInterface; -class ScopingHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface +class ScopingHttpClient implements HttpClientInterface, LoggerAwareInterface, ResetInterface { use HttpClientTrait; private HttpClientInterface $client; + private array $defaultOptionsByRegexp; public function __construct(HttpClientInterface $client, array $defaultOptionsByRegexp) @@ -37,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/Message.php b/src/Kernel/Message.php index ac4a43e02..960ff91cd 100644 --- a/src/Kernel/Message.php +++ b/src/Kernel/Message.php @@ -18,7 +18,7 @@ * * @implements ArrayAccess */ -abstract class Message implements ArrayAccess, Jsonable, \JsonSerializable +abstract class Message implements \JsonSerializable, ArrayAccess, Jsonable { use HasAttributes; @@ -47,14 +47,14 @@ public static function createFromRequest(ServerRequestInterface $request): Messa */ public static function format(string $originContent): array { - if (0 === stripos($originContent, '<')) { + if (stripos($originContent, '<') === 0) { $attributes = Xml::parse($originContent); } // Handle JSON format. $dataSet = json_decode($originContent, true); - if (JSON_ERROR_NONE === json_last_error() && $originContent) { + if (json_last_error() === JSON_ERROR_NONE && $originContent) { $attributes = $dataSet; } diff --git a/src/Kernel/ServerResponse.php b/src/Kernel/ServerResponse.php index c51b8c189..571123de9 100644 --- a/src/Kernel/ServerResponse.php +++ b/src/Kernel/ServerResponse.php @@ -134,7 +134,7 @@ public function sendHeaders(): static } foreach ($this->getHeaders() as $name => $values) { - $replace = 0 === \strcasecmp($name, 'Content-Type'); + $replace = \strcasecmp($name, 'Content-Type') === 0; foreach ($values as $value) { header($name.': '.$value, $replace, $this->getStatusCode()); diff --git a/src/Kernel/Support/AesCbc.php b/src/Kernel/Support/AesCbc.php index 4e3714ab1..b349b9c70 100644 --- a/src/Kernel/Support/AesCbc.php +++ b/src/Kernel/Support/AesCbc.php @@ -16,11 +16,11 @@ 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); - if (false === $ciphertext) { + if ($ciphertext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Encrypt AES CBC error.'); } @@ -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), @@ -40,7 +40,7 @@ public static function decrypt(string $ciphertext, string $key, string $iv = nul (string) $iv ); - if (false === $plaintext) { + if ($plaintext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Decrypt AES CBC error.'); } diff --git a/src/Kernel/Support/AesEcb.php b/src/Kernel/Support/AesEcb.php index 863008615..f910f19d5 100644 --- a/src/Kernel/Support/AesEcb.php +++ b/src/Kernel/Support/AesEcb.php @@ -16,11 +16,11 @@ 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); - if (false === $ciphertext) { + if ($ciphertext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Encrypt AES ECB failed.'); } @@ -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) ?: '', @@ -40,7 +40,7 @@ public static function decrypt(string $ciphertext, string $key, string $iv = nul (string) $iv ); - if (false === $plaintext) { + if ($plaintext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Decrypt AES ECB failed.'); } diff --git a/src/Kernel/Support/AesGcm.php b/src/Kernel/Support/AesGcm.php index c40256342..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, @@ -33,7 +33,7 @@ public static function encrypt(string $plaintext, string $key, string $iv = null self::BLOCK_SIZE ); - if (false === $ciphertext) { + if ($ciphertext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Encrypt failed'); } @@ -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); @@ -53,7 +53,7 @@ public static function decrypt(string $ciphertext, string $key, string $iv = nul $plaintext = openssl_decrypt($ciphertext, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, (string) $iv, $tag, $aad); - if (false === $plaintext) { + if ($plaintext === false) { throw new InvalidArgumentException(openssl_error_string() ?: 'Decrypt failed'); } diff --git a/src/Kernel/Support/Arr.php b/src/Kernel/Support/Arr.php index 264025c6e..3775e9ab0 100644 --- a/src/Kernel/Support/Arr.php +++ b/src/Kernel/Support/Arr.php @@ -10,9 +10,6 @@ class Arr { - /** - * @param mixed $default - */ #[Pure] public static function get(mixed $array, string|int|null $key, mixed $default = null): mixed { @@ -113,7 +110,7 @@ public static function has(array $array, string|int|array|null $keys): bool return false; } - if ([] === $keys) { + if ($keys === []) { return false; } diff --git a/src/Kernel/Support/PublicKey.php b/src/Kernel/Support/PublicKey.php index 64e3ab244..6dbc23a06 100644 --- a/src/Kernel/Support/PublicKey.php +++ b/src/Kernel/Support/PublicKey.php @@ -26,7 +26,7 @@ public function getSerialNo(): string { $info = openssl_x509_parse($this->certificate); - if (false === $info || ! isset($info['serialNumberHex'])) { + if ($info === false || ! isset($info['serialNumberHex'])) { throw new InvalidConfigException('Read the $certificate failed, please check it whether or nor correct'); } diff --git a/src/Kernel/Traits/HasAttributes.php b/src/Kernel/Traits/HasAttributes.php index 18c3533ca..06092673e 100644 --- a/src/Kernel/Traits/HasAttributes.php +++ b/src/Kernel/Traits/HasAttributes.php @@ -11,7 +11,7 @@ trait HasAttributes { /** - * @var array + * @var array */ protected array $attributes = []; @@ -52,7 +52,7 @@ public function merge(array $attributes): static } /** - * @return array $attributes + * @return array $attributes */ public function jsonSerialize(): array { @@ -82,7 +82,7 @@ public function offsetGet(mixed $offset): mixed public function offsetSet(mixed $offset, mixed $value): void { - if (null === $offset) { + if ($offset === null) { $this->attributes[] = $value; } else { $this->attributes[$offset] = $value; diff --git a/src/Kernel/Traits/InteractWithHttpClient.php b/src/Kernel/Traits/InteractWithHttpClient.php index 78c2adab6..8e414dad5 100644 --- a/src/Kernel/Traits/InteractWithHttpClient.php +++ b/src/Kernel/Traits/InteractWithHttpClient.php @@ -5,10 +5,10 @@ namespace EasyWeChat\Kernel\Traits; use EasyWeChat\Kernel\HttpClient\RequestUtil; +use EasyWeChat\Kernel\HttpClient\ScopingHttpClient; use EasyWeChat\Kernel\Support\Arr; use Psr\Log\LoggerAwareInterface; use Symfony\Component\HttpClient\HttpClient; -use EasyWeChat\Kernel\HttpClient\ScopingHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; use function property_exists; 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/MiniApp/Application.php b/src/MiniApp/Application.php index 608bf23ec..9be5b6140 100644 --- a/src/MiniApp/Application.php +++ b/src/MiniApp/Application.php @@ -33,11 +33,11 @@ */ class Application implements ApplicationInterface { - use InteractWithConfig; use InteractWithCache; - use InteractWithServerRequest; - use InteractWithHttpClient; use InteractWithClient; + use InteractWithConfig; + use InteractWithHttpClient; + use InteractWithServerRequest; use LoggerAwareTrait; protected ?Encryptor $encryptor = null; diff --git a/src/OfficialAccount/AccessToken.php b/src/OfficialAccount/AccessToken.php index da32d4214..5fcf1772a 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/Account.php b/src/OfficialAccount/Account.php index b406bbb0b..9793fac77 100644 --- a/src/OfficialAccount/Account.php +++ b/src/OfficialAccount/Account.php @@ -24,7 +24,7 @@ public function getAppId(): string public function getSecret(): string { - if (null === $this->secret) { + if ($this->secret === null) { throw new RuntimeException('No secret configured.'); } diff --git a/src/OfficialAccount/Application.php b/src/OfficialAccount/Application.php index b0cbd2c92..2cfd765d1 100644 --- a/src/OfficialAccount/Application.php +++ b/src/OfficialAccount/Application.php @@ -37,11 +37,11 @@ class Application implements ApplicationInterface { - use InteractWithConfig; use InteractWithCache; - use InteractWithServerRequest; - use InteractWithHttpClient; use InteractWithClient; + use InteractWithConfig; + use InteractWithHttpClient; + use InteractWithServerRequest; use LoggerAwareTrait; protected ?Encryptor $encryptor = null; diff --git a/src/OfficialAccount/Server.php b/src/OfficialAccount/Server.php index 66102dd17..948c390c7 100644 --- a/src/OfficialAccount/Server.php +++ b/src/OfficialAccount/Server.php @@ -22,9 +22,9 @@ class Server implements ServerInterface { - use RespondXmlMessage; use DecryptXmlMessage; use InteractWithHandlers; + use RespondXmlMessage; protected ServerRequestInterface $request; @@ -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/Application.php b/src/OpenPlatform/Application.php index 4b862bd55..dfdcdec59 100644 --- a/src/OpenPlatform/Application.php +++ b/src/OpenPlatform/Application.php @@ -41,8 +41,8 @@ class Application implements ApplicationInterface { use InteractWithCache; - use InteractWithConfig; use InteractWithClient; + use InteractWithConfig; use InteractWithHttpClient; use InteractWithServerRequest; diff --git a/src/OpenPlatform/Authorization.php b/src/OpenPlatform/Authorization.php index 554705ede..f9dec4be9 100644 --- a/src/OpenPlatform/Authorization.php +++ b/src/OpenPlatform/Authorization.php @@ -13,7 +13,7 @@ /** * @implements ArrayAccess */ -class Authorization implements ArrayAccess, Jsonable, Arrayable +class Authorization implements Arrayable, ArrayAccess, Jsonable { use HasAttributes; 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 b7c7a2eae..bc0616f5b 100644 --- a/src/OpenPlatform/Server.php +++ b/src/OpenPlatform/Server.php @@ -23,9 +23,9 @@ class Server implements ServerInterface { + use DecryptXmlMessage; use InteractWithHandlers; use RespondXmlMessage; - use DecryptXmlMessage; protected ?Closure $defaultVerifyTicketHandler = null; @@ -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 79288478c..7a713b01b 100644 --- a/src/OpenWork/Application.php +++ b/src/OpenWork/Application.php @@ -30,10 +30,10 @@ class Application implements ApplicationInterface { use InteractWithCache; + use InteractWithClient; use InteractWithConfig; use InteractWithHttpClient; use InteractWithServerRequest; - use InteractWithClient; protected ?ServerInterface $server = null; @@ -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/Authorization.php b/src/OpenWork/Authorization.php index 2658363ea..4420e9a94 100644 --- a/src/OpenWork/Authorization.php +++ b/src/OpenWork/Authorization.php @@ -12,7 +12,7 @@ /** * @implements ArrayAccess */ -class Authorization implements ArrayAccess, Jsonable, Arrayable +class Authorization implements Arrayable, ArrayAccess, Jsonable { use HasAttributes; 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 57ff28994..db0ede39f 100644 --- a/src/OpenWork/Server.php +++ b/src/OpenWork/Server.php @@ -23,9 +23,9 @@ class Server implements ServerInterface { + use DecryptXmlMessage; use InteractWithHandlers; use RespondXmlMessage; - use DecryptXmlMessage; protected ServerRequestInterface $request; @@ -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 faa369238..914658d88 100644 --- a/src/Pay/Client.php +++ b/src/Pay/Client.php @@ -48,8 +48,8 @@ class Client implements HttpClientInterface use DecoratorTrait { DecoratorTrait::withOptions insteadof HttpClientTrait; } - use HttpClientTrait; use HttpClientMethods; + use HttpClientTrait; use MockableHttpClient; use RequestWithPresets; @@ -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/LegacySignature.php b/src/Pay/LegacySignature.php index 711ee060c..aa588435a 100644 --- a/src/Pay/LegacySignature.php +++ b/src/Pay/LegacySignature.php @@ -51,7 +51,7 @@ public function sign(array $params): array throw new InvalidConfigException('Missing V2 API key.'); } - if (! empty($params['sign_type']) && 'HMAC-SHA256' === $params['sign_type']) { + if (! empty($params['sign_type']) && $params['sign_type'] === 'HMAC-SHA256') { $signType = fn (string $message): string => hash_hmac('sha256', $message, $attributes['key']); } else { $signType = 'md5'; 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/Pay/Utils.php b/src/Pay/Utils.php index 27659548f..ef8c1a20f 100644 --- a/src/Pay/Utils.php +++ b/src/Pay/Utils.php @@ -164,7 +164,7 @@ public function createV2Signature(array $params): string throw new InvalidConfigException('Missing v2 secret key.'); } - if ('HMAC-SHA256' === $params['signType']) { + if ($params['signType'] === 'HMAC-SHA256') { $method = function ($str) use ($secretKey) { return hash_hmac('sha256', $str, $secretKey); }; diff --git a/src/Pay/Validator.php b/src/Pay/Validator.php index bac87860c..82d42377d 100644 --- a/src/Pay/Validator.php +++ b/src/Pay/Validator.php @@ -59,12 +59,12 @@ public function validate(MessageInterface $message): void ); } - if (false === \openssl_verify( + if (\openssl_verify( $message, base64_decode($signature), strval($publicKey), OPENSSL_ALGO_SHA256 - )) { + ) === false) { throw new InvalidSignatureException('Invalid Signature'); } } 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/Application.php b/src/Work/Application.php index a2ad06183..d337228c5 100644 --- a/src/Work/Application.php +++ b/src/Work/Application.php @@ -22,11 +22,11 @@ class Application implements ApplicationInterface { - use InteractWithConfig; use InteractWithCache; - use InteractWithServerRequest; - use InteractWithHttpClient; use InteractWithClient; + use InteractWithConfig; + use InteractWithHttpClient; + use InteractWithServerRequest; protected ?Encryptor $encryptor = null; 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 30519144f..ee9f29efc 100644 --- a/src/Work/Server.php +++ b/src/Work/Server.php @@ -23,8 +23,8 @@ class Server implements ServerInterface { use DecryptXmlMessage; - use RespondXmlMessage; use InteractWithHandlers; + use RespondXmlMessage; protected ServerRequestInterface $request; @@ -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);