PHP code example of becklyn / rector

1. Go to this page and download the library: Download becklyn/rector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

becklyn / rector example snippets


// rector.php

use Becklyn\Rector\Symfony\ReplaceControllerThisGetWithThisContainerGet;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
    // …
    
    $rectorConfig->rule(ReplaceControllerThisGetWithThisContainerGet::class);
    
    // …
};

class ExtendingAbstractController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
    public function run()
    {
        $this->get(SomeClass::class);
    }

    public function runFaster()
    {
        $service = $this->get(SomeOtherClass::class);
    }

    public function runEvenFaster()
    {
        return $this->get(BestClass::class);
    }
}

class ExtendingAbstractController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
    public function run()
    {
        $this->container->get(SomeClass::class);
    }

    public function runFaster()
    {
        $service = $this->container->get(SomeOtherClass::class);
    }

    public function runEvenFaster()
    {
        return $this->container->get(BestClass::class);
    }
}