Fix the issues reported by phpcs

Created on 16 May 2023, over 1 year ago
Updated 26 May 2023, over 1 year ago

Problem/Motivation

PHPCS reported few errors and warnings mentioned in text document "PHPCS-report.txt"

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 integration_chargebee/

Proposed resolution

Fix all the errors and warnings

Remaining tasks

Patch Review.

Excluded "\Drupal calls should be avoided in classes, use dependency injection instead" error because it is already in progress with " https://www.drupal.org/project/integration_chargebee/issues/3360299 ๐Ÿ“Œ Use Dependency Injection on integration_chargebee module Fixed "

๐Ÿ“Œ Task
Status

Fixed

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

Comments & Activities

  • Issue created by @urvashi_vora
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
       requirements:
    +    # Access Admin Page Permission
         _permission: 'access administration pages'
    

    The warning is the following.

    The administration page callback should probably use "administer site configuration" - which implies the user can change something - rather than "access administration pages" which is about viewing but not changing configurations.

    Adding a comment before the _permission line does not change the required permission for those routes.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Rajan Kumar

    Rajan Kumar โ†’ made their first commit to this issueโ€™s fork.

  • @rajan-kumar opened merge request.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Rajan Kumar

    Please review and merge code.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -    ->fields('sub', ['uid', 'subscription_id', 'plan_id', 'status', 'current_term_start', 'current_term_end'])
    +    ->fields('sub', [
    +      'uid',
    +      'subscription_id',
    +      'plan_id',
    +      'status',
    +      'current_term_start',
    +      'current_term_end',
    +    ])

    Code lines are allowed to exceed 80 characters, if they are more readable. The existing code is more readable than the changed code.

         _controller: '\Drupal\integration_chargebee\Controller\PaymentController::success'
         _title: 'Thank you'
       requirements:
    -    _access: 'TRUE'
    +    _permission: 'access content'

    The report does not say that _access: 'TRUE' must be removed from that route definition, but that a comment explaining why _access: 'TRUE' is used must be added.

         _controller: '\Drupal\integration_chargebee\Controller\CheckoutController::plan'
         _title: 'Subscribe Plan'
       requirements:
    -    _access: 'TRUE'
    -
    +    _permission: 'access content'

    The same holds true for this route definition.

    +   * The ConfigFactory.
    +   *
        * @var \Drupal\Core\Config\ConfigFactory

    ConfigFactory is misspelled.

    +   * @param \Drupal\Core\Config\ConfigFactory $configFactory
    +   *   The renderer.

    The description is wrong.

    +  /**
        * Construct a new AuthController object.
        *
    +   * @param \Drupal\Core\Config\ConfigFactory $configFactory

    Since that comment is change, also the method description must be changed: The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

       /**
    -   * integration_chargebee Service.
    +   * Integration_chargebee Service.

    integration_chargebee is the module machine name and it does not describe this service's purpose.
    Service is misspelled, since it must be spelled using lowercase letters.

    +  /**
        * Drupal config.
        *
        * @var \Drupal\Core\Config\ConfigFactoryInterface
        */
       protected $configFactory;

    Since that documentation comment is changed, also the property description must be changed, as property descriptions must not start with Drupal.

    +  /**
    +   * The RequestStack service.
    +   *
    +   * @var Symfony\Component\HttpFoundation\RequestStack
    +   */
    +  protected $requestStack;

    The request stack. is a better description.

        *   The config factory for the form.
    +   * @param Symfony\Component\HttpFoundation\RequestStack $requestStack
    +   *   The request service.

    The request stack. is a better description.

    - /**
    +  /**
        * Entity manager.
        *
        * @var \Drupal\Core\Entity\EntityTypeManagerInterface
        */
       protected $entityTypeManager;
     
    - /**
    +  /**
        * Database connection.
        *

    Since those comments have been changed, a definite article must be added to both the descriptions.

    +  /**
    +   * Class Constructor.
        *
        * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
        *   The config factory for the form.
        */
    +  public function __construct(ConfigFactoryInterface $config_factory) {

    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +    # Access granted in all circumstances.
         _access: 'TRUE'

    That does not explain why.

       /**
    +   * The Config Factory.
    +   *
        * @var \Drupal\Core\Config\ConfigFactory

    Only the first word in the description must be capitalized.

    +  /**
    +   * Construct a new CheckoutController object.

    The class namespace is missing.

     /**
    - * An example controller.
    + * An User controller.
      */

    The indefinite article to use with user is the other one.

        *   Connection.
        * @param \Drupal\Core\Messenger\Messenger $messenger
        *   Messenger.

    Since that documentation comment is changed, the definite article needs to be added to both those descriptions.

     /**
    - * Class ChargebeePlanForm.
    + * Class Chargebee Plan Form.

    That is still repeating the class name. Adding spaces does not change that.

        * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
        *   The config factory for the form.

    Since that documentation comment is changed, that description must be changed too: The config factory. is sufficient.

    +  /**
    +   * Create tableselect for plans list.
    +   */
    +  public function integrationChargebeeCreatePlansSelectTable($plans) {

    The verb must be declined to the third person singular.

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia shashank5563 New Delhi
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia shashank5563 New Delhi

    @apaderno, For the permission issue, I will create another issue. Now, I merging this issue.

  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia shashank5563 New Delhi

    @apaderno, I am marking fixed this issue. I will create another issue for the permission.

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

Production build 0.71.5 2024