PHP code example of ingenerator / risky-rector-rules

1. Go to this page and download the library: Download ingenerator/risky-rector-rules 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/ */

    

ingenerator / risky-rector-rules example snippets


return RectorConfig::configure()
    // ... your existing Rector config
    ->withRules([
      \Ingenerator\RiskyRectorRules\PhpDocToStrictTypes\AddParamTypeFromPhpDocRector::class,
      \Ingenerator\RiskyRectorRules\PhpDocToStrictTypes\AddPropertyTypeFromPhpDocRector::class,
      \Ingenerator\RiskyRectorRules\PhpDocToStrictTypes\AddReturnTypeFromPhpDocRector::class,
      // We recommend running this rule in a *separate* commit, as it may add void returns to methods
      // where the return type was accidentally undocumented.
      \Ingenerator\RiskyRectorRules\PhpDocToStrictTypes\AddImplicitVoidInterfaceReturnTypeRector::class,
    ]);

use Ingenerator\RiskyRectorRules\PhpDocToStrictTypes\AddMethodTypeConfig;

return RectorConfig::configure()
    ->withConfiguredRule(AddParamTypeFromPhpDocRector::class, [AddMethodTypeConfig::INTERFACES_ONLY => true])
    ->withConfiguredRule(AddReturnTypeFromPhpDocRector::class, [AddMethodTypeConfig::INTERFACES_ONLY => true]);

class A {
  public function print(string $a) {
    echo $a;
  }
}

class B extends A {
{
  public function print($a) {
    echo $a ?? '{null}'
  }
}

$b = new B();
$b->print(null);

class A {
  public function print(string $a) {
    echo $a;
  }
}

class B extends A {
{
  public function print(string $a) {
    echo $a ?? '{null}'
  }
}

$b = new B();
$b->print(null);