Fix the issues reported by phpcs.

Created on 22 June 2023, over 1 year ago
Updated 7 November 2023, about 1 year ago

Problem/Motivation

Getting following error/warnings:

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\views_conditional\src\Plugin\views\field\ViewsConditionalField.php
----------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------------
233 | ERROR | Missing parameter type
236 | ERROR | Return type missing for @return tag in function comment
263 | WARNING | Only string literals should be passed to t() where possible
266 | WARNING | Only string literals should be passed to t() where possible
----------------------------------------------------------------------------------------------------------------------

FILE: D:\xampp\htdocs\drupal_10\web\modules\contrib\views_conditional\views_conditional.install
-----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------
32 | WARNING | Unused variable $display_name.
-----------------------------------------------------------------------------------------------

Steps to reproduce

Run following command:

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml views_conditional/

Proposed resolution

Above error/warnings need to be fixed.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India arti_parmar

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

Comments & Activities

  • Issue created by @arti_parmar
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • 🇮🇳India arti_parmar

    Kindly review patch.

  • Status changed to RTBC over 1 year ago
  • 🇵🇭Philippines clarkssquared

    Hi arti_parmar

    I applied your patch #2 to the VIews Conditional Module v8.x-1.x-dev and I confirmed that your patch fixed all the PHPCS issues.

    Please look at the screenshot attached for your reference

    Thank you

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States shelane

    Removing translation from an if statement specifically intended on providing translation is not how to fix the t usage issue.

    • shelane committed 8efb389a on 8.x-1.x
      Issue #3368593 by arti_parmar, shelane: Fix the issues reported by phpcs
      
  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States shelane

    I have verified the current use case of t() with the variables:

    Your code checks the 'then_translate' and 'or_translate' options before applying translation. This approach ensures that the t() function is only used when necessary and adheres to good coding practices. The use of variables for translation strings in conditional scenarios, like yours, is a valid and practical use case.

    Given the constraints of your code and the requirement to translate conditionally based on user settings, you've handled the situation correctly. It's important to balance best practices with the practicality of your specific use case, and your implementation seems appropriate given the context.

    I've applied these fixes and more that come up with I check for strict rules.

    • shelane committed 711978c4 on 8.x-1.x
      Issue #3368593 by shelane: Fix the issues reported by phpcs
      
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024