make use of Set constants

This commit is contained in:
TomasVotruba 2020-07-20 00:52:12 +02:00
parent aeb7937972
commit ee9d0439cf
8 changed files with 167 additions and 8 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\Set;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -44,6 +45,6 @@ CODE_SAMPLE,
'https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.0.md',
],
# e.g. symfony30, target config to append this rector to
'set' => 'symfony30',
'set' => Set::SYMFONY_30,
]);
};

View File

@ -32,6 +32,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(StandaloneLineInMultilineArrayFixer::class);
$services->set(LineLengthFixer::class);
$services->set(GeneralPhpdocAnnotationRemoveFixer::class)
->call('configure', [
[

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\RectorGenerator;
use Nette\Utils\Strings;
use Rector\Core\ValueObject\SetDirectory;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
@ -22,7 +23,7 @@ final class ConfigResolver
// assume new one is created
$match = Strings::match($set, '#\/(?<name>[a-zA-Z_-]+])#');
if (isset($match['name'])) {
return \Rector\Core\ValueObject\SetDirectory::SET_DIRECTORY . '/' . $match['name'] . '/' . $set;
return SetDirectory::SET_DIRECTORY . '/' . $match['name'] . '/' . $set;
}
return null;
@ -39,7 +40,7 @@ final class ConfigResolver
*/
private function getSetFileInfos(string $set): array
{
$fileSet = sprintf('#^%s\.php)?$#', $set);
$fileSet = sprintf('#^%s\.php$#', $set);
$finder = Finder::create()->files()
->in(SetDirectory::SET_DIRECTORY)
->name($fileSet);

View File

@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase;
use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\Set;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -21,8 +22,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SETS, [
// @todo use constants here, so we don't have to google the strings that can be used here
'coding-style', 'code-quality', 'dead-code', 'nette-utils-code-quality', 'solid', 'privatization', 'naming', 'decomplex',
Set::CODING_STYLE, Set::CODE_QUALITY, Set::DEAD_CODE, Set::NETTE_UTILS_CODE_QUALITY, Set::SOLID, Set::PRIVATIZATION, Set::NAMING, Set::DECOMPLEX,
]);
$parameters->set(Option::PATHS, [

View File

@ -3,6 +3,7 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\Set;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -16,7 +17,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
# is_cache_enabled: true
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::SETS, ['naming']);
$parameters->set(Option::SETS, [Set::NAMING]);
$parameters->set(
Option::PATHS,

View File

@ -6,717 +6,859 @@ namespace Rector\Core\ValueObject;
/**
* This class is generated by "bin/rector dump-set-contants"
DO NOT EDIT MANUALLY
* DO NOT EDIT MANUALLY
*/
final class Set
{
/**
* @var string
* @api
*/
public const ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION = 'action-injection-to-constructor-injection';
/**
* @var string
* @api
*/
public const ARRAY_STR_FUNCTIONS_TO_STATIC_CALL = 'array-str-functions-to-static-call';
/**
* @var string
* @api
*/
public const CAKEPHP_30 = 'cakephp30';
/**
* @var string
* @api
*/
public const CAKEPHP_34 = 'cakephp34';
/**
* @var string
* @api
*/
public const CAKEPHP_35 = 'cakephp35';
/**
* @var string
* @api
*/
public const CAKEPHP_36 = 'cakephp36';
/**
* @var string
* @api
*/
public const CAKEPHP_37 = 'cakephp37';
/**
* @var string
* @api
*/
public const CAKEPHP_38 = 'cakephp38';
/**
* @var string
* @api
*/
public const CAKEPHP_40 = 'cakephp40';
/**
* @var string
* @api
*/
public const CAKEPHP_FLUENT_OPTIONS = 'cakephp-fluent-options';
/**
* @var string
* @api
*/
public const CELEBRITY = 'celebrity';
/**
* @var string
* @api
*/
public const CODEIGNITER_40 = 'codeigniter-40';
/**
* @var string
* @api
*/
public const CODE_QUALITY = 'code-quality';
/**
* @var string
* @api
*/
public const CODING_STYLE = 'coding-style';
/**
* @var string
* @api
*/
public const CONSTRUCTOR_INJECTIN_TO_ACTION_INJECTION = 'constructor-injectin-to-action-injection';
/**
* @var string
* @api
*/
public const CONTRIBUTTE_TO_SYMFONY = 'contributte-to-symfony';
/**
* @var string
* @api
*/
public const DEAD_CLASSES = 'dead-classes';
/**
* @var string
* @api
*/
public const DEAD_CODE = 'dead-code';
/**
* @var string
* @api
*/
public const DECOMPLEX = 'decomplex';
/**
* @var string
* @api
*/
public const DOCTRINE = 'doctrine';
/**
* @var string
* @api
*/
public const DOCTRINE_25 = 'doctrine25';
/**
* @var string
* @api
*/
public const DOCTRINE_BEHAVIORS_20 = 'doctrine-behaviors-20';
/**
* @var string
* @api
*/
public const DOCTRINE_CODE_QUALITY = 'doctrine-code-quality';
/**
* @var string
* @api
*/
public const DOCTRINE_COMMON_20 = 'doctrine-common-20';
/**
* @var string
* @api
*/
public const DOCTRINE_DBAL_210 = 'doctrine-dbal-210';
/**
* @var string
* @api
*/
public const DOCTRINE_DBAL_30 = 'doctrine-dbal-30';
/**
* @var string
* @api
*/
public const DOCTRINE_GEDMO_TO_KNPLABS = 'doctrine-gedmo-to-knplabs';
/**
* @var string
* @api
*/
public const DOCTRINE_ID_TO_UUID_STEP_1 = 'doctrine-id-to-uuid-step-1';
/**
* @var string
* @api
*/
public const DOCTRINE_ID_TO_UUID_STEP_2 = 'doctrine-id-to-uuid-step-2';
/**
* @var string
* @api
*/
public const DOCTRINE_ID_TO_UUID_STEP_3 = 'doctrine-id-to-uuid-step-3';
/**
* @var string
* @api
*/
public const DOCTRINE_ID_TO_UUID_STEP_4 = 'doctrine-id-to-uuid-step-4';
/**
* @var string
* @api
*/
public const DOCTRINE_ID_TO_UUID_STEP_5 = 'doctrine-id-to-uuid-step-5';
/**
* @var string
* @api
*/
public const DOCTRINE_REPOSITORY_AS_SERVICE = 'doctrine-repository-as-service';
/**
* @var string
* @api
*/
public const DOCTRINE_SERVICES = 'doctrine-services';
/**
* @var string
* @api
*/
public const DOWNGRADE = 'downgrade';
/**
* @var string
* @api
*/
public const EARLY_RETURN = 'early-return';
/**
* @var string
* @api
*/
public const EASY_ADMIN_BUNDLE_20 = 'easy-admin-bundle20';
/**
* @var string
* @api
*/
public const ELASTICSEARCH_DSL_50 = 'elasticsearch-dsl50';
/**
* @var string
* @api
*/
public const FRAMEWORK_EXTRA_BUNDLE_40 = 'framework-extra-bundle-40';
/**
* @var string
* @api
*/
public const FRAMEWORK_EXTRA_BUNDLE_50 = 'framework-extra-bundle-50';
/**
* @var string
* @api
*/
public const GMAGICK_TO_IMAGICK = 'gmagick_to_imagick';
/**
* @var string
* @api
*/
public const GUZZLE_50 = 'guzzle50';
/**
* @var string
* @api
*/
public const JMS_DECOUPLE = 'jms-decouple';
/**
* @var string
* @api
*/
public const KDYBY_EVENTS_TO_CONTRIBUTTE_EVENT_DISPATCHER = 'kdyby-events-to-contributte-event-dispatcher';
/**
* @var string
* @api
*/
public const KDYBY_TO_SYMFONY = 'kdyby-to-symfony';
/**
* @var string
* @api
*/
public const KDYBY_TRANSLATOR_TO_CONTRIBUTTE_TRANSLATION = 'kdyby-translator-to-contributte-translation';
/**
* @var string
* @api
*/
public const LARAVEL_50 = 'laravel50';
/**
* @var string
* @api
*/
public const LARAVEL_51 = 'laravel51';
/**
* @var string
* @api
*/
public const LARAVEL_52 = 'laravel52';
/**
* @var string
* @api
*/
public const LARAVEL_53 = 'laravel53';
/**
* @var string
* @api
*/
public const LARAVEL_54 = 'laravel54';
/**
* @var string
* @api
*/
public const LARAVEL_55 = 'laravel55';
/**
* @var string
* @api
*/
public const LARAVEL_56 = 'laravel56';
/**
* @var string
* @api
*/
public const LARAVEL_57 = 'laravel57';
/**
* @var string
* @api
*/
public const LARAVEL_58 = 'laravel58';
/**
* @var string
* @api
*/
public const LARAVEL_60 = 'laravel60';
/**
* @var string
* @api
*/
public const LARAVEL_STATIC_TO_INJECTION = 'laravel-static-to-injection';
/**
* @var string
* @api
*/
public const MOCKISTA_TO_MOCKERY = 'mockista-to-mockery';
/**
* @var string
* @api
*/
public const MONOLOG_20 = 'monolog20';
/**
* @var string
* @api
*/
public const MYSQL_TO_MYSQLI = 'mysql-to-mysqli';
/**
* @var string
* @api
*/
public const NAMING = 'naming';
/**
* @var string
* @api
*/
public const NETTE_30 = 'nette-30';
/**
* @var string
* @api
*/
public const NETTE_APPLICATION_CODE_QUALITY = 'nette-application-code-quality';
/**
* @var string
* @api
*/
public const NETTE_CONTROL_TO_SYMFONY_CONTROLLER = 'nette-control-to-symfony-controller';
/**
* @var string
* @api
*/
public const NETTE_FORMS_TO_SYMFONY = 'nette-forms-to-symfony';
/**
* @var string
* @api
*/
public const NETTE_PARAM_TYPES = 'nette-param-types';
/**
* @var string
* @api
*/
public const NETTE_RETURN_TYPES = 'nette-return-types';
/**
* @var string
* @api
*/
public const NETTE_TESTER_TO_PHPUNIT = 'nette-tester-to-phpunit';
/**
* @var string
* @api
*/
public const NETTE_TO_SYMFONY = 'nette-to-symfony';
/**
* @var string
* @api
*/
public const NETTE_UTILS_CODE_QUALITY = 'nette-utils-code-quality';
/**
* @var string
* @api
*/
public const ORDER = 'order';
/**
* @var string
* @api
*/
public const PERFORMANCE = 'performance';
/**
* @var string
* @api
*/
public const PHALCON_40 = 'phalcon40';
/**
* @var string
* @api
*/
public const PHPEXCEL_TO_PHPSPREADSHEET = 'phpexcel-to-phpspreadsheet';
/**
* @var string
* @api
*/
public const PHPSPEC_30 = 'phpspec30';
/**
* @var string
* @api
*/
public const PHPSPEC_40 = 'phpspec40';
/**
* @var string
* @api
*/
public const PHPSPEC_TO_PHPUNIT = 'phpspec-to-phpunit';
/**
* @var string
* @api
*/
public const PHPSTAN = 'phpstan';
/**
* @var string
* @api
*/
public const PHPUNIT80_DMS = 'phpunit80-dms';
/**
* @var string
* @api
*/
public const PHPUNIT_40 = 'phpunit40';
/**
* @var string
* @api
*/
public const PHPUNIT_50 = 'phpunit50';
/**
* @var string
* @api
*/
public const PHPUNIT_60 = 'phpunit60';
/**
* @var string
* @api
*/
public const PHPUNIT_70 = 'phpunit70';
/**
* @var string
* @api
*/
public const PHPUNIT_75 = 'phpunit75';
/**
* @var string
* @api
*/
public const PHPUNIT_80 = 'phpunit80';
/**
* @var string
* @api
*/
public const PHPUNIT_90 = 'phpunit90';
/**
* @var string
* @api
*/
public const PHPUNIT_91 = 'phpunit91';
/**
* @var string
* @api
*/
public const PHPUNIT_CODE_QUALITY = 'phpunit-code-quality';
/**
* @var string
* @api
*/
public const PHPUNIT_EXCEPTION = 'phpunit-exception';
/**
* @var string
* @api
*/
public const PHPUNIT_INJECTOR = 'phpunit-injector';
/**
* @var string
* @api
*/
public const PHPUNIT_MOCK = 'phpunit-mock';
/**
* @var string
* @api
*/
public const PHPUNIT_SPECIFIC_METHOD = 'phpunit-specific-method';
/**
* @var string
* @api
*/
public const PHPUNIT_YIELD_DATA_PROVIDER = 'phpunit-yield-data-provider';
/**
* @var string
* @api
*/
public const PHP_52 = 'php52';
/**
* @var string
* @api
*/
public const PHP_53 = 'php53';
/**
* @var string
* @api
*/
public const PHP_54 = 'php54';
/**
* @var string
* @api
*/
public const PHP_55 = 'php55';
/**
* @var string
* @api
*/
public const PHP_56 = 'php56';
/**
* @var string
* @api
*/
public const PHP_70 = 'php70';
/**
* @var string
* @api
*/
public const PHP_71 = 'php71';
/**
* @var string
* @api
*/
public const PHP_72 = 'php72';
/**
* @var string
* @api
*/
public const PHP_73 = 'php73';
/**
* @var string
* @api
*/
public const PHP_74 = 'php74';
/**
* @var string
* @api
*/
public const PHP_80 = 'php80';
/**
* @var string
* @api
*/
public const PHP_CODE_SNIFFER_30 = 'php-code-sniffer30';
/**
* @var string
* @api
*/
public const PHP_DI_DECOUPLE = 'php-di-decouple';
/**
* @var string
* @api
*/
public const PRIVATIZATION = 'privatization';
/**
* @var string
* @api
*/
public const PSR_4 = 'psr-4';
/**
* @var string
* @api
*/
public const SAFE_07 = 'safe07';
/**
* @var string
* @api
*/
public const SHOPWARE_55 = 'shopware55';
/**
* @var string
* @api
*/
public const SHOPWARE_56 = 'shopware56';
/**
* @var string
* @api
*/
public const SOLID = 'solid';
/**
* @var string
* @api
*/
public const SWIFTMAILER_60 = 'swiftmailer60';
/**
* @var string
* @api
*/
public const SYLIUS_10 = 'sylius10';
/**
* @var string
* @api
*/
public const SYLIUS_102 = 'sylius102';
/**
* @var string
* @api
*/
public const SYLIUS_109 = 'sylius109';
/**
* @var string
* @api
*/
public const SYMFONY50_TYPES = 'symfony50-types';
/**
* @var string
* @api
*/
public const SYMFONY_26 = 'symfony26';
/**
* @var string
* @api
*/
public const SYMFONY_28 = 'symfony28';
/**
* @var string
* @api
*/
public const SYMFONY_30 = 'symfony30';
/**
* @var string
* @api
*/
public const SYMFONY_31 = 'symfony31';
/**
* @var string
* @api
*/
public const SYMFONY_32 = 'symfony32';
/**
* @var string
* @api
*/
public const SYMFONY_33 = 'symfony33';
/**
* @var string
* @api
*/
public const SYMFONY_34 = 'symfony34';
/**
* @var string
* @api
*/
public const SYMFONY_40 = 'symfony40';
/**
* @var string
* @api
*/
public const SYMFONY_41 = 'symfony41';
/**
* @var string
* @api
*/
public const SYMFONY_42 = 'symfony42';
/**
* @var string
* @api
*/
public const SYMFONY_43 = 'symfony43';
/**
* @var string
* @api
*/
public const SYMFONY_44 = 'symfony44';
/**
* @var string
* @api
*/
public const SYMFONY_50 = 'symfony50';
/**
* @var string
* @api
*/
public const SYMFONY_CODE_QUALITY = 'symfony-code-quality';
/**
* @var string
* @api
*/
public const SYMFONY_CONSTRUCTOR_INJECTION = 'symfony-constructor-injection';
/**
* @var string
* @api
*/
public const SYMFONY_PHPUNIT = 'symfony-phpunit';
/**
* @var string
* @api
*/
public const TWIG_112 = 'twig112';
/**
* @var string
* @api
*/
public const TWIG_127 = 'twig127';
/**
* @var string
* @api
*/
public const TWIG_134 = 'twig134';
/**
* @var string
* @api
*/
public const TWIG_140 = 'twig140';
/**
* @var string
* @api
*/
public const TWIG_20 = 'twig20';
/**
* @var string
* @api
*/
public const TWIG_240 = 'twig240';
/**
* @var string
* @api
*/
public const TWIG_UNDERSCORE_TO_NAMESPACE = 'twig-underscore-to-namespace';
/**
* @var string
* @api
*/
public const TYPE_DECLARATION = 'type-declaration';
/**
* @var string
* @api
*/
public const UNWRAP_COMPAT = 'unwrap-compat';
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Rector\Utils\DocumentationGenerator\Command;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
@ -113,6 +114,10 @@ final class DumpSetConstantsCommand extends AbstractCommand
private function printFileStmtsToSetFile(array $fileStmts): void
{
$contents = $this->betterStandardPrinter->prettyPrintFile($fileStmts);
// remove pre-trailing spaces from Nop()
$contents = Strings::replace($contents, '#^\s+$#ms');
$this->smartFileSystem->dumpFile(self::SET_FILE_PATH, $contents);
}

View File

@ -7,7 +7,9 @@ namespace Rector\Utils\DocumentationGenerator\NodeFactory;
use PhpParser\Comment\Doc;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Nop;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class SetClassNodeFactory
{
@ -34,6 +36,11 @@ final class SetClassNodeFactory
$lastKey = array_key_last($constantNamesToSetNames);
foreach ($constantNamesToSetNames as $constantName => $setName) {
$classConst = $this->nodeFactory->createPublicClassConst($constantName, $setName);
/** @var PhpDocInfo $phpDocInfo */
$phpDocInfo = $classConst->getAttribute(AttributeKey::PHP_DOC_INFO);
$phpDocInfo->addBareTag('api');
$class->stmts[] = $classConst;
// space between constants
@ -48,7 +55,7 @@ final class SetClassNodeFactory
private function decorateClassWithDoc(Class_ $class): void
{
$text = sprintf(
'/**%s * This class is generated by "bin/rector dump-set-contants"%sDO NOT EDIT MANUALLY%s */',
'/**%s * This class is generated by "bin/rector dump-set-constants"%s * DO NOT EDIT MANUALLY%s */',
PHP_EOL,
PHP_EOL,
PHP_EOL