add init command (#4311)

This commit is contained in:
Kerrial Newham 2020-09-28 23:42:20 +02:00 committed by GitHub
parent 6350692b98
commit 4578e6d849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 0 deletions

30
rector.php.dist Normal file
View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
use Rector\Architecture\Rector\Class_\MoveRepositoryFromParentToConstructorRector;
use Rector\Architecture\Rector\MethodCall\ReplaceParentRepositoryCallsByRepositoryPropertyRector;
use Rector\Core\Configuration\Option;
use Rector\Doctrine\Rector\Class_\RemoveRepositoryFromEntityAnnotationRector;
use Rector\Set\ValueObject\SetList;
use Rector\SOLID\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\TypeDeclaration\Rector\Property\PropertyTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
// Define what rule sets will be applied
$parameters->set(Option::SETS, [
SetList::NAMING,
SetList::CODE_QUALITY,
]);
// get services (needed for register a single rule)
// $services = $containerConfigurator->services();
// register a single rule
// $services->set(TypedPropertyRector::class);
};

View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace Rector\Core\Console\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Console\Command\CommandNaming;
use Symplify\PackageBuilder\Console\ShellCode;
use Symplify\SmartFileSystem\SmartFileSystem;
final class InitCommand extends AbstractCommand
{
/**
* @var SmartFileSystem
*/
private $smartFileSystem;
/**
* @var SymfonyStyle
*/
private $symfonyStyle;
/**
* InitCommand constructor.
*/
public function __construct(SmartFileSystem $smartFileSystem, SymfonyStyle $symfonyStyle)
{
parent::__construct();
$this->smartFileSystem = $smartFileSystem;
$this->symfonyStyle = $symfonyStyle;
}
protected function configure(): void
{
$this->setName(CommandNaming::classToName(self::class));
$this->setDescription('Generate rector.php configuration file');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$rectorConfigFiles = $this->smartFileSystem->exists(getcwd() . '/rector.php');
if (! $rectorConfigFiles) {
$this->smartFileSystem->copy('rector.php.dist', getcwd() . '/rector.php');
$this->symfonyStyle->success('rector.php config file has been generated successfully');
} else {
$this->symfonyStyle->error('Config file not generated. A rector.php configuration file already exists');
}
return ShellCode::SUCCESS;
}
}