Skip to content

Commit

Permalink
Apply rector
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed May 21, 2023
1 parent 5c4fdfd commit dc1f5f7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* This source file is subject to the MIT license that is bundled.
*/

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$header = <<<'EOF'
Expand Down Expand Up @@ -61,7 +62,7 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
return (new Config())
->setFinder($finder)
->setRiskyAllowed(true)
->setUsingCache(false)
Expand Down
87 changes: 44 additions & 43 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->importNames(true, false);
$rectorConfig->importShortClasses(false);
// $rectorConfig->disableParallel();
$rectorConfig->parallel(240);
$rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon');
$rectorConfig->phpVersion(PhpVersion::PHP_72);
// $rectorConfig->cacheClass(FileCacheStorage::class);
// $rectorConfig->cacheDirectory(__DIR__.'/build/rector');
// $rectorConfig->containerCacheDirectory(__DIR__.'/build/rector');
// $rectorConfig->disableParallel();
// $rectorConfig->fileExtensions(['php']);
// $rectorConfig->indent(' ', 4);
// $rectorConfig->memoryLimit('2G');
// $rectorConfig->nestedChainMethodCallLimit(3);
// $rectorConfig->noDiffs();
// $rectorConfig->parameters()->set(Option::APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY, true);
// $rectorConfig->removeUnusedImports();

$rectorConfig->bootstrapFiles([
// __DIR__.'/vendor/autoload.php',
]);
Expand All @@ -64,39 +82,42 @@

$rectorConfig->skip([
// rules
CallableThisArrayToAnonymousFunctionRector::class,
InlineIfToExplicitIfRector::class,
LogicalToBooleanRector::class,
SimplifyBoolIdenticalTrueRector::class,
RemoveEmptyMethodCallRector::class,
AddSeeTestAnnotationRector::class,
NormalizeNamespaceByPSR4ComposerAutoloadRector::class,
ChangeAndIfToEarlyReturnRector::class,
ReturnBinaryOrToEarlyReturnRector::class,
EncapsedStringsToSprintfRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,

// optional rules
// AddArrayDefaultToArrayPropertyRector::class,
// AddDefaultValueForUndefinedVariableRector::class,
// AddSeeTestAnnotationRector::class,
// CallableThisArrayToAnonymousFunctionRector::class,
// ChangeAndIfToEarlyReturnRector::class,
// ExplicitBoolCompareRector::class,
// RemoveEmptyClassMethodRector::class,
// RemoveEmptyMethodCallRector::class,
// RemoveUnusedVariableAssignRector::class,
// ReturnBinaryOrToEarlyReturnRector::class,
// SimplifyBoolIdenticalTrueRector::class,
// StaticClosureRector::class,
// UnSpreadOperatorRector::class,

ConsistentPregDelimiterRector::class,
// StaticClosureRector::class,
EncapsedStringsToSprintfRector::class,
InlineIfToExplicitIfRector::class,
LogicalToBooleanRector::class,
ReturnBinaryAndToEarlyReturnRector::class,
AddArrayDefaultToArrayPropertyRector::class,
RemoveEmptyClassMethodRector::class,
ExplicitBoolCompareRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,

NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [
__DIR__.'/src/Support/helpers.php',
],
RemoveExpectAnyFromMockRector::class => [
__DIR__.'/tests/Concerns/WithDumpableTest.php',
],
ReturnEarlyIfVariableRector::class => [
__DIR__.'/src/Support/EscapeArg.php',
],
UnSpreadOperatorRector::class => [
__DIR__.'/src/Concerns/WithDumpable.php',
],
RemoveExpectAnyFromMockRector::class => [
__DIR__.'/tests/Concerns/WithDumpableTest.php',
],

// paths
__DIR__.'/src/xxx.php',
'**/Fixture*',
'**/Fixture/*',
'**/Fixtures*',
Expand All @@ -111,7 +132,6 @@
'**/Expected*',
'**/__snapshots__/*',
'**/__snapshots__*',
__DIR__.'/src/foundation/tests/AppTest.php',
]);

$rectorConfig->sets([
Expand All @@ -121,43 +141,24 @@
SetList::CODING_STYLE,
SetList::DEAD_CODE,
// SetList::GMAGICK_TO_IMAGICK,
// SetList::MONOLOG_20,
// SetList::MYSQL_TO_MYSQLI,
SetList::NAMING,
// SetList::PRIVATIZATION,
SetList::PSR_4,
SetList::TYPE_DECLARATION,
// SetList::TYPE_DECLARATION_STRICT,
SetList::EARLY_RETURN,
SetList::INSTANCEOF,

PHPUnitLevelSetList::UP_TO_PHPUNIT_80,
// PHPUnitSetList::PHPUNIT80_DMS,
PHPUnitSetList::PHPUNIT80_DMS,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_EXCEPTION,
PHPUnitSetList::REMOVE_MOCKS,
PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD,
PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER,
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
]);

$rectorConfig->importNames(true, false);
$rectorConfig->importShortClasses(false);
// $rectorConfig->disableParallel();
$rectorConfig->parallel(240);
$rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon');
$rectorConfig->phpVersion(PhpVersion::PHP_72);

// $rectorConfig->cacheClass(FileCacheStorage::class);
// $rectorConfig->cacheDirectory(__DIR__.'/build/rector');
// $rectorConfig->containerCacheDirectory(__DIR__.'/build/rector');
// $rectorConfig->disableParallel();
// $rectorConfig->fileExtensions(['php']);
// $rectorConfig->indent(' ', 4);
// $rectorConfig->memoryLimit('2G');
// $rectorConfig->nestedChainMethodCallLimit(3);
// $rectorConfig->noDiffs();
// $rectorConfig->parameters()->set(Option::APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY, true);
// $rectorConfig->removeUnusedImports();

$rectorConfig->rules([
InlineConstructorDefaultToPropertyRector::class,
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Concerns/ConcreteScoresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testArrayScores(): void
/** @noinspection ForgottenDebugOutputInspection */
/** @noinspection DebugFunctionUsageInspection */
OS::isWindows() and dump($arrayScores);
OS::isWindows() or version_compare(PHP_VERSION, '8.1', '>=') or $this->assertMatchesYamlSnapshot($arrayScores);
OS::isWindows() or \PHP_VERSION_ID >= 80100 or $this->assertMatchesYamlSnapshot($arrayScores);
}

public function testJsonScores(): void
Expand Down

0 comments on commit dc1f5f7

Please sign in to comment.