Replies: 2 comments 2 replies
|
You can use this rule and build a set from it: I'm thinking of similar set... there is a mysql-to-mysqli set, that is changing names and argument order too: If there is a community interest already, we can make it part of Rector 👍 |
0 replies
|
I was able to rewrite everything (my project used) using: $mapping = [
'keyExists' => 'keyExists',
'isInstanceOf' => 'isInstanceOf',
'allIsInstanceOf' => 'allIsInstanceOf',
'isObject' => 'object',
'notEmpty' => 'notEmpty',
'regex' => 'regex',
'email' => 'email',
'count' => 'count',
'notSame' => 'notSame',
'same' => 'same',
'false' => 'false',
'true' => 'true',
'inArray' => 'oneOf',
'startsWith' => 'startsWith',
'eq' => 'eq',
'keyIsset' => 'keyExists',
'minLength' => 'minLength',
'maxLength' => 'maxLength',
'min' => 'greaterThanEq',
'greaterOrEqualThan' => 'greaterThanEq',
'choice' => 'oneOf',
'contains' => 'contains',
'numeric' => 'numeric',
'allNumeric' => 'allNumeric',
'keyNotExists' => 'keyNotExists',
'notBlank' => 'notEmpty',
'notNull' => 'notNull',
];
$mapping = array_map(function (string $from, string $to) {
return new RenameStaticMethod(
'Assert\Assertion',
$from,
'Webmozart\Assert\Assert',
$to
);
}, array_keys($mapping), $mapping);
$services->set(RenameStaticMethodRector::class)
->call('configure',
[[
RenameStaticMethodRector::OLD_TO_NEW_METHODS_BY_CLASSES => ValueObjectInliner::inline($mapping)
]]);❤️ Now there is 1 job left, and that's to automatically fix PHPDocs use Assert\AssertionFailedException;
/**
* @throws AssertionFailedException
*/
try {
Assert::startsWith($string, 'https://');
} catch (AssertionFailedException $exception) {
throw new InvalidArgumentException('Wrong string');
}Are there rectors available to do that? Basically a generic rector that replaces FQCN > new FQCN. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm thinking of creating a Rector to convert
beberlei/asserttowebmozarts/assert.I would like some advice on the best and simplest way to achieve this.
Do you have some examples of similar transitions? I think both libraries are very similar already, method names and argument ordering are big differences.
Also found somebody on Twitter that wanted to have this: https://twitter.com/norbert_tech/status/1255426199318396929
All reactions