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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ parameters:
php_version_features: '7.2' # your version is 7.3
```

### Paths

If you're annoyed by repeating paths in arguments, you can move them to config instead:

```yaml
# rector.yaml
parameters:
paths:
- 'src'
- 'tests'
```

### Import Use Statements

FQN classes are imported by default every time Rector performs a change, so you don't have to do it manually/after each run. You can disable it by:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"bin/rector dump-rectors -o markdown > docs/AllRectorsOverview.md",
"bin/rector dump-nodes -o markdown > docs/NodesOverview.md"
],
"rector": "bin/rector process packages src tests --config rector-ci.yaml --dry-run"
"rector": "bin/rector process --config rector-ci.yaml --dry-run"
},
"scripts-descriptions": {
"docs": "Regenerate descriptions of all Rectors to docs/AllRectorsOverview.md file"
Expand Down
6 changes: 5 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ imports:
- { resource: '../utils/**/config/config.yaml', ignore_errors: true }

parameters:
# processed paths
paths: []
exclude_paths: []
exclude_rectors: []
autoload_paths: []
Expand All @@ -16,6 +18,8 @@ parameters:
# e.g. /** @var \Some\ClassHere */
import_doc_blocks: true

php_version_features: ~ # what PHP version should be used for features, local PHP version is used by default
# what PHP version is used for features, composer.json version, then local PHP version is used by default
php_version_features: ~

file_extensions:
- 'php'
5 changes: 5 additions & 0 deletions rector-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ parameters:
- 'dead-code'
- 'nette-utils-code-quality'

paths:
- 'src'
- 'packages'
- 'tests'

exclude_paths:
- '/Fixture/'
- '/Source/'
Expand Down
28 changes: 26 additions & 2 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ final class ProcessCommand extends AbstractCommand
private $stubLoader;

/**
* @var string[]
*/
private $paths = [];

/**
* @param string[] $paths
* @param string[] $fileExtensions
*/
public function __construct(
Expand All @@ -94,6 +100,7 @@ public function __construct(
ReportingExtensionRunner $reportingExtensionRunner,
RectorNodeTraverser $rectorNodeTraverser,
StubLoader $stubLoader,
array $paths,
array $fileExtensions
) {
$this->filesFinder = $phpFilesFinder;
Expand All @@ -109,6 +116,7 @@ public function __construct(
$this->stubLoader = $stubLoader;

parent::__construct();
$this->paths = $paths;
}

protected function configure(): void
Expand All @@ -117,7 +125,7 @@ protected function configure(): void
$this->setDescription('Upgrade or refactor source code with provided rectors');
$this->addArgument(
Option::SOURCE,
InputArgument::REQUIRED | InputArgument::IS_ARRAY,
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Files or directories to be upgraded.'
);
$this->addOption(
Expand Down Expand Up @@ -160,7 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->rectorGuard->ensureSomeRectorsAreRegistered();
$this->stubLoader->loadStubs();

$source = (array) $input->getArgument(Option::SOURCE);
$source = $this->resolvesSourcePaths($input);

$phpFileInfos = $this->filesFinder->findInDirectoriesAndFiles($source, $this->fileExtensions);

Expand All @@ -187,4 +195,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Shell::CODE_SUCCESS;
}

/**
* @return string[]
*/
private function resolvesSourcePaths(InputInterface $input): array
{
$commandLinePaths = (array) $input->getArgument(Option::SOURCE);

// manual command line value has priority
if (count($commandLinePaths) > 0) {
return $commandLinePaths;
}

// fallback to config defined paths
return $this->paths;
}
}