Fix the issues reported by phpcs

Created on 27 July 2020, over 4 years ago
Updated 14 March 2024, 8 months ago

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml shows the following warnings/errors which should be fixed.

FILE: ./css/galleryslider.css
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 19 | ERROR | [x] Spaces must be used for alignment; tabs are not
    |       |     allowed
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./galleryslider.module
----------------------------------------------------------------------
FOUND 14 ERRORS AND 3 WARNINGS AFFECTING 10 LINES
----------------------------------------------------------------------
  13 | WARNING | [ ] Hook implementations should not duplicate @param
     |         |     documentation
  13 | ERROR   | [ ] Missing parameter comment
  13 | ERROR   | [ ] Missing parameter type
  14 | WARNING | [ ] Hook implementations should not duplicate @param
     |         |     documentation
  14 | ERROR   | [ ] Missing parameter comment
  16 | WARNING | [ ] Hook implementations should not duplicate
     |         |     @return documentation
  16 | ERROR   | [ ] Description for the @return value is missing
  49 | ERROR   | [ ] Missing parameter comment
  49 | ERROR   | [ ] Missing parameter type
  96 | ERROR   | [ ] Missing parameter comment
  96 | ERROR   | [ ] Missing parameter type
 109 | ERROR   | [ ] Missing parameter comment
 111 | ERROR   | [ ] Description for the @return value is missing
 122 | ERROR   | [x] Use null coalesce operator instead of ternary
     |         |     operator.
 128 | ERROR   | [ ] Missing parameter comment
 128 | ERROR   | [ ] Missing parameter type
 130 | ERROR   | [ ] Description for the @return value is missing
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldFormatter/GallerySliderFieldFormatter.php
----------------------------------------------------------------------
FOUND 4 ERRORS AND 3 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
   6 | WARNING | [x] Unused use statement
   9 | WARNING | [x] Unused use statement
  34 | ERROR   | [ ] Missing member variable doc comment
  35 | ERROR   | [ ] Missing member variable doc comment
 163 | WARNING | [x] 'TODO: Implement settings summary.' should match
     |         |     the format '@todo Fix problem X here.'
 169 | ERROR   | [x] There must be exactly one blank line before the
     |         |     tags in a doc comment
 232 | ERROR   | [x] Use null coalesce operator instead of ternary
     |         |     operator.
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Plugin/views/style/GallerySlider.php
----------------------------------------------------------------------
FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------
  5 | WARNING | [x] Unused use statement
  7 | WARNING | [x] Unused use statement
 55 | ERROR   | [ ] Missing parameter comment
 55 | ERROR   | [ ] Missing parameter type
 56 | ERROR   | [ ] Missing parameter comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
📌 Task
Status

Needs review

Version

3.0

Component

Code

Created by

🇮🇳India nitesh624 Ranchi, India

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    - * @param null $key
    + * @param string $key
    + *   The default keys in galleryslider settings.
      *
      * @return array|mixed
    + *   An array with all settings key.
    

    Since the parameter is $key and it is a string, probably the default keys (plural) is not correct. It is not even the default key.
    The function does not always return an array. That needs to be made clear.

      * @return mixed
    + *   Formatted js array.
      */
    -function _galleryslider_format_settings($settings) {
    +function _galleryslider_format_settings(array $settings) {

    If it is mixed, it is not an array.

    -  var rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g;
    +  var rvalidescape = /\\(?:["\\\/bfnrt] | u[\da - fA - F]{4}) / g;

    Spaces inside a regular expression are wrong, except in the case they are part of the regular expression, which does not seem in this case.

    +   *    options: an optional list of space-separated options that will change how
    +   *            the callback list behaves or a more traditional option object
    

    Lines are indented by two spaces.

    -   *	once:			will ensure the callback list can only be fired once (like a Deferred)
    +   *    once:            will ensure the callback list can only be fired once (like a Deferred)
    

    The line was already correctly indented (two spaces).

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India chaitanyadessai Goa

    Fixed issues reported by phpcs.

  • 🇮🇳India arpitk

    Hi I reviewed the patch #19 it applied cleanly. No more errors/warnings are produced. I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig . to test on version 8.x-3.x-dev and drupal 9.5.9

    Thanks!

  • Hello Folks !!
    Created a patch for galleryslider 8.x-3.x-dev . The patch seems to fix the phpcs issues.
    Can someone please review the patch.

    Thank you for your support!!!

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Build Successful
  • Status changed to RTBC over 1 year ago
  • 🇮🇳India Anmol_Specbee

    The patch#20 mentioned in the comment#21 is working and is resolving all the issues.

  • @Anmol_Specbee , thanks for confirmation :)

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -/**
    - * @file
    - * Contains galleryslider.module..
    - */

    A module file needs to contain that comment, but the description given there is Hook implementations for the Gallery Slider for Multiple Images module. (assuming that the module name shown in the .info.yml file is Gallery Slider for Multiple Images).

    diff --git a/galleryslider.module b/galleryslider.module
    index b3ea4ce..52553c2 100644
    --- a/galleryslider.module
    +++ b/galleryslider.module
    @@ -1,159 +1,89 @@
     <?php
     
    -/**
    - * @file
    - * Contains galleryslider.module..
    - */
    +namespace Drupal\galleryslider\Plugin\views\style;
     
    -use Drupal\Core\Routing\RouteMatchInterface;
    +use Drupal\Core\Form\FormStateInterface;
    +use Drupal\views\Plugin\views\style\StylePluginBase;
     
     /**
    - * Implements hook_help().
    + * Style plugin to render each item into a simple carousel.
      *
    - * @param $route_name
    - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
    + * @ingroup views_style_plugins
      *
    - * @return string
    + * @ViewsStyle(
    + *   id = "galleryslider",
    + *   title = @Translation("Gallery Slider"),
    + *   help = @Translation("Displays rows as a gallery slider."),
    + *   theme = "galleryslider_views",
    + *   display_types = {"normal"}
    + * )
      */
    -function galleryslider_help($route_name, RouteMatchInterface $route_match) {
    -  switch ($route_name) {
    -    // Main module help for the simple module.
    -    case 'help.page.galleryslider':
    -      $output = '';
    -      $output .= '<h3>' . t('About') . '</h3>';
    -      $output .= '<p>' . t('simple Carousel: Download code at drupal.org') . '</p>';
    -      $output .= '<p>' . t('Video tutorial will be uploaded soon') . '</p>';
    -      return $output;
    -
    -    default:
    -  }
    -}
    +class GallerySlider extends StylePluginBase {
     
    -/**
    - * Implements hook_theme().
    - */
    -function galleryslider_theme() {
    -  return [
    -    'galleryslider' => [
    -      'variables' => ['items' => NULL, 'settings' => NULL],
    -    ],
    -    'galleryslider_views' => [
    -      'variables' => [],
    -    ],
    -  ];
    -}
    -
    -/**
    - * Themeable for galleryslider.
    - *
    - * @param $variables
    - */
    -function template_preprocess_galleryslider(&$variables) {
    -  $items = $variables['items'];
    -  $settings = _galleryslider_format_settings($variables['settings']);
    -  $variables['attributes']['class'][] = 'slider';
    -  $variables['attributes']['class'][] = '';
    -  $variables['attributes']['data-settings'] = json_encode($settings);
    -  $html = '';
    -  if (!empty($items)) {
    -    $i = 0;
    -    $html .= '<ul data-title="Row">';
    -    foreach ($items as $item) {
    -      $html .= '<li  ' . $i . '>' . render($item) . '</li>';
    -      $i++;
    -    }
    -  }
    +  /**
    +   * Indicates whether the style plugin allows the use of row plugins.
    +   *
    +   * @var bool
    +   */
    +  protected $usesRowPlugin = TRUE;
     
    -  $html .= '</ul>';
    -  $output = [
    -    '#type' => 'markup',
    -    '#markup' => $html,
    -  ];
    -  $variables['output'] = render($output);
    -}
    +  /**
    +   * Indicates whether the style plugin supports custom CSS class for the rows.
    +   *
    +   * @var bool
    +   */
    +  protected $usesRowClass = TRUE;
     
    -/**
    - * Prepares variables for Views galleryslider carousel templates.
    - *
    - * Default template: galleryslider-views.html.twig.
    - *
    - * @param array $variables
    - *   An associative array containing:
    - *   - view: A View object.
    - */
    -function template_preprocess_galleryslider_views(array &$variables) {
    -  $handler = $variables['view']->style_plugin;
    -  $settings = _galleryslider_format_settings($handler->options);
    -  $variables['attributes']['class'][] = 'slider ';
    -  $variables['attributes']['class'][] = '';
    -  $variables['attributes']['data-settings'] = json_encode($settings);
    -  template_preprocess_views_view_unformatted($variables);
    -}
    +  /**
    +   * Defines the default options for the style plugin.
    +   */
    +  protected function defineOptions() {
    +    $options = parent::defineOptions();
     
    -/**
    - * Settings to display view at front page.
    - *
    - * @param $variables
    - */
    -function galleryslider_preprocess_page(&$variables) {
    -  $node = \Drupal::routeMatch()->getParameter('node');
    -  $frontpage = \Drupal::service('path.matcher')->isFrontPage();
    -  if ($node || $frontpage) {
    -    $variables['#attached']['library'][] = 'galleryslider/galleryslider';
    +    $settings = _galleryslider_default_settings();
    +    foreach ($settings as $k => $v) {
    +      $options[$k] = ['default' => $v];
    +    }
    +    return $options;
       }
    -}
     
    -/**
    - * Default settings for simple.
    - *
    - * @param null $key
    - *
    - * @return array|mixed
    - */
    -function _galleryslider_default_settings($key = NULL) {
    -  $settings = [
    -    'menu' => 'grid',
    -    'imgGrid' => '',
    -    'speed' => 300,
    -    'image_style' => '',
    -    'image_link' => '',
    -  ];
    -
    -  return isset($settings[$key]) ? $settings[$key] : $settings;
    -}
    

    Removing the hook implementations from that file to add a class (which should not be placed in a .module file) is blatantly wrong.

  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • hello @apaderno, hope you are doing well.
    updated the patch addressed #24 issues.
    kindly review the updated patch.
    Thank you for your support.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    diff --git a/galleryslider.module b/galleryslider.module
    index 52553c2..ff875fd 100644
    --- a/galleryslider.module
    +++ b/galleryslider.module
    @@ -1,89 +1,166 @@
     <?php
     
    -namespace Drupal\galleryslider\Plugin\views\style;
    +/**
    + * @file
    + * Contains the Gallery Slider for Multiple Images module.
    + */

    I take the patch is created from the wrong files, since the first lines from the galleryslider.module are the following one.

    <?php
    
    /**
     * @file
     * Contains galleryslider.module..
     */
    
    use Drupal\Core\Routing\RouteMatchInterface;
    
    /**
     * Implements hook_help().
     *
     * @param $route_name
     * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
     *
     * @return string
     */
    
  • 🇮🇳India AkashKumar07

    This patch addresses the #11 changes. Please review.
    Thanks!

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • Status changed to Needs review over 1 year ago
  • The last submitted patch, 27: 3161596-27.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • 🇮🇳India zkhan.aamir

    Hi,

    Patch #27 applied successfully.

    Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib/galleryslider (8.x-3.x)
    $ curl https://www.drupal.org/files/issues/2023-06-22/3161596-27.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 17884  100 17884    0     0  33384      0 --:--:-- --:--:-- --:--:-- 33490
    patching file css/galleryslider.css
    patching file galleryslider.module
    patching file js/galleryslider.js
    patching file js/gridSlide.js
    patching file js/slider.js
    patching file src/Plugin/Field/FieldFormatter/GallerySliderFieldFormatter.php
    patching file src/Plugin/views/style/GallerySlider.php
    

    All the issue resolved.

  • Hi, patch #27 applied cleanly but it not fixes all the phpcs issues.

    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml galleryslider/
    
    FILE: C:\Users\Nisha\galleryslider\css\galleryslider.css
    ----------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------
     1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
    ----------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Nisha\galleryslider\css\gridslide.css
    ----------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------
     1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
    ----------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Nisha\galleryslider\galleryslider.install
    ----------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------
     1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
    ----------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Nisha\galleryslider\galleryslider.module
    ------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ------------------------------------------------------------------------------------
       1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
     121 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    ------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Nisha\galleryslider\src\Plugin\Field\FieldFormatter\GallerySliderFieldFormatter.php
    -----------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------
       1 | ERROR   | [x] End of line character is invalid; expected "\n" but found "\r\n"
     172 | WARNING | [x] 'TODO: Implement settings summary.' should match the format '@todo Fix problem
         |         |     X here.'
     242 | ERROR   | [x] Use null coalesce operator instead of ternary operator.
    -----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------
    
    
    FILE: C:\Users\Nisha\galleryslider\src\Plugin\views\style\GallerySlider.php
    ----------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------
     1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
    ----------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------
    
    Time: 474ms; Memory: 10MB
    
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 10 months ago
    Waiting for branch to pass
  • First commit to issue fork.
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 9 months ago
    Waiting for branch to pass
  • First commit to issue fork.
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 8 months ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 8 months ago
    Waiting for branch to pass
  • Pipeline finished with Canceled
    8 months ago
    Total: 67s
    #118978
  • Pipeline finished with Success
    8 months ago
    Total: 196s
    #118980
Production build 0.71.5 2024