Closed murugappanrm closed 1 year ago
Not yet, really. What particular operation do you think about?
One of the major aspects and goodness of PHP it extensively support OOP. In VS Code in my scripts i have defined and used class and quite often i would need to re-organize my classes and class methods. In the example below:
Original code:
<?php
declare(strict_types=1);
use App\Classes\Home;
use App\Classes\Invoice;
use App\Router;
// use Kirby\Filesystem\Dir;
// use Kirby\Toolkit\Str;
require __DIR__ . '/../vendor/autoload.php';
session_start();
define('STORAGE_PATH', __DIR__ . '/../storage');
$router = new Router();
// register a route
/*
* Long Method
$router->register('/', [Home::class, 'index']);
$router->register('/invoices', [Invoice::class, 'index']);
*/
// d($_SERVER);
$router
->get('/', [Home::class, 'index'])
->post('/upload', [Home::class, 'upload'])
->get('/invoices', [Invoice::class, 'index'])
->get('/invoices/create', [Invoice::class, 'create'])
->post('/invoices/store', [Invoice::class, 'store']);
// d($router->getRoutes());
echo ($router->resolve(
$_SERVER['REQUEST_URI'],
strtolower($_SERVER['REQUEST_METHOD'])
));
I need to refactor all classes to have the suffix "Controller" and the namespace which contains "Classes" to "Controllers" as below:
<?php
declare(strict_types=1);
use App\Controllers\HomeController;
use App\Controllers\InvoiceController;
use App\Router;
// use Kirby\Filesystem\Dir;
// use Kirby\Toolkit\Str;
require __DIR__ . '/../vendor/autoload.php';
session_start();
define('STORAGE_PATH', __DIR__ . '/../storage');
$router = new Router();
// register a route
/*
* Long Method
$router->register('/', [Home::class, 'index']);
$router->register('/invoices', [Invoice::class, 'index']);
*/
// d($_SERVER);
$router
->get('/', [HomeController::class, 'index'])
->post('/upload', [HomeController::class, 'upload'])
->get('/invoices', [InvoiceController::class, 'index'])
->get('/invoices/create', [InvoiceController::class, 'create'])
->post('/invoices/store', [InvoiceController::class, 'store']);
// d($router->getRoutes());
echo ($router->resolve(
$_SERVER['REQUEST_URI'],
strtolower($_SERVER['REQUEST_METHOD'])
));
At first, this looks more like a simpler renaming operation. Multi-file renaming is still a rather late development in the plugin and frankly, I was waiting for some of my own experience and that of others to see whether it already behaves reliably or not yet. As such, I didn't yet want to touch renames that also change the path of the file but it might come next. I would also need to implement storing some of the analysis for later reuse, to keep the burden of always calculating everything and storing in memory all the time (of course, this only becomes problematic for larger projects) but that is a slippery terrain requiring lots of testing. :-)
So in simple terms can i assume it does not work?
You can rename individual classes but there's nothing that renames a full set of related classes automatically.
It needs rename the classes across all the scripts. Otherwise, it would defeat the purpose of refactoring.
It does so. But, as I mentioned in the README, I still recommend to get a preview first, then allow it to happen. As you can read there, the plugin is still new and developed actively.
Hi,
Does this extension refactors classes, interfaces, etc.? The documentation does not state so.