SlideShare a Scribd company logo
1 of 54
Tackling
Tech Debt
with Rector
Michele Orselli
Eng Manager@Spreaker
_orso_
micheleorselli
michele.orselli@spreaker.com
● Spreaker is a podcast platform
● Within Spreaker, podcasts can be
hosted, distributed, monetized,
discovered, and listened to
● Part of iHeartMedia family since
2020
🤓 Expert teams can tame it, choosing willingly
to accumulate it
→ trade off cleaner solution with a good
enough one
Tech Debt
🐥 Green teams accumulate it unconsciously
→ let's try this and that
Never saw a project without it 🙄
The mere fact that
we are writing code
exposes us to tech debt
Tech Debt
-> Language Evolves
-> Libraries evolve
-> Frameworks evolve
-> Things are (re)discovered
How can we deal with it?
Invest 🕒 and ⚡
to repay the debt
😫 Sometimes it is hard
to justify the investment
🤔 Is there a way to get away
with it?
Tech Debt
Performs automated refactorings on a codebase
It provides a list of predefined rectors, aka rules, refactorings you can choose
to apply on your codebase, via a rector.php config file. E.g.
- Change a property access with a method call
from $obj->property to $obj->method()
- Substitute class invocation with another one
from Banana::method() to Apple::anotherMethod()
Rector
Provided a ton of rules out of the box
- Code style/quality
- Manipulate properties/methods
- Upgrade language version
- Upgrade framework version
Rector
https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md
Why do I need it?
-> Regexp are not enough?
-> Search and replace is not enough?
Rectors parses the code, so it can perform complex manipulation. For this
reason it is also unaffected by code formatting (spaces, newlines, …)
Rector
Installation/configuration
$ composer require rector/rector --dev
If you create custom rules, configure composer.json to enable autoload
"autoload-dev": {
"psr-4": {
"UtilsRector": "tools/php/rector/src",
"UtilsRectorTests": "tools/php/rector/tests"
}
}
Installation/configuration
Create an empty rector.php file in the project root directory
$ vendor/bin/rector init
Change rector.php to specify which directories should be scanned and which
rules should be applied
rector.php
<?php
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/apps',
__DIR__ . '/lib',
__DIR__ . '/test',
]);
$rectorConfig->rule(AddContainerAwareIfNotPresent::class);
$rectorConfig->rule(MigrateSpUtilStaticCallsRector::class);
};
Run
In the project root directory run
$ vendor/bin/rector process
If you want to see a preview of the changes without touching the files
$ vendor/bin/rector process --dry-run
Rules
RectorPhp74RectorPropertyTypedPropertyRector
TypedPropertyRector
RectorPhp80RectorClass_StringableForToStringRector
StringableForToStringRector
RectorPhp82RectorFuncCallUtf8DecodeEncodeToMbConvertEncodingRector
Utf8DecodeEncodeToMbConvertEncodingRector
Configurable Rules
Rule accepting configuration params
RectorTransformRectorClass_AddAllowDynamicPropertiesAttributeRector
AddAllowDynamicPropertiesAttributeRector
SetLists
Define a group of rules to avoid specify them one by one
rector.php
<?php
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/apps',
__DIR__ . '/lib',
__DIR__ . '/test',
]);
$rectorConfig->sets([SetList::DEAD_CODE, SetList::PHP_82]);
};
LevelSetLists
Applies all the rules up to a certain PHP version
rector.php
<?php
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/apps',
__DIR__ . '/lib',
__DIR__ . '/test',
]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_82]);
};
1. Loads configuration from rector.php
2. Iterates all files
3. For each file
a. Preparation phase: parse file, creates AST (array of nodes), add some
metadata
b. Rectify Phase
i. Traverse AST
ii. Check if rectors can be applied to that node
iii. If yse, apply
c. Save/Diff phase
How it works
A rule is a PHP class that extends AbstractRector
Implement 3 method
Writing Custom Rules
public function getRuleDefinition(): RuleDefinition
public function getNodeTypes(): array
public function refactor(Node $node): ?Node
Life of a PHP file 🐘
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
c
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
c
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
<?php
namespace AppTime;
c
class Clock
{
public function now()
{
return date('Y-m-d');
}
}
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Tokenizer
token_get_all
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Parser
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Parser
T_OPEN_TAG ('<?php')
T_NAMESPACE ('namespace')
T_WHITESPACE (' ')
T_STRING ('App')
T_NS_SEPARATOR ('')
T_STRING ('Time')
T_WHITESPACE (' ')
T_CLASS ('class')
T_WHITESPACE (' ')
T_STRING ('Clock')
T_WHITESPACE (' ')
T_WHITESPACE (' ')
T_PUBLIC ('public')
T_WHITESPACE (' ')
T_FUNCTION ('function')
T_WHITESPACE (' ')
T_STRING ('now')
T_WHITESPACE (' ')
T_WHITESPACE ('')
T_RETURN ('return')
T_WHITESPACE (' ')
T_STRING ('date')
T_CONSTANT_ENCAPSED_STRING
(''Y-m-d'')
T_WHITESPACE ('')
T_WHITESPACE ('')
T_WHITESPACE ('')
Parser
AST:
Abstract
Syntax
Tree
PHP-Parser
PHP Vm
AST:
Abstract
Syntax
Tree
Compiler
PHP Vm
AST:
Abstract
Syntax
Tree
Compiler
PHP Vm
Opcodes
AST:
Abstract
Syntax
Tree
Compiler
PHP Vm
Opcodes
AST:
Abstract
Syntax
Tree
AST - Abstract Syntax Tree
Intermediate representation of the source code
Machine friendly
Tree structure
Traversing the AST means
traversing the original source code
https://phpast.com/
https://github.com/rectorphp/php-parser-nodes-docs
PHP-Parser nodes docs
A rule is a PHP class that extends AbstractRector
Implement 3 method
Writing Custom Rules
public function getRuleDefinition(): RuleDefinition
public function getNodeTypes(): array
public function refactor(Node $node): ?Node
Look for existing rules that perform similar tasks. Use it as a starting point.
Look for helper classes: classes that perform some heavy lifting for you. E.g
pull up a property
There are plenty:
- ClassDependencyManipulator
- ClassInsertManipulator
- NodeFactory
- ParamAnalyzer
Create a small snippet of code to test it with --dry-run
Start with an existing rule
Let's 👀 at the code…
Look for a rule that does something similar to what you need and use it as a
starting point
This part is a bit time consuming, there are multiple ways to achieve the same
result
Don't try to do too much in a single rule, combine multiple rules
Writing Custom Rules: lesson learned
Get all the corner cases is hard, Pareto rulez!
NodeDumper is your friend
Create a Dummy snippet for quick testing
Writing Custom Rules: lesson learned
Extensions: composer installable set of rules for specific framework/libraries
These are provided out of the box
https://github.com/rectorphp/rector-symfony
https://github.com/rectorphp/rector-doctrine
https://github.com/rectorphp/rector-phpunit
Extensions
That's All Folks!
https://leanpub.com/rector-the-power-of-automated-refactoring
Questions?

More Related Content

Similar to Tackling Tech Debt with Rector

Spstc2011 managed metadata real world
Spstc2011 managed metadata real worldSpstc2011 managed metadata real world
Spstc2011 managed metadata real world
Atul Chhoda
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Victor Rentea
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 

Similar to Tackling Tech Debt with Rector (20)

Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Spstc2011 managed metadata real world
Spstc2011 managed metadata real worldSpstc2011 managed metadata real world
Spstc2011 managed metadata real world
 
Spstc2011 managed metadata real world
Spstc2011 managed metadata real worldSpstc2011 managed metadata real world
Spstc2011 managed metadata real world
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
TYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkTYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase framework
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
 
Symfony 1, mi viejo amigo
Symfony 1, mi viejo amigoSymfony 1, mi viejo amigo
Symfony 1, mi viejo amigo
 
Magento code audit
Magento code auditMagento code audit
Magento code audit
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Event Sourcing with php
Event Sourcing with phpEvent Sourcing with php
Event Sourcing with php
 
What's new in Doctrine
What's new in DoctrineWhat's new in Doctrine
What's new in Doctrine
 
Reactive programming with RxJS - Taiwan
Reactive programming with RxJS - TaiwanReactive programming with RxJS - Taiwan
Reactive programming with RxJS - Taiwan
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 

More from Michele Orselli

Developing sustainable php projects
Developing sustainable php projectsDeveloping sustainable php projects
Developing sustainable php projects
Michele Orselli
 

More from Michele Orselli (20)

A dive into Symfony 4
A dive into Symfony 4A dive into Symfony 4
A dive into Symfony 4
 
A recommendation engine for your applications codemotion ams
A recommendation engine for your applications codemotion amsA recommendation engine for your applications codemotion ams
A recommendation engine for your applications codemotion ams
 
A recommendation engine for your applications phpday
A recommendation engine for your applications phpdayA recommendation engine for your applications phpday
A recommendation engine for your applications phpday
 
Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17Hopping in clouds - phpuk 17
Hopping in clouds - phpuk 17
 
A recommendation engine for your php application
A recommendation engine for your php applicationA recommendation engine for your php application
A recommendation engine for your php application
 
Symfony e micro (non così tanto) services
Symfony e micro (non così tanto) servicesSymfony e micro (non così tanto) services
Symfony e micro (non così tanto) services
 
Hopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherHopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to another
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
Migrare a Symfony 3
Migrare a Symfony 3Migrare a Symfony 3
Migrare a Symfony 3
 
Vagrant for real
Vagrant for realVagrant for real
Vagrant for real
 
Implementing data sync apis for mibile apps @cloudconf
Implementing data sync apis for mibile apps @cloudconfImplementing data sync apis for mibile apps @cloudconf
Implementing data sync apis for mibile apps @cloudconf
 
Server side data sync for mobile apps with silex
Server side data sync for mobile apps with silexServer side data sync for mobile apps with silex
Server side data sync for mobile apps with silex
 
Continuous, continuous, continuous
Continuous, continuous, continuousContinuous, continuous, continuous
Continuous, continuous, continuous
 
Deploy a PHP App on Google App Engine
Deploy a PHP App on Google App EngineDeploy a PHP App on Google App Engine
Deploy a PHP App on Google App Engine
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
 
Deploy a php app on Google App Engine
Deploy a php app on Google App EngineDeploy a php app on Google App Engine
Deploy a php app on Google App Engine
 
Sf2 wtf
Sf2 wtfSf2 wtf
Sf2 wtf
 
Manage a project portfolio
Manage a project portfolioManage a project portfolio
Manage a project portfolio
 
Developing sustainable php projects
Developing sustainable php projectsDeveloping sustainable php projects
Developing sustainable php projects
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

Tackling Tech Debt with Rector

  • 3. ● Spreaker is a podcast platform ● Within Spreaker, podcasts can be hosted, distributed, monetized, discovered, and listened to ● Part of iHeartMedia family since 2020
  • 4. 🤓 Expert teams can tame it, choosing willingly to accumulate it → trade off cleaner solution with a good enough one Tech Debt 🐥 Green teams accumulate it unconsciously → let's try this and that Never saw a project without it 🙄
  • 5. The mere fact that we are writing code exposes us to tech debt Tech Debt -> Language Evolves -> Libraries evolve -> Frameworks evolve -> Things are (re)discovered
  • 6. How can we deal with it? Invest 🕒 and ⚡ to repay the debt 😫 Sometimes it is hard to justify the investment 🤔 Is there a way to get away with it? Tech Debt
  • 7. Performs automated refactorings on a codebase It provides a list of predefined rectors, aka rules, refactorings you can choose to apply on your codebase, via a rector.php config file. E.g. - Change a property access with a method call from $obj->property to $obj->method() - Substitute class invocation with another one from Banana::method() to Apple::anotherMethod() Rector
  • 8. Provided a ton of rules out of the box - Code style/quality - Manipulate properties/methods - Upgrade language version - Upgrade framework version Rector https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md
  • 9. Why do I need it? -> Regexp are not enough? -> Search and replace is not enough? Rectors parses the code, so it can perform complex manipulation. For this reason it is also unaffected by code formatting (spaces, newlines, …) Rector
  • 10. Installation/configuration $ composer require rector/rector --dev If you create custom rules, configure composer.json to enable autoload "autoload-dev": { "psr-4": { "UtilsRector": "tools/php/rector/src", "UtilsRectorTests": "tools/php/rector/tests" } }
  • 11. Installation/configuration Create an empty rector.php file in the project root directory $ vendor/bin/rector init Change rector.php to specify which directories should be scanned and which rules should be applied
  • 12. rector.php <?php return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/apps', __DIR__ . '/lib', __DIR__ . '/test', ]); $rectorConfig->rule(AddContainerAwareIfNotPresent::class); $rectorConfig->rule(MigrateSpUtilStaticCallsRector::class); };
  • 13. Run In the project root directory run $ vendor/bin/rector process If you want to see a preview of the changes without touching the files $ vendor/bin/rector process --dry-run
  • 14. Rules
  • 18. Configurable Rules Rule accepting configuration params
  • 20. SetLists Define a group of rules to avoid specify them one by one
  • 21. rector.php <?php return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/apps', __DIR__ . '/lib', __DIR__ . '/test', ]); $rectorConfig->sets([SetList::DEAD_CODE, SetList::PHP_82]); };
  • 22. LevelSetLists Applies all the rules up to a certain PHP version
  • 23. rector.php <?php return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/apps', __DIR__ . '/lib', __DIR__ . '/test', ]); $rectorConfig->sets([LevelSetList::UP_TO_PHP_82]); };
  • 24. 1. Loads configuration from rector.php 2. Iterates all files 3. For each file a. Preparation phase: parse file, creates AST (array of nodes), add some metadata b. Rectify Phase i. Traverse AST ii. Check if rectors can be applied to that node iii. If yse, apply c. Save/Diff phase How it works
  • 25. A rule is a PHP class that extends AbstractRector Implement 3 method Writing Custom Rules public function getRuleDefinition(): RuleDefinition public function getNodeTypes(): array public function refactor(Node $node): ?Node
  • 26. Life of a PHP file 🐘
  • 27. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } }
  • 28. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 29. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 30. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 31. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 32. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 33. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 34. <?php namespace AppTime; class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 35. <?php namespace AppTime; c class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 36. <?php namespace AppTime; c class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer
  • 37. <?php namespace AppTime; c class Clock { public function now() { return date('Y-m-d'); } } T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Tokenizer token_get_all
  • 38. T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Parser
  • 39. T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Parser
  • 40. T_OPEN_TAG ('<?php') T_NAMESPACE ('namespace') T_WHITESPACE (' ') T_STRING ('App') T_NS_SEPARATOR ('') T_STRING ('Time') T_WHITESPACE (' ') T_CLASS ('class') T_WHITESPACE (' ') T_STRING ('Clock') T_WHITESPACE (' ') T_WHITESPACE (' ') T_PUBLIC ('public') T_WHITESPACE (' ') T_FUNCTION ('function') T_WHITESPACE (' ') T_STRING ('now') T_WHITESPACE (' ') T_WHITESPACE ('') T_RETURN ('return') T_WHITESPACE (' ') T_STRING ('date') T_CONSTANT_ENCAPSED_STRING (''Y-m-d'') T_WHITESPACE ('') T_WHITESPACE ('') T_WHITESPACE ('') Parser AST: Abstract Syntax Tree PHP-Parser
  • 45. AST - Abstract Syntax Tree Intermediate representation of the source code Machine friendly Tree structure Traversing the AST means traversing the original source code
  • 48. A rule is a PHP class that extends AbstractRector Implement 3 method Writing Custom Rules public function getRuleDefinition(): RuleDefinition public function getNodeTypes(): array public function refactor(Node $node): ?Node
  • 49. Look for existing rules that perform similar tasks. Use it as a starting point. Look for helper classes: classes that perform some heavy lifting for you. E.g pull up a property There are plenty: - ClassDependencyManipulator - ClassInsertManipulator - NodeFactory - ParamAnalyzer Create a small snippet of code to test it with --dry-run Start with an existing rule
  • 50. Let's 👀 at the code…
  • 51. Look for a rule that does something similar to what you need and use it as a starting point This part is a bit time consuming, there are multiple ways to achieve the same result Don't try to do too much in a single rule, combine multiple rules Writing Custom Rules: lesson learned
  • 52. Get all the corner cases is hard, Pareto rulez! NodeDumper is your friend Create a Dummy snippet for quick testing Writing Custom Rules: lesson learned
  • 53. Extensions: composer installable set of rules for specific framework/libraries These are provided out of the box https://github.com/rectorphp/rector-symfony https://github.com/rectorphp/rector-doctrine https://github.com/rectorphp/rector-phpunit Extensions