Skip to content

Commit

Permalink
Update rector config
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Aug 21, 2024
1 parent ae0a21d commit f261a32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 51 deletions.
7 changes: 3 additions & 4 deletions benchmarks/Utils/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QueryGenerator

private int $maxLeafFields;

private int $currentLeafFields;
private int $currentLeafFields = 0;

public function __construct(Schema $schema, float $percentOfLeafFields)
{
Expand All @@ -32,12 +32,11 @@ public function __construct(Schema $schema, float $percentOfLeafFields)
$totalFields = 0;
foreach ($schema->getTypeMap() as $type) {
if ($type instanceof ObjectType) {
$totalFields += \count($type->getFieldNames());
$totalFields += count($type->getFieldNames());
}
}

$this->maxLeafFields = \max(1, (int) \round($totalFields * $percentOfLeafFields));
$this->currentLeafFields = 0;
$this->maxLeafFields = max(1, (int) round($totalFields * $percentOfLeafFields));
}

public function buildQuery(): string
Expand Down
72 changes: 25 additions & 47 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,40 @@
<?php declare(strict_types=1);

use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector;
use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodeQuality\Rector\Switch_\SwitchTrueToIfRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertIssetToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertPropertyExistsRector;
use Rector\PHPUnit\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
return static function (Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
PHPUnitSetList::PHPUNIT_60,
PHPUnitSetList::PHPUNIT_70,
PHPUnitSetList::PHPUNIT_80,
PHPUnitSetList::PHPUNIT_90,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
Rector\Set\ValueObject\SetList::CODE_QUALITY,
Rector\Set\ValueObject\SetList::DEAD_CODE,
Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_60,
Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_70,
Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_80,
Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_90,
Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);
$rectorConfig->skip([
AddSeeTestAnnotationRector::class, // We do not bundle tests, so referring to them is confusing for library users
PreferPHPUnitThisCallRector::class, // Prefer self::
AddDoesNotPerformAssertionToNonAssertingTestRector::class, // False-positive
CallableThisArrayToAnonymousFunctionRector::class, // Callable in array form is shorter and more efficient
IssetOnPropertyObjectToPropertyExistsRector::class, // isset() is nice when moving towards typed properties
FlipTypeControlToUseExclusiveTypeRector::class, // Unnecessarily complex with PHPStan
JoinStringConcatRector::class => [
__DIR__ . '/tests',
Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector::class, // Prefer self::
Rector\PHPUnit\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector::class, // False-positive
Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector::class, // isset() is nice when moving towards typed properties
Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector::class, // Unnecessarily complex with PHPStan
Rector\CodeQuality\Rector\Concat\JoinStringConcatRector::class => [
__DIR__ . '/tests', // Sometimes more readable for long strings
],
LocallyCalledStaticMethodToNonStaticRector::class, // static methods are fine
UnusedForeachValueToArrayKeysRector::class, // Less efficient
RemoveAlwaysTrueIfConditionRector::class, // Sometimes necessary to prove runtime behaviour matches defined types
RemoveDeadInstanceOfRector::class, // Sometimes necessary to prove runtime behaviour matches defined types
RemoveNonExistingVarAnnotationRector::class, // Sometimes false-positive
RemoveUnusedPrivatePropertyRector::class, // TODO reintroduce when https://github.com/rectorphp/rector-src/pull/4491 is released
AssertPropertyExistsRector::class, // Uses deprecated PHPUnit methods
AssertIssetToSpecificMethodRector::class => [
Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class, // static methods are fine
Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector::class, // Less efficient
Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector::class, // Sometimes necessary to prove runtime behaviour matches defined types
Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector::class, // Sometimes necessary to prove runtime behaviour matches defined types
Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector::class, // Sometimes false-positive
Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector::class, // TODO reintroduce when https://github.com/rectorphp/rector-src/pull/4491 is released
Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertPropertyExistsRector::class, // Uses deprecated PHPUnit methods
Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertIssetToSpecificMethodRector::class => [
__DIR__ . '/tests/Utils/MixedStoreTest.php', // Uses keys that are not string or int
],
AssertEqualsToSameRector::class => [
Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector::class => [
__DIR__ . '/tests/TestCaseBase.php', // Array output may differ between tested PHP versions, assertEquals smooths over this
],
SwitchTrueToIfRector::class, // More expressive in some cases
Rector\CodeQuality\Rector\Switch_\SwitchTrueToIfRector::class, // More expressive in some cases
]);
$rectorConfig->paths([
__DIR__ . '/benchmarks',
__DIR__ . '/examples',
__DIR__ . '/phpstan',
__DIR__ . '/src',
Expand Down

0 comments on commit f261a32

Please sign in to comment.