Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
__DIR__ . '/build/build-preload.php',
])
->withRootFiles()
->withImportNames(removeUnusedImports: true)
->withImportNames()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you were testing speed? I think this can be re-enabled again, it already fast on rector-src, and this also enabled in other rector-* packages rector.php.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the removeUnusedImports: true is enabled by default.

I think we should enable it, so default behavior is the one with least work. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, current optional implementation already correct, it should be optional, as it "remove things" that can possibly there on purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I'll restore it here then.

->withSkip([
StringClassNameToClassConstantRector::class,
// tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function beforeTraverse(array $nodes): ?array
return null;
}

if ($this->startWithShebang($this->file)) {
if ($this->startsWithShebang($this->file)) {
return null;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public function refactor(Node $node): ?Node
return null;
}

private function startWithShebang(File $file): bool
private function startsWithShebang(File $file): bool
{
return str_starts_with($file->getFileContent(), '#!');
}
Expand Down
5 changes: 3 additions & 2 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public function __construct(
public function run(Configuration $configuration, InputInterface $input): ProcessResult
{
$filePaths = $this->filesFinder->findFilesInPaths($configuration->getPaths(), $configuration);
$this->missConfigurationReporter->reportVendorInPaths($filePaths);
$this->missConfigurationReporter->reportStartWithShortOpenTag();

// no files found
if ($filePaths === []) {
return new ProcessResult([], []);
}

$this->missConfigurationReporter->reportVendorInPaths($filePaths);
$this->missConfigurationReporter->reportStartWithShortOpenTag();

$this->configureCustomErrorHandler();

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\DependencyInjection\Laravel\ContainerMemento;
use Rector\Enum\Config\Defaults;
use Rector\Exception\ShouldNotHappenException;
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
use Rector\Validation\RectorConfigValidator;
Expand Down Expand Up @@ -93,8 +94,11 @@ public function disableParallel(): void
SimpleParameterProvider::setParameter(Option::PARALLEL, false);
}

public function parallel(int $processTimeout = 120, int $maxNumberOfProcess = 16, int $jobSize = 16): void
{
public function parallel(
int $processTimeout = 120,
int $maxNumberOfProcess = Defaults::PARALLEL_MAX_NUMBER_OF_PROCESS,
int $jobSize = 16
): void {
SimpleParameterProvider::setParameter(Option::PARALLEL, true);
SimpleParameterProvider::setParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS, $processTimeout);
SimpleParameterProvider::setParameter(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, $maxNumberOfProcess);
Expand Down
3 changes: 2 additions & 1 deletion src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Enum\Config\Defaults;
use Rector\Exception\Configuration\InvalidConfigurationException;
use Rector\Php\PhpVersionResolver\ComposerJsonPhpVersionResolver;
use Rector\PHPUnit\Set\PHPUnitSetList;
Expand Down Expand Up @@ -90,7 +91,7 @@ final class RectorConfigBuilder

private int $parallelTimeoutSeconds = 120;

private int $parallelMaxNumberOfProcess = 16;
private int $parallelMaxNumberOfProcess = Defaults::PARALLEL_MAX_NUMBER_OF_PROCESS;

private int $parallelJobSize = 16;

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// 2. add files and directories to static locator
$this->dynamicSourceLocatorDecorator->addPaths($paths);
if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) {
if ($this->dynamicSourceLocatorDecorator->arePathsEmpty()) {
// read from rector.php, no paths definition needs withPaths() config
if ($paths === []) {
$this->symfonyStyle->error(
Expand Down
13 changes: 13 additions & 0 deletions src/Enum/Config/Defaults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Enum\Config;

final class Defaults
{
/**
* @var int
*/
public const PARALLEL_MAX_NUMBER_OF_PROCESS = 32;
}
2 changes: 1 addition & 1 deletion src/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function resolveToStringNativeTypeFromAstResolver(PhpMethodReflection $p

if ($class instanceof ClassLike) {
$classMethod = $class->getMethod($phpMethodReflection->getName());
if ($classMethod instanceof ClassMethod && !$classMethod->returnType instanceof Node) {
if ($classMethod instanceof ClassMethod && ! $classMethod->returnType instanceof Node) {
return new MixedType();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function provide(): SourceLocator
return $this->aggregateSourceLocator = new AggregateSourceLocator($sourceLocators);
}

public function isPathsEmpty(): bool
public function arePathsEmpty(): bool
{
return $this->filePaths === [] && $this->directories === [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ final public function enterNode(Node $node): int|Node|null
* Replacing nodes in leaveNode() method avoids infinite recursion
* see"infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown
*/
public function leaveNode(Node $node): array|int|Node|null
final public function leaveNode(Node $node): array|int|Node|null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems bc break

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On purpose, this should have never been allowed.

{
if ($node->hasAttribute(AttributeKey::ORIGINAL_NODE)) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/StaticReflection/DynamicSourceLocatorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function addPaths(array $paths): void
$this->dynamicSourceLocatorProvider->addDirectories($directories);
}

public function isPathsEmpty(): bool
public function arePathsEmpty(): bool
{
return $this->dynamicSourceLocatorProvider->isPathsEmpty();
return $this->dynamicSourceLocatorProvider->arePathsEmpty();
}
}