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.

Comments

arti_parmar created an issue. See original summary.

arti_parmar’s picture

Assigned: arti_parmar » Unassigned
Status: Active » Needs review
StatusFileSize
new2.09 KB

Kindly review patch.

clarkssquared’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new142.37 KB

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

shelane’s picture

Status: Reviewed & tested by the community » Needs work

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
    
shelane’s picture

Status: Needs work » Fixed

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
    

Status: Fixed » Closed (fixed)

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