Automatický převod Nette konstant např Form::PATTERN na Form::Patern

dms
Člen | 93
+
+1
-

Máme x projektů, které průběžně aktualizujeme a řeším automatickou změnu nette konstant, která nastala a staré konstanty jsou označeny jako deprecated. Má to nějaké easy řešení např přes rector pravidlo? Řešil na to někdo automatizaci nebo to přepisujete ručně replacem? ve větším množství projektů to zabírá dost času a je to hlavně opruz práce.

Pavel Kravčík
Člen | 1193
+
-1
-

Pravidlo do coding standardu. Buď do fixu, když je komplikované tak ruční oprava (vynucená).

Marek Bartoš
Nette Blogger | 1244
+
+1
-

Na tohle se používá rector, konkrétně to bude pravidlo RenameClassConstFetchRector

David Grudl
Nette Core | 8205
+
+2
-

Přejmenovával jsem si to jednorázovým nástrojem, ale kdyby chtěl někdo udělat něco obecného, zde jsou data:

Změna konstanty

'Nette\Application\UI\Presenter::ACTION_KEY' => 'ActionKey',
'Nette\Application\UI\Presenter::DEFAULT_ACTION' => 'DefaultAction',
'Nette\Application\UI\Presenter::FLASH_KEY' => 'FlashKey',
'Nette\Application\UI\Presenter::INVALID_LINK_EXCEPTION' => 'InvalidLinkException',
'Nette\Application\UI\Presenter::INVALID_LINK_SILENT' => 'InvalidLinkSilent',
'Nette\Application\UI\Presenter::INVALID_LINK_TEXTUAL' => 'InvalidLinkTextual',
'Nette\Application\UI\Presenter::INVALID_LINK_WARNING' => 'InvalidLinkWarning',
'Nette\Application\UI\Presenter::PRESENTER_KEY' => 'PresenterKey',
'Nette\Application\UI\Presenter::SIGNAL_KEY' => 'SignalKey',
'Nette\Bootstrap\Configurator::COOKIE_SECRET' => 'CookieSecret',
'Nette\Caching\Cache::ALL' => 'All',
'Nette\Caching\Cache::CALLBACKS' => 'Callbacks',
'Nette\Caching\Cache::CONSTS' => 'Constants',
'Nette\Caching\Cache::EXPIRATION' => 'Expire',
'Nette\Caching\Cache::EXPIRE' => 'Expire',
'Nette\Caching\Cache::FILES' => 'Files',
'Nette\Caching\Cache::ITEMS' => 'Items',
'Nette\Caching\Cache::NAMESPACE_SEPARATOR' => 'NamespaceSeparator',
'Nette\Caching\Cache::NAMESPACES' => 'Namespaces',
'Nette\Caching\Cache::PRIORITY' => 'Priority',
'Nette\Caching\Cache::SLIDING' => 'Sliding',
'Nette\Caching\Cache::TAGS' => 'Tags',
'Nette\CommandLine\Parser::ARGUMENT' => 'Argument',
'Nette\CommandLine\Parser::ENUM' => 'Enum',
'Nette\CommandLine\Parser::OPTIONAL' => 'Optional',
'Nette\CommandLine\Parser::REALPATH' => 'RealPath',
'Nette\CommandLine\Parser::REPEATABLE' => 'Repeatable',
'Nette\CommandLine\Parser::VALUE' => 'Default',
'Nette\ComponentModel\IComponent::NAME_SEPARATOR' => 'NameSeparator',
'Nette\DI\ContainerBuilder::THIS_CONTAINER' => 'ThisContainer',
'Nette\DI\ContainerBuilder::THIS_SERVICE' => 'ThisService',
'Nette\DI\Definitions\Reference::SELF' => 'Self',
'Nette\DI\Extensions\InjectExtension::TAG_INJECT' => 'TagInject',
'Nette\Forms\Controls\CsrfProtection::PROTECTION' => 'Protection',
'Nette\Forms\Controls\SelectBox::VALID' => 'Valid',
'Nette\Forms\Controls\UploadControl::VALID' => 'Valid',
'Nette\Forms\Form::BLANK' => 'Blank',
'Nette\Forms\Form::COUNT' => 'Count',
'Nette\Forms\Form::DATA_FILE' => 'DataFile',
'Nette\Forms\Form::DATA_KEYS' => 'DataKeys',
'Nette\Forms\Form::DATA_LINE' => 'DataLine',
'Nette\Forms\Form::DATA_TEXT' => 'DataText',
'Nette\Forms\Form::EMAIL' => 'Email',
'Nette\Forms\Form::EQUAL' => 'Equal',
'Nette\Forms\Form::FILLED' => 'Filled',
'Nette\Forms\Form::FLOAT' => 'Float',
'Nette\Forms\Form::GET' => 'Get',
'Nette\Forms\Form::IMAGE' => 'Image',
'Nette\Forms\Form::INTEGER' => 'Integer',
'Nette\Forms\Form::IS_IN' => 'IsIn',
'Nette\Forms\Form::IS_NOT_IN' => 'IsNotIn',
'Nette\Forms\Form::LENGTH' => 'Length',
'Nette\Forms\Form::MAX' => 'Max',
'Nette\Forms\Form::MAX_FILE_SIZE' => 'MaxFileSize',
'Nette\Forms\Form::MAX_LENGTH' => 'MaxLength',
'Nette\Forms\Form::MAX_POST_SIZE' => 'MaxPostSize',
'Nette\Forms\Form::MIME_TYPE' => 'MimeType',
'Nette\Forms\Form::MIN' => 'Min',
'Nette\Forms\Form::MIN_LENGTH' => 'MinLength',
'Nette\Forms\Form::NOT_EQUAL' => 'NotEqual',
'Nette\Forms\Form::NUMERIC' => 'Numeric',
'Nette\Forms\Form::PATTERN' => 'Pattern',
'Nette\Forms\Form::PATTERN_ICASE' => 'PatternInsensitive',
'Nette\Forms\Form::POST' => 'Post',
'Nette\Forms\Form::PROTECTOR_ID' => 'ProtectorId',
'Nette\Forms\Form::RANGE' => 'Range',
'Nette\Forms\Form::REQUIRED' => 'Required',
'Nette\Forms\Form::SUBMITTED' => 'Submitted',
'Nette\Forms\Form::TRACKER_ID' => 'TrackerId',
'Nette\Forms\Form::VALID' => 'Valid',
'Nette\Http\IRequest::DELETE' => 'Delete',
'Nette\Http\IRequest::GET' => 'Get',
'Nette\Http\IRequest::HEAD' => 'Head',
'Nette\Http\IRequest::OPTIONS' => 'Options',
'Nette\Http\IRequest::PATCH' => 'Patch',
'Nette\Http\IRequest::POST' => 'Post',
'Nette\Http\IRequest::PUT' => 'Put',
'Nette\Http\IResponse::REASON_PHRASES' => 'ReasonPhrases',
'Nette\Http\IResponse::S100_CONTINUE' => 'S100_Continue',
'Nette\Http\IResponse::S101_SWITCHING_PROTOCOLS' => 'S101_SwitchingProtocols',
'Nette\Http\IResponse::S102_PROCESSING' => 'S102_Processing',
'Nette\Http\IResponse::S201_CREATED' => 'S201_Created',
'Nette\Http\IResponse::S202_ACCEPTED' => 'S202_Accepted',
'Nette\Http\IResponse::S203_NON_AUTHORITATIVE_INFORMATION' => 'S203_NonAuthoritativeInformation',
'Nette\Http\IResponse::S204_NO_CONTENT' => 'S204_NoContent',
'Nette\Http\IResponse::S205_RESET_CONTENT' => 'S205_ResetContent',
'Nette\Http\IResponse::S206_PARTIAL_CONTENT' => 'S206_PartialContent',
'Nette\Http\IResponse::S207_MULTI_STATUS' => 'S207_MultiStatus',
'Nette\Http\IResponse::S208_ALREADY_REPORTED' => 'S208_AlreadyReported',
'Nette\Http\IResponse::S226_IM_USED' => 'S226_ImUsed',
'Nette\Http\IResponse::S300_MULTIPLE_CHOICES' => 'S300_MultipleChoices',
'Nette\Http\IResponse::S301_MOVED_PERMANENTLY' => 'S301_MovedPermanently',
'Nette\Http\IResponse::S302_FOUND' => 'S302_Found',
'Nette\Http\IResponse::S303_POST_GET' => 'S303_PostGet',
'Nette\Http\IResponse::S303_SEE_OTHER' => 'S303_PostGet',
'Nette\Http\IResponse::S304_NOT_MODIFIED' => 'S304_NotModified',
'Nette\Http\IResponse::S305_USE_PROXY' => 'S305_UseProxy',
'Nette\Http\IResponse::S307_TEMPORARY_REDIRECT' => 'S307_TemporaryRedirect',
'Nette\Http\IResponse::S308_PERMANENT_REDIRECT' => 'S308_PermanentRedirect',
'Nette\Http\IResponse::S400_BAD_REQUEST' => 'S400_BadRequest',
'Nette\Http\IResponse::S401_UNAUTHORIZED' => 'S401_Unauthorized',
'Nette\Http\IResponse::S402_PAYMENT_REQUIRED' => 'S402_PaymentRequired',
'Nette\Http\IResponse::S403_FORBIDDEN' => 'S403_Forbidden',
'Nette\Http\IResponse::S404_NOT_FOUND' => 'S404_NotFound',
'Nette\Http\IResponse::S405_METHOD_NOT_ALLOWED' => 'S405_MethodNotAllowed',
'Nette\Http\IResponse::S406_NOT_ACCEPTABLE' => 'S406_NotAcceptable',
'Nette\Http\IResponse::S407_PROXY_AUTHENTICATION_REQUIRED' => 'S407_ProxyAuthenticationRequired',
'Nette\Http\IResponse::S408_REQUEST_TIMEOUT' => 'S408_RequestTimeout',
'Nette\Http\IResponse::S409_CONFLICT' => 'S409_Conflict',
'Nette\Http\IResponse::S410_GONE' => 'S410_Gone',
'Nette\Http\IResponse::S411_LENGTH_REQUIRED' => 'S411_LengthRequired',
'Nette\Http\IResponse::S412_PRECONDITION_FAILED' => 'S412_PreconditionFailed',
'Nette\Http\IResponse::S413_REQUEST_ENTITY_TOO_LARGE' => 'S413_RequestEntityTooLarge',
'Nette\Http\IResponse::S414_REQUEST_URI_TOO_LONG' => 'S414_RequestUriTooLong',
'Nette\Http\IResponse::S415_UNSUPPORTED_MEDIA_TYPE' => 'S415_UnsupportedMediaType',
'Nette\Http\IResponse::S416_REQUESTED_RANGE_NOT_SATISFIABLE' => 'S416_RequestedRangeNotSatisfiable',
'Nette\Http\IResponse::S417_EXPECTATION_FAILED' => 'S417_ExpectationFailed',
'Nette\Http\IResponse::S421_MISDIRECTED_REQUEST' => 'S421_MisdirectedRequest',
'Nette\Http\IResponse::S422_UNPROCESSABLE_ENTITY' => 'S422_UnprocessableEntity',
'Nette\Http\IResponse::S423_LOCKED' => 'S423_Locked',
'Nette\Http\IResponse::S424_FAILED_DEPENDENCY' => 'S424_FailedDependency',
'Nette\Http\IResponse::S426_UPGRADE_REQUIRED' => 'S426_UpgradeRequired',
'Nette\Http\IResponse::S428_PRECONDITION_REQUIRED' => 'S428_PreconditionRequired',
'Nette\Http\IResponse::S429_TOO_MANY_REQUESTS' => 'S429_TooManyRequests',
'Nette\Http\IResponse::S431_REQUEST_HEADER_FIELDS_TOO_LARGE' => 'S431_RequestHeaderFieldsTooLarge',
'Nette\Http\IResponse::S451_UNAVAILABLE_FOR_LEGAL_REASONS' => 'S451_UnavailableForLegalReasons',
'Nette\Http\IResponse::S500_INTERNAL_SERVER_ERROR' => 'S500_InternalServerError',
'Nette\Http\IResponse::S501_NOT_IMPLEMENTED' => 'S501_NotImplemented',
'Nette\Http\IResponse::S502_BAD_GATEWAY' => 'S502_BadGateway',
'Nette\Http\IResponse::S503_SERVICE_UNAVAILABLE' => 'S503_ServiceUnavailable',
'Nette\Http\IResponse::S504_GATEWAY_TIMEOUT' => 'S504_GatewayTimeout',
'Nette\Http\IResponse::S505_HTTP_VERSION_NOT_SUPPORTED' => 'S505_HttpVersionNotSupported',
'Nette\Http\IResponse::S506_VARIANT_ALSO_NEGOTIATES' => 'S506_VariantAlsoNegotiates',
'Nette\Http\IResponse::S507_INSUFFICIENT_STORAGE' => 'S507_InsufficientStorage',
'Nette\Http\IResponse::S508_LOOP_DETECTED' => 'S508_LoopDetected',
'Nette\Http\IResponse::S510_NOT_EXTENDED' => 'S510_NotExtended',
'Nette\Http\IResponse::S511_NETWORK_AUTHENTICATION_REQUIRED' => 'S511_NetworkAuthenticationRequired',
'Nette\Http\IResponse::SAME_SITE_LAX' => 'SameSiteLax',
'Nette\Http\IResponse::SAME_SITE_NONE' => 'SameSiteNone',
'Nette\Http\IResponse::SAME_SITE_STRICT' => 'SameSiteStrict',
'Nette\Mail\Message::HIGH' => 'High',
'Nette\Mail\Message::LOW' => 'Low',
'Nette\Mail\Message::NORMAL' => 'Normal',
'Nette\Neon\Neon::CHAIN' => 'Chain',
'Nette\PhpGenerator\ClassType::VISIBILITY_PRIVATE' => 'VisibilityPrivate',
'Nette\PhpGenerator\ClassType::VISIBILITY_PROTECTED' => 'VisibilityProtected',
'Nette\PhpGenerator\ClassType::VISIBILITY_PUBLIC' => 'VisibilityPublic',
'Nette\PhpGenerator\PhpNamespace::NAME_CONSTANT' => 'NameConstant',
'Nette\PhpGenerator\PhpNamespace::NAME_FUNCTION' => 'NameFunction',
'Nette\PhpGenerator\PhpNamespace::NAME_NORMAL' => 'NameNormal',
'Nette\PhpGenerator\Type::ARRAY' => 'Array',
'Nette\PhpGenerator\Type::BOOL' => 'Bool',
'Nette\PhpGenerator\Type::CALLABLE' => 'Callable',
'Nette\PhpGenerator\Type::FALSE' => 'False',
'Nette\PhpGenerator\Type::FLOAT' => 'Float',
'Nette\PhpGenerator\Type::INT' => 'Int',
'Nette\PhpGenerator\Type::ITERABLE' => 'Iterable',
'Nette\PhpGenerator\Type::MIXED' => 'Mixed',
'Nette\PhpGenerator\Type::NEVER' => 'Never',
'Nette\PhpGenerator\Type::NULL' => 'Null',
'Nette\PhpGenerator\Type::OBJECT' => 'Object',
'Nette\PhpGenerator\Type::PARENT' => 'Parent',
'Nette\PhpGenerator\Type::SELF' => 'Self',
'Nette\PhpGenerator\Type::STATIC' => 'Static',
'Nette\PhpGenerator\Type::STRING' => 'String',
'Nette\PhpGenerator\Type::VOID' => 'Void',
'Nette\Routing\Route::FILTER_IN' => 'FilterIn',
'Nette\Routing\Route::FILTER_OUT' => 'FilterOut',
'Nette\Routing\Route::FILTER_STRICT' => 'FilterStrict',
'Nette\Routing\Route::FILTER_TABLE' => 'FilterTable',
'Nette\Routing\Route::PATTERN' => 'Pattern',
'Nette\Routing\Route::VALUE' => 'Value',
'Nette\Security\Authenticator::FAILURE' => 'Failure',
'Nette\Security\Authenticator::IDENTITY_NOT_FOUND' => 'IdentityNotFound',
'Nette\Security\Authenticator::INVALID_CREDENTIAL' => 'InvalidCredential',
'Nette\Security\Authenticator::NOT_APPROVED' => 'NotApproved',
'Nette\Security\Authorizator::ALL' => 'All',
'Nette\Security\Authorizator::ALLOW' => 'Allow',
'Nette\Security\Authorizator::DENY' => 'Deny',
'Nette\Security\User::INACTIVITY' => 'LogoutInactivity',
'Nette\Security\User::LOGOUT_INACTIVITY' => 'LogoutInactivity',
'Nette\Security\User::LOGOUT_MANUAL' => 'LogoutManual',
'Nette\Security\User::MANUAL' => 'LogoutManual',
'Nette\Schema\Message::DEPRECATED' => 'Deprecated',
'Nette\Schema\Message::FAILED_ASSERTION' => 'FailedAssertion',
'Nette\Schema\Message::LENGTH_OUT_OF_RANGE' => 'LengthOutOfRange',
'Nette\Schema\Message::MISSING_ITEM' => 'MissingItem',
'Nette\Schema\Message::PATTERN_MISMATCH' => 'PatternMismatch',
'Nette\Schema\Message::TYPE_MISMATCH' => 'TypeMismatch',
'Nette\Schema\Message::UNEXPECTED_ITEM' => 'UnexpectedItem',
'Nette\Schema\Message::VALUE_OUT_OF_RANGE' => 'ValueOutOfRange',
'Nette\Utils\Image::EMPTY_GIF' => 'EmptyGIF',
'Nette\Utils\Image::EXACT' => 'Cover',
'Nette\Utils\Image::FILL' => 'OrBigger',
'Nette\Utils\Image::FIT' => 'OrSmaller',
'Nette\Utils\Image::SHRINK_ONLY' => 'ShrinkOnly',
'Nette\Utils\Image::STRETCH' => 'Stretch',
'Tester\Environment::COLORS' => 'VariableColors',
'Tester\Environment::COVERAGE' => 'VariableCoverage',
'Tester\Environment::COVERAGE_ENGINE' => 'VariableCoverageEngine',
'Tester\Environment::RUNNER' => 'VariableRunner',
'Tester\Environment::THREAD' => 'VariableThread',
'Tracy\Debugger::COOKIE_SECRET' => 'CookieSecret',
'Tracy\Debugger::DETECT' => 'Detect',
'Tracy\Debugger::DEVELOPMENT' => 'Development',
'Tracy\Debugger::PRODUCTION' => 'Production',
'Tracy\Debugger::VERSION' => 'Version',

Změna třídy a konstanty

'Latte\Engine::CONTENT_CSS' => 'Latte\ContentType::Css',
'Latte\Engine::CONTENT_HTML' => 'Latte\ContentType::Html',
'Latte\Engine::CONTENT_ICAL' => 'Latte\ContentType::ICal',
'Latte\Engine::CONTENT_JS' => 'Latte\ContentType::JavaScript',
'Latte\Engine::CONTENT_TEXT' => 'Latte\ContentType::Text',
'Latte\Engine::CONTENT_XML' => 'Latte\ContentType::Xml',
'Nette\Security\UserStorage::LOGOUT_INACTIVITY' => 'Nette\Security\User::LogoutInactivity',
'Nette\Security\UserStorage::LOGOUT_MANUAL' => 'Nette\Security\User::LogoutManual',
'Nette\Utils\Image::AVIF' => 'Nette\Utils\ImageType::AVIF',
'Nette\Utils\Image::BMP' => 'Nette\Utils\ImageType::BMP',
'Nette\Utils\Image::GIF' => 'Nette\Utils\ImageType::GIF',
'Nette\Utils\Image::JPEG' => 'Nette\Utils\ImageType::JPEG',
'Nette\Utils\Image::PNG' => 'Nette\Utils\ImageType::PNG',
'Nette\Utils\Image::WEBP' => 'Nette\Utils\ImageType::WEBP',
Marek Bartoš
Nette Blogger | 1244
+
0
-

Ideálně asi doplnit sem
https://github.com/…rector-nette

Pavel Kravčík
Člen | 1193
+
0
-

Marek Bartoš napsal(a):

Ideálně asi doplnit sem
https://github.com/…rector-nette

To už bohužel s novým Rektorem nejde, ale kdyby to někomu pomohlo stačí něco simple a použít ten Davidovo seznam:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\ValueObject\RenameClassConstFetch;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/app'
    ])
	->withConfiguredRule(RenameClassConstFetchRector::class, [
		new RenameClassConstFetch('Nette\Forms\Form', 'FILLED', 'Filled')
		//...
	]);

Editoval Pavel Kravčík (22. 2. 14:35)