mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
1.6 KiB
1.6 KiB
How to turn Magic to Explicit with Rectors?
Replace get/set
magic methods with real ones
services:
Rector\Rector\MagicDisclosure\GetAndSetToMethodCallRector:
$typeToMethodCalls:
# class
'Nette\DI\Container':
# magic method (prepared keys): new real method
'get': 'getService'
'set': 'addService'
For example:
- $result = $container['key'];
+ $result = $container->getService('key');
- $container['key'] = $value;
+ $container->addService('key', $value);
Replace isset/unset
magic methods with real ones
services:
Rector\Rector\MagicDisclosure\UnsetAndIssetToMethodCallRector:
$typeToMethodCalls:
# class
'Nette\DI\Container':
# magic method (prepared keys): new real method
'isset': 'hasService'
'unset': 'removeService'
For example:
- isset($container['key']);
+ $container->hasService('key');
- unset($container['key']);
+ $container->removeService('key');
Replace toString
magic method with real one
services:
Rector\Rector\MagicDisclosure\ToStringToMethodCallRector:
$typeToMethodCalls:
# class
'Symfony\Component\Config\ConfigCache':
# magic method (prepared key): new real method
'toString': 'getPath'
For example:
- $result = (string) $someValue;
+ $result = $someValue->getPath();
- $result = $someValue->__toString();
+ $result = $someValue->getPath();