Use null coalesce operator instead of ternary operator.

Created on 10 July 2023, over 1 year ago
Updated 20 August 2024, 7 months ago

Problem/Motivation

PHPCS throws the null coalesce operator error for the files: SettingsForm.php and AopProductWidget.php

Here's the report:
FILE: C:\xampp\htdocs\backendassignment\web\modules\custom\amazon_onsite\src\Plugin\Field\FieldWidget\AopProductWidget.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
--------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
29 | ERROR | [x] Use null coalesce operator instead of ternary operator.
35 | ERROR | [x] Use null coalesce operator instead of ternary operator.
41 | ERROR | [x] Use null coalesce operator instead of ternary operator.
47 | ERROR | [x] Use null coalesce operator instead of ternary operator.
53 | ERROR | [x] Use null coalesce operator instead of ternary operator.
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\custom\amazon_onsite\src\Form\SettingsForm.php
--------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
142 | ERROR | [x] Use null coalesce operator instead of ternary operator.
144 | ERROR | [x] Use null coalesce operator instead of ternary operator.
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

Steps to reproduce

Run the phpcs command on the module.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

šŸ“Œ Task
Status

RTBC

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India sidharth_soman Bangalore

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

Comments & Activities

  • Issue created by @sidharth_soman
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins ā†’ Open on Drupal.org ā†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    1 pass
  • šŸ‡®šŸ‡³India sidharth_soman Bangalore

    I have fixed the issue and attached a patch. Please review.

  • Status changed to RTBC 7 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @sidharth_soman,

    I applied patch #2, it was applied smoothly, and fixed all the issues related to the null coalesce.

    āžœ  amazon_onsite git:(1.x) curl https://www.drupal.org/files/issues/2023-07-10/3373610-2.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  3123  100  3123    0     0  10668      0 --:--:-- --:--:-- --:--:-- 10695
    patching file amazon_onsite.permissions.yml
    patching file src/Form/SettingsForm.php
    patching file src/Plugin/Field/FieldWidget/AopProductWidget.php
    āžœ  amazon_onsite git:(1.x) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml amazon_onsite
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/amazon_onsite/README.md
    --------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------
     5 | WARNING | Line exceeds 80 characters; contains 87 characters
    --------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/amazon_onsite/src/AopFeedItemListBuilder.php
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Datetime\DateFormatterInterface.
    -------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 388ms; Memory: 10MB
    
    āžœ  contrib

    I am moving the status to RTBC since this issue only focuses on the issues mentioned in the description.

    Thank you.

Production build 0.71.5 2024