rectorphp / rector Goto Github PK
View Code? Open in Web Editor NEWInstant Upgrades and Automated Refactoring of any PHP 5.3+ code
Home Page: https://getrector.com
License: MIT License
Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Home Page: https://getrector.com
License: MIT License
Should cover
E.g Symfony 3.0
class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->locale;
// update locale
$this->locale = $locale;
}
}
class CustomTranslator extends Translator
{
public function fooMethod()
{
// get locale
$locale = $this->getLocale();
// update locale
$this->setLocale($locale);
}
}
To reflect changes like:
"If you write your own extensions, you should know that these namespaces was renamed: Nette\Config → Nette\DI and Nette\Utils\PhpGenerator → Nette\PhpGenerator."
Source: https://doc.nette.org/en/2.4/migration-2-1#toc-dependency-injection-di-2
I run rector as standalone project. If I run it on my project like this:
php w:\git\rector\bin\rector process src --level symfony40
I get following error
...
- src\Admin\Media\Image\EntityType.php
...and 356 more.
PHP Notice: Undefined property: PhpParser\Node\Stmt\Trait_::$extends in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 48
Notice: Undefined property: PhpParser\Node\Stmt\Trait_::$extends in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 48
PHP Notice: Undefined property: PhpParser\Node\Stmt\Trait_::$implements in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 58
Notice: Undefined property: PhpParser\Node\Stmt\Trait_::$implements in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 58
PHP Notice: Undefined property: PhpParser\Node\Stmt\Interface_::$implements in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 58
Notice: Undefined property: PhpParser\Node\Stmt\Interface_::$implements in W:\git\rector\src\NodeAnalyzer\ClassAnalyzer.php on line 58
[Rector\BetterReflection\Reflector\Exception\IdentifierNotFound]
Rector\BetterReflection\Reflection\ReflectionClass "XY\AppBundle\Sentry\SentryObject" could not be found in the located source
For @shopsys ❤️
Ref: https://github.com/symfony/symfony/blob/master/UPGRADE-3.3.md
FrameworkBundle classes https://github.com/symfony/symfony/blob/master/UPGRADE-3.3.md#frameworkbundle
The console.exception event and the related ConsoleExceptionEvent class have been deprecated in favor of the console.error event and the ConsoleErrorEvent class. The deprecated event and class will be removed in 4.0.
The ContextErrorException class is deprecated. \ErrorException will be used instead in 4.0.
For use cases like #8
Hi,
I have trouble with run Rector. After creating rector as project (via #46) then I run
rector/bin/rector process /path/to/my-files
Iteration from files was correct (I dumped file names) but it did nothing. Where is the problem, maybe it is in rewrited command?
Hi,
is it on packagist already?
It looks really great, I want test it :)
[InvalidArgumentException]
Could not find package rector/rector at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
I get project with full of problems in codebase. For example how are created dependencies:
protected function createComponent($name)
{
switch ($name)
{
// models
case 'catalog': $this->addComponent(Environment::getService('CatalogModel'), $name); return;
case 'library': $this->addComponent(Environment::getService('LibraryModel'), $name); return;
case 'page': $this->addComponent(Environment::getService('PageModel'), $name); return;
case 'seo': $this->addComponent(Environment::getService('SeoModel'), $name); return;
case 'shop': $this->addComponent(Environment::getService('ShopModel'), $name); return;
case 'user': $this->addComponent(Environment::getService('UserModel'), $name); return;
default:
return parent::createComponent($name);
}
}
and using of dependency:
$this['shop']->getShopSubcategories(..);
Any idea how automaticaly repair this? :-))
E.g. Symfony 3.0
The __toString()
method of the \Symfony\Component\Config\ConfigCache
class was removed in favor of the new getPath()
method.
E.g. Nette\InjectPropertyRector
=> Nette\DI\InjectPropertyRector
E.g.
class MyControl extends Control
{
}
$types = $controlNode->getAttribute(Attribute::TYPES);
dump($types); // ['MyControl', 'Control']
- $this->assertTrue(is_readable($readmeFile), sprintf('Cannot read "%s".', $readmeFile));
+ $this->assertIsReadable($readmeFile, sprintf('Cannot read "%s".', $readmeFile));
$this->setExpectedExceptionRegExp(
- \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class,
+ $this->expectException(InvalidConfigurationException::class);
+ $this->expectExceptionMessageRegExp(
'#^The config file: ".+[\/\\\]Fixtures[\/\\\]ConfigurationResolverConfigFile[\/\\\]case_5[\/\\\]\.php_cs\.dist" does not return a "PhpCsFixer\\\ConfigInterface" instance\. Got: "string"\.$#'
);
After this gets fixed deprecated-packages/symplify#265
See https://github.com/umpirsky/Symfony-Upgrade-Fixer#fixers-available
symfony30.yml
Done | Name | Description |
---|---|---|
👍 | form_configure_options | The method AbstractType::setDefaultOptions(OptionsResolverInterface $resolver) have been renamed to AbstractType::configureOptions(OptionsResolver $resolver). |
👍 | form_events | The events PRE_BIND, BIND and POST_BIND were renamed to PRE_SUBMIT, SUBMIT and POST_SUBMIT. |
👍 | form_getname_to_getblockprefix | The method FormTypeInterface::getName() was deprecated, you should now implement FormTypeInterface::getBlockPrefix() instead. |
👍 | form_option_names | Options precision and virtual was renamed to scale and inherit_data. |
👍 | form_parent_type | Returning type instances from FormTypeInterface::getParent() is deprecated, return the fully-qualified class name of the parent type class instead. |
👍 | form_type_names | Instead of referencing types by name, you should reference them by their fully-qualified class name (FQCN) instead. |
👍 | get_request | The getRequest method of the base controller class was removed, request object is injected in the action method instead. |
👍 | inherit_data_aware_iterator | The class VirtualFormAwareIterator was renamed to InheritDataAwareIterator. |
👍 | progress_bar | ProgressHelper has been removed in favor of ProgressBar. |
👍 | property_access | Renamed PropertyAccess::getPropertyAccessor to PropertyAccess::createPropertyAccessor. |
All migration guides in Docs:
"In PhpGenerator methods setDocuments(), getDocuments() and addDocument() was replaced by setComment(), getComment() and addComment()" - Closed by #12
"Negative validation rules. An alternative for the ~Form::FILLED is Form::BLANK, or ~Form::EQUAL can be replaced with Form::NOT_EQUAL"
"Nette\Utils\Html::add() is replaced with addHtml() and addText()" - Closed by #8
Nette 2.1?
Faster to bootstrap:
# symfony33.yml
rectors:
ClassReplacer:
OldClass: NewClass
It would also make change more transparent and easy to scale - adding new class is now easy.
It's not worth writing custom class and tests, since it only uses AbstractClassReplacerRector
over and over again.
What do you think @grogy?
private function getThis()
{
}
// this one should be above, because reading code from top to bottom makes is easier to understand
private function getThat()
{
return $this->getThis();
}
to phpunit60.yml
$this->template->registerHelper('texy', callback($texy, 'process'));
# todo
# todo
For framework related changes that are not strictly connected with framework versions' BC breaks
Message in the code => propert rector operation
With setInject()
to setTag()
Nette\DI\Definition example
See:
Yes, when there is addRule(), there must be setRequired().
The mainstream use case:
$form->addRule(...);
$form->setRequired(true);
->addRule(...);
Use AbstractChangeMethodNameRector
Maybe general underscore to slash rector, like php code Sniffer sniff class
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setScope(ContainerBuilder::SCOPE_PROTOTYPE)
;
last call into
->setShared(false)
Ref: umpirsky/Symfony-Upgrade-Fixer#23
Before
public function setDefaultOptions(OptionsResolverInterface $resolver) {
parent::setDefaultOptions($resolver);
}
After:
public function configureOptions(OptionsResolver $resolver) {
// Parent call renamed as well
parent::configureOptions($resolver);
}
This looks amazing! Really looking forward to testing it. One thing I noticed straight from the README, though. Shouldn't the nette, symfony, etc rectors be in their own repositories? I think it will be a pain, further down the road, to strip them from the main repo and notify everyone to update the dependencies, etc.
To prevent any install issues, like those report by @EdoBarnas on Windows
Not worth the pain for person who install this package
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.