[DX] add "paths" parameter (#2302)

[DX] add "paths" parameter
This commit is contained in:
Tomáš Votruba 2019-11-10 18:55:29 +01:00 committed by GitHub
commit 23ea1397c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 4 deletions

View File

@ -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:

View File

@ -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"

View File

@ -5,6 +5,8 @@ imports:
- { resource: '../utils/**/config/config.yaml', ignore_errors: true }
parameters:
# processed paths
paths: []
exclude_paths: []
exclude_rectors: []
autoload_paths: []
@ -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'

View File

@ -5,6 +5,11 @@ parameters:
- 'dead-code'
- 'nette-utils-code-quality'
paths:
- 'src'
- 'packages'
- 'tests'
exclude_paths:
- '/Fixture/'
- '/Source/'

View File

@ -81,6 +81,12 @@ final class ProcessCommand extends AbstractCommand
private $stubLoader;
/**
* @var string[]
*/
private $paths = [];
/**
* @param string[] $paths
* @param string[] $fileExtensions
*/
public function __construct(
@ -94,6 +100,7 @@ final class ProcessCommand extends AbstractCommand
ReportingExtensionRunner $reportingExtensionRunner,
RectorNodeTraverser $rectorNodeTraverser,
StubLoader $stubLoader,
array $paths,
array $fileExtensions
) {
$this->filesFinder = $phpFilesFinder;
@ -109,6 +116,7 @@ final class ProcessCommand extends AbstractCommand
$this->stubLoader = $stubLoader;
parent::__construct();
$this->paths = $paths;
}
protected function configure(): void
@ -117,7 +125,7 @@ final class ProcessCommand extends AbstractCommand
$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(
@ -160,7 +168,7 @@ final class ProcessCommand extends AbstractCommand
$this->rectorGuard->ensureSomeRectorsAreRegistered();
$this->stubLoader->loadStubs();
$source = (array) $input->getArgument(Option::SOURCE);
$source = $this->resolvesSourcePaths($input);
$phpFileInfos = $this->filesFinder->findInDirectoriesAndFiles($source, $this->fileExtensions);
@ -187,4 +195,20 @@ final class ProcessCommand extends AbstractCommand
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;
}
}