diff --git a/composer.json b/composer.json
index 50de7198..4341c4e6 100644
--- a/composer.json
+++ b/composer.json
@@ -167,7 +167,8 @@
"@md-lint",
"@zh-lint",
"@style-lint",
- "@test"
+ "@test",
+ "@rector-dry-run"
],
"composer-bin-all-update": "@composer bin all update --ansi -v",
"composer-check-platform-reqs": "@composer check-platform-reqs --lock --ansi -v",
diff --git a/psalm.xml.dist b/psalm.xml.dist
index c826f936..d435b0a6 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -19,16 +19,11 @@
-
-
-
-
-
-
+
diff --git a/rector.php b/rector.php
index cc89cbb9..891eb05b 100644
--- a/rector.php
+++ b/rector.php
@@ -26,6 +26,7 @@
use Rector\Configuration\Option;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
+use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
@@ -33,6 +34,7 @@
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
+use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\ValueObject\PhpVersion;
return static function (RectorConfig $rectorConfig): void {
@@ -43,7 +45,7 @@
$rectorConfig->importNames(false, false);
$rectorConfig->importShortClasses(false);
$rectorConfig->parallel(240);
- $rectorConfig->disableParallel();
+ // $rectorConfig->disableParallel();
$rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon');
$rectorConfig->phpVersion(PhpVersion::PHP_74);
// $rectorConfig->cacheClass(FileCacheStorage::class);
@@ -91,6 +93,12 @@
RemoveEmptyClassMethodRector::class,
ExplicitBoolCompareRector::class,
AddSeeTestAnnotationRector::class,
+ DisallowedEmptyRuleFixerRector::class,
+ RemoveUselessReturnTagRector::class,
+
+ StaticClosureRector::class => [
+ __DIR__.'/tests',
+ ],
// paths
__DIR__.'/src/Clients',
@@ -113,25 +121,25 @@
]);
$rectorConfig->sets([
- // DowngradeLevelSetList::DOWN_TO_PHP_74,
- // LevelSetList::UP_TO_PHP_74,
- // // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION,
- // SetList::CODE_QUALITY,
- // SetList::CODING_STYLE,
- // SetList::DEAD_CODE,
- // // SetList::STRICT_BOOLEANS,
- // // SetList::GMAGICK_TO_IMAGICK,
- // // SetList::MYSQL_TO_MYSQLI,
- // SetList::NAMING,
- // // SetList::PRIVATIZATION,
- // // SetList::PSR_4,
- // SetList::TYPE_DECLARATION,
- // SetList::EARLY_RETURN,
- // SetList::INSTANCEOF,
- //
- // PHPUnitSetList::PHPUNIT_90,
- // PHPUnitSetList::PHPUNIT_CODE_QUALITY,
- // PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
+ DowngradeLevelSetList::DOWN_TO_PHP_74,
+ LevelSetList::UP_TO_PHP_74,
+ // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION,
+ SetList::CODE_QUALITY,
+ SetList::CODING_STYLE,
+ SetList::DEAD_CODE,
+ // SetList::STRICT_BOOLEANS,
+ // SetList::GMAGICK_TO_IMAGICK,
+ // SetList::MYSQL_TO_MYSQLI,
+ SetList::NAMING,
+ // SetList::PRIVATIZATION,
+ // SetList::PSR_4,
+ SetList::TYPE_DECLARATION,
+ SetList::EARLY_RETURN,
+ SetList::INSTANCEOF,
+
+ PHPUnitSetList::PHPUNIT_90,
+ PHPUnitSetList::PHPUNIT_CODE_QUALITY,
+ PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);
$rectorConfig->rules([
diff --git a/src/Foundation/Credentials/AggregateCredential.php b/src/Foundation/Credentials/AggregateCredential.php
index 251c344b..9d769afa 100644
--- a/src/Foundation/Credentials/AggregateCredential.php
+++ b/src/Foundation/Credentials/AggregateCredential.php
@@ -22,9 +22,9 @@ class AggregateCredential implements Credential
*/
private array $credentials;
- public function __construct(Credential ...$credentials)
+ public function __construct(Credential ...$credential)
{
- $this->credentials = $credentials;
+ $this->credentials = $credential;
}
public function applyToOptions(array $options): array
@@ -40,7 +40,7 @@ public function applyToRequest(RequestInterface $request): RequestInterface
{
return array_reduce(
$this->credentials,
- static fn (RequestInterface $carry, Credential $credential): RequestInterface => $credential->applyToRequest($carry),
+ static fn (RequestInterface $request, Credential $credential): RequestInterface => $credential->applyToRequest($request),
$request,
);
}
diff --git a/src/Foundation/Credentials/BasicAuthCredential.php b/src/Foundation/Credentials/BasicAuthCredential.php
index 34fa70a8..7c99aaf8 100644
--- a/src/Foundation/Credentials/BasicAuthCredential.php
+++ b/src/Foundation/Credentials/BasicAuthCredential.php
@@ -23,6 +23,7 @@
class BasicAuthCredential extends NullCredential
{
private string $username;
+
private string $password;
public function __construct(string $username, string $password)
diff --git a/src/Foundation/Credentials/CertificateCredential.php b/src/Foundation/Credentials/CertificateCredential.php
index f5d73e2f..5baa9a8e 100644
--- a/src/Foundation/Credentials/CertificateCredential.php
+++ b/src/Foundation/Credentials/CertificateCredential.php
@@ -17,6 +17,7 @@
class CertificateCredential extends NullCredential
{
private string $path;
+
private ?string $password;
public function __construct(string $path, ?string $password = null)
diff --git a/src/Foundation/Credentials/DigestAuthCredential.php b/src/Foundation/Credentials/DigestAuthCredential.php
index 4909e7cd..f57df03d 100644
--- a/src/Foundation/Credentials/DigestAuthCredential.php
+++ b/src/Foundation/Credentials/DigestAuthCredential.php
@@ -17,6 +17,7 @@
class DigestAuthCredential extends NullCredential
{
private string $username;
+
private string $password;
public function __construct(string $username, string $password)
diff --git a/src/Foundation/Credentials/KeyValueCredential.php b/src/Foundation/Credentials/KeyValueCredential.php
index f4d01c9a..bc119250 100644
--- a/src/Foundation/Credentials/KeyValueCredential.php
+++ b/src/Foundation/Credentials/KeyValueCredential.php
@@ -17,7 +17,9 @@
class KeyValueCredential extends NullCredential
{
private string $key;
+
private string $value;
+
private string $type;
public function __construct(string $key, string $value, string $type = RequestOptions::HEADERS)
diff --git a/src/Foundation/Credentials/NtlmAuthCredential.php b/src/Foundation/Credentials/NtlmAuthCredential.php
index 7549c12a..1674ad3e 100644
--- a/src/Foundation/Credentials/NtlmAuthCredential.php
+++ b/src/Foundation/Credentials/NtlmAuthCredential.php
@@ -17,6 +17,7 @@
class NtlmAuthCredential extends NullCredential
{
private string $username;
+
private string $password;
public function __construct(string $username, string $password)
diff --git a/src/Foundation/Credentials/UriTemplateCredential.php b/src/Foundation/Credentials/UriTemplateCredential.php
index 72643c3a..352fc27d 100644
--- a/src/Foundation/Credentials/UriTemplateCredential.php
+++ b/src/Foundation/Credentials/UriTemplateCredential.php
@@ -19,6 +19,7 @@
class UriTemplateCredential extends NullCredential
{
private array $variables;
+
private HttpFactory $httpFactory;
public function __construct(array $variables)
diff --git a/src/Foundation/Credentials/WebHookCredential.php b/src/Foundation/Credentials/WebHookCredential.php
index fa943f3d..a0119b73 100644
--- a/src/Foundation/Credentials/WebHookCredential.php
+++ b/src/Foundation/Credentials/WebHookCredential.php
@@ -18,6 +18,7 @@
class WebHookCredential extends NullCredential
{
private string $webHook;
+
private HttpFactory $httpFactory;
public function __construct(string $webHook)
diff --git a/src/Foundation/Credentials/WsseAuthCredential.php b/src/Foundation/Credentials/WsseAuthCredential.php
index 2fca2df9..84b2396d 100644
--- a/src/Foundation/Credentials/WsseAuthCredential.php
+++ b/src/Foundation/Credentials/WsseAuthCredential.php
@@ -17,6 +17,7 @@
class WsseAuthCredential extends NullCredential
{
private string $username;
+
private string $password;
public function __construct(string $username, string $password)
diff --git a/src/Foundation/Middleware/EnsureResponse.php b/src/Foundation/Middleware/EnsureResponse.php
index be6e877e..13deb19a 100644
--- a/src/Foundation/Middleware/EnsureResponse.php
+++ b/src/Foundation/Middleware/EnsureResponse.php
@@ -20,7 +20,7 @@ class EnsureResponse
{
public function __invoke(callable $handler): callable
{
- return Middleware::mapResponse(fn (ResponseInterface $response): ResponseInterface => Response::createFromPsrResponse($response))($handler);
+ return Middleware::mapResponse(static fn (ResponseInterface $response): ResponseInterface => Response::createFromPsrResponse($response))($handler);
}
public static function name(): string
diff --git a/src/Foundation/Support/Str.php b/src/Foundation/Support/Str.php
index 3c5b3223..58c96682 100644
--- a/src/Foundation/Support/Str.php
+++ b/src/Foundation/Support/Str.php
@@ -42,11 +42,7 @@ public static function pascal(string $value): string
*/
public static function camel(string $value): string
{
- if (isset(static::$camelCache[$value])) {
- return static::$camelCache[$value];
- }
-
- return static::$camelCache[$value] = lcfirst(static::studly($value));
+ return static::$camelCache[$value] ?? (static::$camelCache[$value] = lcfirst(static::studly($value)));
}
/**
@@ -82,7 +78,7 @@ public static function studly(string $value): string
$words = explode(' ', static::replace(['-', '_'], ' ', $value));
- $studlyWords = array_map(fn ($word) => static::ucfirst($word), $words);
+ $studlyWords = array_map(static fn ($word): string => static::ucfirst($word), $words);
return static::$studlyCache[$key] = implode('', $studlyWords);
}
@@ -94,8 +90,6 @@ public static function studly(string $value): string
*/
public static function is($pattern, string $value): bool
{
- $value = (string) $value;
-
if (! is_iterable($pattern)) {
$pattern = [$pattern];
}
diff --git a/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php b/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php
index 42ac4f27..f6ade006 100644
--- a/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php
+++ b/src/Foundation/Support/UpdateHasHttpClientDocCommentRector.php
@@ -33,6 +33,7 @@
class UpdateHasHttpClientDocCommentRector extends AbstractRector implements ConfigurableRectorInterface
{
private const MAIN_CLASS = \Guanguans\Notify\Foundation\Client::class;
+
private const TRAIT = HasHttpClient::class;
private array $except = [
@@ -49,6 +50,7 @@ class UpdateHasHttpClientDocCommentRector extends AbstractRector implements Conf
];
private DocBlockUpdater $docBlockUpdater;
+
private PhpDocInfoFactory $phpDocInfoFactory;
public function __construct(DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory)
@@ -119,7 +121,7 @@ public function refactor(Node $node)
foreach ($this->mixins as $mixin) {
$reflectionMethods = array_filter(
(new \ReflectionClass($mixin))->getMethods(\ReflectionMethod::IS_PUBLIC),
- fn (\ReflectionMethod $reflectionMethod) => ! Str::is($this->except, $reflectionMethod->getName())
+ fn (\ReflectionMethod $reflectionMethod): bool => ! Str::is($this->except, $reflectionMethod->getName())
);
foreach ($reflectionMethods as $reflectionMethod) {
@@ -160,7 +162,7 @@ private function createMethodPhpDocTagNode(\ReflectionMethod $reflectionMethod):
$parameters = rtrim(
array_reduce(
$reflectionMethod->getParameters(),
- static function (string $carry, \ReflectionParameter $reflectionParameter) {
+ static function (string $carry, \ReflectionParameter $reflectionParameter): string {
if ($reflectionParameter->hasType()) {
/** @noinspection PhpVoidFunctionResultUsedInspection */
$type = $reflectionParameter->getType();
diff --git a/src/Foundation/Support/UpdateHasOptionsDocCommentRector.php b/src/Foundation/Support/UpdateHasOptionsDocCommentRector.php
index f365ea39..701ad4e5 100644
--- a/src/Foundation/Support/UpdateHasOptionsDocCommentRector.php
+++ b/src/Foundation/Support/UpdateHasOptionsDocCommentRector.php
@@ -74,7 +74,7 @@ class Message extends \Guanguans\Notify\Foundation\Message
}
CODE_SAMPLE
,
- ['\Guanguans\Notify\Foundation\Message::class']
+ [Message::class]
),
]
);
diff --git a/src/Foundation/Support/helpers.php b/src/Foundation/Support/helpers.php
index a8c32226..98a1f2af 100644
--- a/src/Foundation/Support/helpers.php
+++ b/src/Foundation/Support/helpers.php
@@ -39,7 +39,7 @@ function to_multipart(array $form): array
// preg_match('/^.*:\/\/.*$/', $contents);
is_string($contents) and is_file($contents) and $contents = Utils::tryFopen($contents, 'r');
- return [compact('name', 'contents')];
+ return [['name' => $name, 'contents' => $contents]];
}
if (
diff --git a/src/Foundation/Traits/Conditionable.php b/src/Foundation/Traits/Conditionable.php
index c45021a7..7a7f3ef5 100644
--- a/src/Foundation/Traits/Conditionable.php
+++ b/src/Foundation/Traits/Conditionable.php
@@ -36,7 +36,8 @@ public function when($value = null, ?callable $callback = null, ?callable $defau
if ($value) {
return $callback($this, $value) ?? $this;
}
- if ($default) {
+
+ if (null !== $default) {
return $default($this, $value) ?? $this;
}
@@ -62,7 +63,8 @@ public function unless($value = null, ?callable $callback = null, ?callable $def
if (! $value) {
return $callback($this, $value) ?? $this;
}
- if ($default) {
+
+ if (null !== $default) {
return $default($this, $value) ?? $this;
}
diff --git a/src/Foundation/Traits/HasHttpClient.php b/src/Foundation/Traits/HasHttpClient.php
index 05750a3a..387abed9 100644
--- a/src/Foundation/Traits/HasHttpClient.php
+++ b/src/Foundation/Traits/HasHttpClient.php
@@ -51,8 +51,11 @@
trait HasHttpClient
{
private ?Client $httpClient = null;
+
private $httpClientResolver;
+
private ?HandlerStack $handlerStack = null;
+
private array $httpOptions = [];
/**
@@ -165,7 +168,7 @@ private function ensureWithApplyCredentialToRequest(HandlerStack $handlerStack):
(function (): void {
$this->findByName(ApplyCredentialToRequest::name());
})->call($handlerStack);
- } catch (\InvalidArgumentException $e) {
+ } catch (\InvalidArgumentException $invalidArgumentException) {
$handlerStack->push(
new ApplyCredentialToRequest($this->credential),
ApplyCredentialToRequest::name()