Refactor the initial value in __construct() by using the 'InlineConstructorDefaultToPropertyRector' rule of Drupal rector

Created on 9 November 2023, 8 months ago
Updated 10 November 2023, 8 months ago

Problem/Motivation

  • Run a drupal-rector analysis ./vendor/bin/rector process web/modules/contrib/cloud --dry-run on the module will show:
    1) web/modules/contrib/cloud/modules/cloud_service_providers/vmware/src/Controller/ApiController.php:88
    
        ---------- begin diff ----------
    @@ @@
        *
        * @var array
        */
    -  protected $configuration;
    +  protected $configuration = ['cloud_context' => ''];
    
       /**
        * The current user.
    @@ @@
         $this->database = $database;
         $this->cloudService = $cloud_service;
         $this->currentUser = $current_user;
    -    $this->configuration = ['cloud_context' => ''];
       }
    
       /**
        ----------- end diff -----------
    
    Applied rules:
     * InlineConstructorDefaultToPropertyRector
    
    
    2) web/modules/contrib/cloud/modules/cloud_service_providers/k8s/src/Controller/ApiController.php:110
    
        ---------- begin diff ----------
    @@ @@
        *
        * @var array
        */
    -  private $configuration;
    +  private $configuration = ['cloud_context' => ''];
    
       /**
        * The cloud service provider plugin manager (CloudConfigPluginManager).
    @@ @@
         $this->cloudStorePluginManager = $plugin_manager;
         $this->cloudService = $cloud_service;
         $this->currentUser = $current_user;
    -    $this->configuration = ['cloud_context' => ''];
         $this->cloudConfigPluginManager = $cloud_config_plugin_manager;
       }
        ----------- end diff -----------
    
    Applied rules:
     * InlineConstructorDefaultToPropertyRector
    
    
    3) web/modules/contrib/cloud/modules/cloud_service_providers/openstack/src/Controller/ApiController.php:88
    
        ---------- begin diff ----------
    @@ @@
        *
        * @var array
        */
    -  protected $configuration;
    +  protected $configuration = ['cloud_context' => ''];
    
       /**
        * The current user.
    @@ @@
         $this->renderer = $renderer;
         $this->cloudService = $cloud_service;
         $this->currentUser = $current_user;
    -    $this->configuration = ['cloud_context' => ''];
         $this->openStackOperationsService = $openstack_operations_service;
         $this->openStackService = $openstack_service;
         $this->httpClient = $http_client;
        ----------- end diff -----------
    
    Applied rules:
     * InlineConstructorDefaultToPropertyRector
    
    
    4) web/modules/contrib/cloud/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php:124
    
        ---------- begin diff ----------
    @@ @@
        *
        * @var array
        */
    -  protected $configuration;
    +  protected $configuration = ['cloud_context' => ''];
    
       /**
        * ApiController constructor.
    @@ @@
         $this->cloudService = $cloud_service;
         $this->entityTypeManager = $entity_type_manager;
         $this->currentUser = $current_user;
    -    $this->configuration = ['cloud_context' => ''];
       }
    
       /**
        ----------- end diff -----------
    
    Applied rules:
     * InlineConstructorDefaultToPropertyRector
    

Proposed resolution

Fix the warnings.

📌 Task
Status

Fixed

Version

6.0

Component

Code

Created by

🇮🇳India MukhtarM

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024