Skip to content

Instantly share code, notes, and snippets.

@Tjitse-E
Created January 29, 2024 13:50
Show Gist options
  • Save Tjitse-E/b368670a80a2ab357e59acec02562fc9 to your computer and use it in GitHub Desktop.
Save Tjitse-E/b368670a80a2ab357e59acec02562fc9 to your computer and use it in GitHub Desktop.
Add missing dynamic properties using RectorPHP
<?php
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
// Define directories to check
$directories = [
__DIR__ . '/app/code',
__DIR__ . '/extensions'
];
// Filter out directories that do not exist
$existingDirectories = array_filter($directories, function ($dir) {
return is_dir($dir);
});
// Add existing directories to the configuration
$rectorConfig->paths($existingDirectories);
};
@peterjaap
Copy link

Additions to also check template files;

    // Define directories to check
    $directories = [
        __DIR__ . '/app/code',
        __DIR__ . '/app/design',
        __DIR__ . '/extensions'
    ];
   // Add phtml
   $rectorConfig->fileExtensions(['php', 'phtml']);

@peterjaap
Copy link

Also add to check for the PHP version you're upgrading to;

   // PHP 8.2 upgrade
   $rectorConfig->sets([Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment