mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 10:50:48 +00:00
add init command (#4311)
This commit is contained in:
parent
6350692b98
commit
4578e6d849
30
rector.php.dist
Normal file
30
rector.php.dist
Normal 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);
|
||||
};
|
56
src/Console/Command/InitCommand.php
Normal file
56
src/Console/Command/InitCommand.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user