Skip to content

Commit

Permalink
apply rector
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Feb 6, 2024
1 parent 2f23179 commit c2922a6
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 47 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 2 additions & 7 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
</projectFiles>
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="info"/>
<InvalidReturnStatement>
<errorLevel type="suppress">
<directory name="src/Clients"/>
</errorLevel>
</InvalidReturnStatement>
<UnusedClosureParam>
<!--<UnusedClosureParam>
<errorLevel type="suppress">
<directory name="src/Messages"/>
</errorLevel>
</UnusedClosureParam>
</UnusedClosureParam>-->
</issueHandlers>
<plugins>
<!--<pluginClass class="Psalm\LaravelPlugin\Plugin"/>-->
Expand Down
48 changes: 28 additions & 20 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
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;
use Rector\PHPUnit\Set\PHPUnitSetList;
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 {
Expand All @@ -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);
Expand Down Expand Up @@ -91,6 +93,12 @@
RemoveEmptyClassMethodRector::class,
ExplicitBoolCompareRector::class,
AddSeeTestAnnotationRector::class,
DisallowedEmptyRuleFixerRector::class,
RemoveUselessReturnTagRector::class,

StaticClosureRector::class => [
__DIR__.'/tests',
],

// paths
__DIR__.'/src/Clients',
Expand All @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions src/Foundation/Credentials/AggregateCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/BasicAuthCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class BasicAuthCredential extends NullCredential
{
private string $username;

private string $password;

public function __construct(string $username, string $password)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/CertificateCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class CertificateCredential extends NullCredential
{
private string $path;

private ?string $password;

public function __construct(string $path, ?string $password = null)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/DigestAuthCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class DigestAuthCredential extends NullCredential
{
private string $username;

private string $password;

public function __construct(string $username, string $password)
Expand Down
2 changes: 2 additions & 0 deletions src/Foundation/Credentials/KeyValueCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/NtlmAuthCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class NtlmAuthCredential extends NullCredential
{
private string $username;

private string $password;

public function __construct(string $username, string $password)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/UriTemplateCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class UriTemplateCredential extends NullCredential
{
private array $variables;

private HttpFactory $httpFactory;

public function __construct(array $variables)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/WebHookCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class WebHookCredential extends NullCredential
{
private string $webHook;

private HttpFactory $httpFactory;

public function __construct(string $webHook)
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/Credentials/WsseAuthCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class WsseAuthCredential extends NullCredential
{
private string $username;

private string $password;

public function __construct(string $username, string $password)
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Middleware/EnsureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/Foundation/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -49,6 +50,7 @@ class UpdateHasHttpClientDocCommentRector extends AbstractRector implements Conf
];

private DocBlockUpdater $docBlockUpdater;

private PhpDocInfoFactory $phpDocInfoFactory;

public function __construct(DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Message extends \Guanguans\Notify\Foundation\Message
}
CODE_SAMPLE
,
['\Guanguans\Notify\Foundation\Message::class']
[Message::class]
),
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions src/Foundation/Traits/Conditionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Foundation/Traits/HasHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
trait HasHttpClient
{
private ?Client $httpClient = null;

private $httpClientResolver;

private ?HandlerStack $handlerStack = null;

private array $httpOptions = [];

/**
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c2922a6

Please sign in to comment.