update backers

This commit is contained in:
TomasVotruba 2019-11-24 16:05:51 +01:00
parent 86d14353f4
commit d5952978c9
7 changed files with 77 additions and 40 deletions

View File

@ -11,7 +11,6 @@
phpstan.neon
rector.yaml
create-rector.yaml.dist
phpunit.xml
ecs.yaml
ecs-after-rector.yaml

1
.gitattributes vendored
View File

@ -27,6 +27,5 @@ LICENSE export-ignore
ecs.yml export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
create-rector.yaml.dist export-ignore
rector.yaml export-ignore
utils export-ignore

View File

@ -9,25 +9,21 @@ Development of Rector is made possible thanks to these awesome backers! Would yo
Check out all the tiers - higher ones include additional goodies like placing the logo of your company in Rector's README or creating custom set for your needs.
## $20+
- Jan Votruba
## $5+
- Kerrial Newham
- Jan Mikeš
- Jan Kuchař
- Jakob Oberhummer
- Sebastian Schreiber
- Attila Fulop
## $1+
- Jakob Oberhummer
- Jan Kuchař
- Jan Mikes
- Arnaud TIERANT
**Thank you for making this happen.**
<br>
## PayPal Backers
- Musement S.p.a.
- Sebastian Schreiber
<!-- source: https://www.patreon.com/manageRewardsList -->

View File

@ -82,7 +82,7 @@
"Rector\\Php72\\": "packages/Php72/src",
"Rector\\Php73\\": "packages/Php73/src",
"Rector\\Php74\\": "packages/Php74/src",
"Rector\\Php80\\": "packages/Php80/src"
"Rector\\Php80\\": "packages/Php80/src",
"Rector\\RemovingStatic\\": "packages/RemovingStatic/src",
"Rector\\Renaming\\": "packages/Renaming/src",
"Rector\\Restoration\\": "packages/Restoration/src",
@ -143,7 +143,7 @@
"Rector\\Php72\\Tests\\": "packages/Php72/tests",
"Rector\\Php73\\Tests\\": "packages/Php73/tests",
"Rector\\Php74\\Tests\\": "packages/Php74/tests",
"Rector\\Php80\\Tests\\": "packages/Php80/tests"
"Rector\\Php80\\Tests\\": "packages/Php80/tests",
"Rector\\RemovingStatic\\Tests\\": "packages/RemovingStatic/tests",
"Rector\\Renaming\\Tests\\": "packages/Renaming/tests",
"Rector\\Restoration\\Tests\\": "packages/Restoration/tests",

View File

@ -97,7 +97,7 @@ final class CreateRectorCommand extends Command implements ContributorCommandInt
protected function configure(): void
{
$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('Create a new Rector, in proper location, with new tests');
$this->setDescription('Create a new Rector, in a proper location, with new tests');
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -108,37 +108,64 @@ final class CreateRectorCommand extends Command implements ContributorCommandInt
// setup psr-4 autoload, if not already in
$this->composerPackageAutoloadUpdater->processComposerAutoload($configuration);
$templateFileInfos = $this->findTemplateFileInfos();
$isUnwantedOverride = $this->isUnwantedOverride($templateFileInfos, $templateVariables, $configuration);
if ($isUnwantedOverride) {
$this->symfonyStyle->warning(
'The rule already exists and you decided to keep the original. No files were changed'
);
return ShellCode::SUCCESS;
}
foreach ($this->findTemplateFileInfos() as $smartFileInfo) {
$destination = $this->resolveDestination($smartFileInfo, $templateVariables, $configuration);
$content = $this->resolveContent($smartFileInfo, $templateVariables);
if ($configuration->getPackage() === 'Rector') {
$content = Strings::replace($content, '#Rector\\\\Rector\\\\#ms', 'Rector\\');
$content = Strings::replace(
$content,
'#use Rector\\\\AbstractRector;#',
'use Rector\\Rector\\AbstractRector;'
);
$content = $this->addOneMoreRectorNesting($content);
}
FileSystem::write($destination, $content);
$this->generatedFiles[] = $destination;
// is test case?
// is a test case?
if (Strings::endsWith($destination, 'Test.php')) {
$this->testCasePath = dirname($destination);
}
}
$this->appendToLevelConfig($configuration, $templateVariables);
$this->appendRectorServiceToSetConfig($configuration, $templateVariables);
$this->printSuccess($configuration->getName());
return ShellCode::SUCCESS;
}
/**
* @param SmartFileInfo[] $templateFileInfos
* @param mixed[] $templateVariables
*/
private function isUnwantedOverride(
array $templateFileInfos,
array $templateVariables,
Configuration $configuration
) {
foreach ($templateFileInfos as $templateFileInfo) {
$destination = $this->resolveDestination($templateFileInfo, $templateVariables, $configuration);
if (! file_exists($destination)) {
continue;
}
return ! $this->symfonyStyle->confirm('Files for this rules already exist. Should we override them?');
}
return false;
}
/**
* @return SmartFileInfo[]
*/
@ -189,33 +216,33 @@ final class CreateRectorCommand extends Command implements ContributorCommandInt
/**
* @param string[] $templateVariables
*/
private function appendToLevelConfig(Configuration $configuration, array $templateVariables): void
private function appendRectorServiceToSetConfig(Configuration $configuration, array $templateVariables): void
{
if ($configuration->getLevelConfig() === null) {
if ($configuration->getSetConfig() === null) {
return;
}
if (! file_exists($configuration->getLevelConfig())) {
if (! file_exists($configuration->getSetConfig())) {
return;
}
$rectorFqnName = $this->applyVariables(self::RECTOR_FQN_NAME_PATTERN, $templateVariables);
$levelConfigContent = FileSystem::read($configuration->getLevelConfig());
$setConfigContent = FileSystem::read($configuration->getSetConfig());
// already added
if (Strings::contains($levelConfigContent, $rectorFqnName)) {
if (Strings::contains($setConfigContent, $rectorFqnName)) {
return;
}
$levelConfigContent = trim($levelConfigContent) . sprintf(
$setConfigContent = trim($setConfigContent) . sprintf(
'%s%s: ~%s',
PHP_EOL,
Strings::indent($rectorFqnName, 4, ' '),
$this->indentFourSpaces($rectorFqnName),
PHP_EOL
);
FileSystem::write($configuration->getLevelConfig(), $levelConfigContent);
FileSystem::write($configuration->getSetConfig(), $setConfigContent);
}
private function printSuccess(string $name): void
@ -225,7 +252,7 @@ final class CreateRectorCommand extends Command implements ContributorCommandInt
$this->symfonyStyle->listing($this->generatedFiles);
$this->symfonyStyle->success(sprintf(
'Now make these tests green again:%svendor/bin/phpunit %s',
'Now make these tests green:%svendor/bin/phpunit %s',
PHP_EOL . PHP_EOL,
$this->testCasePath
));
@ -238,4 +265,20 @@ final class CreateRectorCommand extends Command implements ContributorCommandInt
{
return str_replace(array_keys($variables), array_values($variables), $content);
}
private function addOneMoreRectorNesting(string $content): string
{
$content = Strings::replace($content, '#Rector\\\\Rector\\\\#ms', 'Rector\\');
return Strings::replace(
$content,
'#use Rector\\\\AbstractRector;#',
'use Rector\\Rector\\AbstractRector;'
);
}
private function indentFourSpaces(string $string): string
{
return Strings::indent($string, 4, ' ');
}
}

View File

@ -46,7 +46,7 @@ final class ComposerPackageAutoloadUpdater
// ask user
$isConfirmed = $this->symfonyStyle->confirm(sprintf(
'Can we update composer.json autoload section with "%s" namespace?%s Or you have to handle it manually',
'Can we update "composer.json" autoload with "%s" namespace?%s Handle it manually otherwise',
$package->getSrcNamespace(),
PHP_EOL
));

View File

@ -41,7 +41,7 @@ final class Configuration
/**
* @var string|null
*/
private $levelConfig;
private $setConfig;
/**
* @var string[]
@ -66,7 +66,7 @@ final class Configuration
string $codeBefore,
string $codeAfter,
array $source,
?string $levelConfig
?string $setConfig
) {
$this->package = $package;
$this->setName($name);
@ -76,7 +76,7 @@ final class Configuration
$this->codeAfter = $codeAfter;
$this->description = $description;
$this->source = $source;
$this->levelConfig = $levelConfig;
$this->setConfig = $setConfig;
}
public function getDescription(): string
@ -125,9 +125,9 @@ final class Configuration
return $this->source;
}
public function getLevelConfig(): ?string
public function getSetConfig(): ?string
{
return $this->levelConfig;
return $this->setConfig;
}
private function setName(string $name): void