Update module to utilize Dependency Injection instead of direct Drupal calls

Created on 16 April 2024, 2 months ago
Updated 7 May 2024, about 2 months ago

Description:

This issue aims to refactor the existing codebase to modern best practices by replacing direct calls to \Drupal:: static methods with dependency injection. Direct calls to \Drupal:: are considered deprecated and can lead to tight coupling and difficulties in testing and maintainability. By utilizing dependency injection, we can improve the codebase's modularity, flexibility, and testability.

Tasks

  1. Identify areas in the codebase where \Drupal:: static methods are used.
  2. Refactor the code to inject necessary dependencies instead of using \Drupal::.
  3. Test the refactored code to ensure functionality remains intact
📌 Task
Status

Fixed

Version

1.3

Component

Code

Created by

🇧🇷Brazil PabloNicolas

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @PabloNicolas
  • 🇧🇷Brazil PabloNicolas

    PabloNicolas → changed the visibility of the branch 3441260-update-module-to to hidden.

  • 🇧🇷Brazil PabloNicolas

    PabloNicolas → changed the visibility of the branch 3441260-update-module-to to active.

  • Status changed to Needs review 2 months ago
  • First commit to issue fork.
  • 🇮🇳India mitthukumawat

    I have checked all conding standard errors via phpcs and it was showing these :

    /modules/contrib $ phpcs --standard=DrupalPractice  --extensions=php,module,inc,install tripadvisor_integration/
    
    FILE: /modules/contrib/tripadvisor_integration/src/Form/TripAdvisorIntegrationAdminForm.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     50 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     54 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     59 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     63 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    /modules/contrib $ phpcs --standard=Drupal  --extensions=php,module,inc,install tripadvisor_integration/
    
    FILE: /modules/contrib/tripadvisor_integration/tripadvisor_integration.module
    ----------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------
     51 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
    ----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------
    
    
    FILE: /modules/contrib/tripadvisor_integration/src/Form/TripAdvisorIntegrationAdminForm.php
    ------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------
     20 | WARNING | Possible useless method overriding detected
    ------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /modules/contrib/tripadvisor_integration/src/Plugin/Field/FieldType/TripAdvisorItem.php
    --------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------
     36 | WARNING | Possible useless method overriding detected
    --------------------------------------------------------------------------------------------------------------------
    
    
    FILE:/modules/contrib/tripadvisor_integration/src/Plugin/Field/FieldFormatter/TripAdvisorFieldFormatter.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------------------------------
     27 | ERROR | Class property $cache_backend should use lowerCamel naming without underscores
     34 | ERROR | Class property $date_time should use lowerCamel naming without underscores
     41 | ERROR | Class property $module_extension_list should use lowerCamel naming without underscores
    -----------------------------------------------------------------------------------------------------------------------------------
    
    

    Most of the errors from above has been fixed except Possible useless method overriding detected.

  • 🇧🇷Brazil PabloNicolas

    Thank you for helping on this one mitthukumawat!

    My last commit fixed the remaining coding standards warning.

  • Status changed to Fixed 2 months ago
  • 🇬🇧United Kingdom joekers UK

    PR merged into the dev release - thanks for your work on this!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024