Fix the issues reported by phpcs

Created on 13 April 2023, about 1 year ago
Updated 14 February 2024, 5 months ago

Problem/Motivation

FILE: ...ibution/drupal10/web/modules/contrib/scaleflex_cloudimage/js/cloudimage.js
--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------
9 | ERROR | [x] Whitespace found at end of line
18 | ERROR | [x] Whitespace found at end of line
19 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...eb/modules/contrib/scaleflex_cloudimage/scaleflex_cloudimage.libraries.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
10 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...b/modules/contrib/scaleflex_cloudimage/scaleflex_cloudimage.links.menu.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
6 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...l10/web/modules/contrib/scaleflex_cloudimage/scaleflex_cloudimage.info.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
5 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...web/modules/contrib/scaleflex_cloudimage/scaleflex_cloudimage.services.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
4 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...rupal10/web/modules/contrib/scaleflex_cloudimage/src/CloudimageService.php
--------------------------------------------------------------------------------
FOUND 18 ERRORS AND 2 WARNINGS AFFECTING 11 LINES
--------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
5 | ERROR | [x] Non-namespaced classes/interfaces/traits should not be
| | referenced with use statements
12 | ERROR | [x] Missing class doc comment
28 | ERROR | [x] Missing function doc comment
34 | ERROR | [x] Missing function doc comment
36 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency
| | injection instead
38 | ERROR | [x] Expected 1 space after IF keyword; 0 found
38 | ERROR | [x] Expected 1 space after closing parenthesis; found 5
43 | ERROR | [x] Expected 1 space after IF keyword; 0 found
43 | ERROR | [x] Expected 1 space after closing parenthesis; found 9
45 | ERROR | [x] Space found before comma in argument list
47 | ERROR | [x] Expected 1 space after ELSE keyword; 0 found
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
63 | ERROR | [x] Concat operator must be surrounded by a single space
69 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 19 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...pal10/web/modules/contrib/scaleflex_cloudimage/src/Form/CloudimageForm.php
--------------------------------------------------------------------------------
FOUND 17 ERRORS AND 4 WARNINGS AFFECTING 17 LINES
--------------------------------------------------------------------------------
1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
14 | WARNING | [ ] The class short comment should describe what the class does
| | and not simply repeat the class name
17 | ERROR | [ ] Missing member variable doc comment
19 | ERROR | [x] Missing function doc comment
35 | ERROR | [x] There should be no white space after an opening "["
35 | ERROR | [x] There should be no white space before a closing "]"
44 | ERROR | [x] Expected 1 space before "="; 0 found
45 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
46 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
47 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
48 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
48 | WARNING | [ ] t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and
| | $this->t() instead
49 | ERROR | [x] Array closing indentation error, expected 4 spaces but
| | found 6
51 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
51 | ERROR | [x] Expected 1 space before "="; 0 found
55 | WARNING | [ ] t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and
| | $this->t() instead
57 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
57 | ERROR | [x] Expected 1 space before "="; 0 found
61 | WARNING | [ ] t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and
| | $this->t() instead
75 | ERROR | [x] Expected 1 blank line after function; 0 found
76 | ERROR | [x] The closing brace for the class must have an empty line
| | before it
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 16 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...ution/drupal10/web/modules/contrib/scaleflex_cloudimage/css/cloudimage.css
--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------
2 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
5 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
6 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...pal10/web/modules/contrib/scaleflex_cloudimage/scaleflex_cloudimage.module
--------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 6 LINES
--------------------------------------------------------------------------------
1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
1 | ERROR | [x] Missing file doc comment
7 | ERROR | [x] Expected 1 blank line before function; 2 found
22 | ERROR | [x] Whitespace found at end of line
23 | ERROR | [x] Missing function doc comment
23 | ERROR | [x] Expected 1 space before opening brace; found 0
26 | ERROR | [x] Concat operator must be surrounded by a single space
26 | ERROR | [x] Concat operator must be surrounded by a single space
46 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 333ms; Memory: 10MB

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig scaleflex_cloudimage/

Proposed resolution

Resolve all errors and warnings for Drupal and DrupalPractice coding standards

Remaining tasks

Patch review.

Remaining issue:
FILE: ...rupal10/web/modules/contrib/scaleflex_cloudimage/src/CloudimageService.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
44 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

Time: 323ms; Memory: 10MB

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇳India urvashi_vora Madhya Pradesh, 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

  • Issue created by @urvashi_vora
  • 🇵🇭Philippines kenyoOwen

    Hi urvashi_vora

    I applied the patch coding-standard-fixes.patch to the “Scaleflex Cloudimage” module against Version 1.0.x-dev and there is still remaining issue. I will transition this to needs work so others can fix the remaining issue. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sakthi_dev

    Resolved the issue. Please review.

  • Status changed to RTBC about 1 year ago
  • 🇵🇭Philippines kenyoOwen

    Hi sakthi_dev

    I applied the patch #3 to the “Scaleflex Cloudimage” module against Version 1.0.x-dev and confirmed that it fixed the remaining issue. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * @file
    + * Module File.
    + */

    The usual short description is Hook implementations for the [module name] module.

    +/**
    + * Cloud Image Service.
    + */
     class CloudimageService {
    

    An article is missing from the short description.
    Image and Service are misspelled, since they are not at the beginning of the sentence.

    +  /**
    +   * Router for get the base url.
    +   *
    +   * @var \Drupal\Core\Routing\RequestContext

    url is misspelled.
    That class is not a router.

    -      $message = "{ \n" . "status".":"."success".",\n"."count_added".":". count($images) ."\n }";
    +      $message = "{ \n" . "status" . ":" . "success" . ",\n" . "count_added" . ":" . count($images) . "\n }";
           $this->logger->notice($message);

    Strings passed as first argument to logger methods must use placeholders, not be a concatenation of strings.

     /**
    - * Class CloudimageForm.
    + * Cloud image Form.
      *
      * @package Drupal\scaleflex_cloudimage\Form
      */
     class CloudimageForm extends ConfigFormBase {

    The short description must not contain the class name.
    Form is misspelled.

    +  /**
    +   * {@inheritdoc}
    +   */
       private $cloudimageConfig;

    {@inheritdoc} is not used for properties that are not inherited from the parent class or defined from an interface.

    +  /**
    +   * {@inheritdoc}
    +   */
       public function __construct(ConfigFactoryInterface $config_factory) {

    It is not even used for class constructors.

  • 🇮🇳India Preethy_ray

    pray_12 made their first commit to this issue’s fork.

  • Status changed to Needs review 7 months ago
  • 🇮🇳India Preethy_ray

    Fixed the issues reported by phpcs.

  • Status changed to Needs work 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * @file
    + * Adds CloudImage source to image variables if the route is not node edit form.
    + */

    The usual description for a .module file is Hook implementations for the [module name] module. where [module name] is the name of the module given in its .info.yml file.

     /**
      * Implements hook_page_attachments().
      */
    +
    +/**
    + * Adds CloudImage-related attachments to the page.
    + */
     function scaleflex_cloudimage_page_attachments(array &$attachments) {

    Each function/method must have only a single documentation comment. The existing one is already correct.

    -function scaleflex_cloudimage_preprocess_html(array &$variables){
    +
    +/**
    + * Adds CloudImage attributes to HTML variables for specific pages.
    + */
    +function scaleflex_cloudimage_preprocess_html(array &$variables) {

    That is not the correct documentation comment for a preprocess hook. It should be similar to Implements hook_preprocess_HOOK() for image.html.twig.

    +/**
    + * Provides methods to interact with the Cloudimage service.
    + *
    + * This class encapsulates functionality related to Cloudimage services,
    + * allowing interaction with Cloudimage APIs and related operations.
    + */

    The long description is not necessary.

    + /**
    + * Constructs a new CloudimageService object.
    + *
    + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    + * The configuration factory service.
    + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
    + * The logger channel factory service.
    + * @param \Drupal\Core\File\FileSystemInterface $file_system
    + * The file system service.
    + * @param \GuzzleHttp\ClientInterface $http_client
    + * The Guzzle HTTP client.
    + * @param \Drupal\Core\Routing\RouterInterface $router
    + * The router service.
    + */

    The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.

    -      $response = $client->post('https://warmup.api.cloudimage.com/warmup/urls', [
    +      // $response = new Response();
    +      // $client = new Client();
    +      $response = $this->httpClient->post('https://warmup.api.cloudimage.com/warmup/urls', [
             'headers' => [
               'X-Client-Key' => $config->get('client_key'),

    Code that is not necessary is removed, not commented out.

    +  /**
    +   * Represents the Cloudimage configuration.
    +   *
    +   * @var \Drupal\Core\Config\ImmutableConfig
    +   */
       private $cloudimageConfig;

    The config object. is sufficient.

  • Status changed to Needs review 7 months ago
  • 🇮🇳India sakthi_dev

    Addressed the comment #8. Please review.

  • Status changed to Needs work 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +/**
    + * @file
    + * Hook implementations for the Scaleflex Cloudimage.
    + */
    Hook implementations for the Scaleflex Cloudimage module.
     /**
      * Implements hook_page_attachments().
    + *
    + * Adds CloudImage-related attachments to the page.
      */
     function scaleflex_cloudimage_page_attachments(array &$attachments) {

    The longer description essentially says what the short description already says; it is not necessary.

    +/**
    + * Implements hook_preprocess_html().
    + */
    +function scaleflex_cloudimage_preprocess_html(array &$variables) {

    The short description must be Implements hook_preprocess_HOOK() for [template filename].

     /**
      * Implements hook_cron().
      */
    +
    +/**
    + * Perform CloudImage-related tasks during cron runs.
    + */
     function scaleflex_cloudimage_cron() {

    Each function/method must have a single documentation comment. This patch is adding a new documentation comment to a function which has already a documentation comment.

    +  /**
    +   * The Cloudimage settings.
    +   *
    +   * @var \Drupal\Core\Config\ImmutableConfig
    +   */
    +  protected $cloudimageSettings;

    The config object. is sufficient.

    +  /**
    +   * Constructs a new class instance.
    +   *
    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   The configuration factory service.
    +   */
    

    The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.
    That holds true for every class constructors.

  • Assigned to nitin_lama
  • 🇮🇳India nitin_lama

    Addressing comment #10. Providing updated patch.

  • Merge request !1#3353886: MR for the changes. → (Open) created by nitin_lama
  • Status changed to Needs review 7 months ago
  • 🇮🇳India nitin_lama

    Please review.

  • Issue was unassigned.
  • Hi, Reviewed the patch #12, applied cleanly and fixes all errors. And addresses the comments #10.
    Thank you!

Production build 0.69.0 2024