Fix Coding Standards

Created on 7 April 2023, over 1 year ago
Updated 2 September 2023, over 1 year ago

Problem/Motivation

Getting following error/warnings.

FILE: /var/www/html/modules/contrib/ayrshare/modules/ayrshare_node/src/Form/SettingsForm.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
87 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/ayrshare/modules/ayrshare_node/src/Plugin/views/field/UnserializedData.php
-------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------
21 | ERROR | unserialize() is insecure unless allowed classes are limited. Use a safe format like JSON or use the allowed_classes option.
-------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/ayrshare/modules/ayrshare_node/src/Controller/NodeController.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
24 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/ayrshare/src/AyrshareApiClient.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------------------------
145 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
638 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
646 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------------------------------------------------------------------------------------------------

Time: 1.58 secs; Memory: 8MB

Steps to reproduce

Run following command

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

Proposed resolution

Above error/warnings need to be fixed.

๐Ÿ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

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

Comments & Activities

  • Issue created by @samit.310@gmail.com
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Above errors/warnings has been fixed.

  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines kenyoOwen

    Hi samit.310@gmail.com

    I applied patch #2 to the โ€œAyrshareโ€ module against Version 1.0.x-dev and confirmed that the error and warnings are resolved. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -   * @return string
    +   * @return array
        *   Return Hello string.
        */
       public function tools($node) {
         return [
           '#type' => 'html_tag',
           '#tag' => 'p',
    -      '#value' => t("Ayrshares gives you the tools to schedule social 
    -        media posts to Twitter, Facebook Pages and Groups, LinkedIn, Instagram, 
    -        YouTube, Reddit, Google My Business, Pinterest, TikTok, and Telegram via 
    -        a REST API. You can post to all your, or your user's, linked social 
    +      '#value' => $this->t("Ayrshares gives you the tools to schedule social
    +        media posts to Twitter, Facebook Pages and Groups, LinkedIn, Instagram,
    +        YouTube, Reddit, Google My Business, Pinterest, TikTok, and Telegram via
    +        a REST API. You can post to all your, or your user's, linked social
             networks with a single API call."),
         ];

    Since the @return line has been changed, also the return value description must be changed: What returned is not a Hello string.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Ashutosh Ahirwal India

    Providing patch with fixes.

  • First commit to issue fork.
  • @naveenvalecha opened merge request.
  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024