Fix the issues reported by phpcs

Created on 9 June 2023, over 1 year ago
Updated 19 July 2024, 2 months ago
šŸ“Œ Task
Status

Needs work

Version

2.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
  • Assigned to arpitk
  • šŸ‡®šŸ‡³India arpitk

    Reviewing this.

  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    +/**
    + * @file
    + * Drupal hooks for installation, updating and checking requirements.
    + */
    +

    The usual description is Install, update and uninstall functions for the [module name] module. where [module name] is the module name reported in the .info.yml file. It is even better when hooks is used instead of functions, but both are correct.

    -	//get the config
    +  // Get the config.
       $config = \Drupal::config('menu_custom_access.settings');
    -    //If admin user, allow menu access
    -    if($is_admin_user) return AccessResult::neutral();
    +    // If admin user, allow menu access.
    +    if ($is_admin_user) {
    +      return AccessResult::neutral();
    +    }

    Since those comments are edited, they can also be removed, as there is no need to comment those code lines.

    -  //loop through the menus so we can use it later
    +  // Loop through the menus so we can use it later.
       $set_menu_options = [];
    -  foreach ($menus as $k => $v) {
    - 	 if(!empty($v)) {
    - 	 	$set_menu_options[] = $v;
    - 	 }
    +  foreach ($menus as $v) {
    +    if (!empty($v)) {
    +      $set_menu_options[] = $v;
    +    }

    Since that comment is edited, it can also be removed, as it is not clear what it tries to say.

    -    //check to make sure the we are giving access to the correct account
    +    // Check to make sure the we are giving access to the correct account.
         $account_does_not_have_role = array_diff($account->getRoles(TRUE), $config->get('menu_custom_access.roles'));
    -    if(!empty($account_does_not_have_role)) {

    Since that comment is edited, it should also be corrected: Articles are generally not used before personal pronouns; that comment can simply be Make sure we are giving access to the correct account.

    +  /**
    +   * The config factory service.
    +   *
    +   * @var \Drupal\Core\Config\ConfigFactoryInterface
    +   */
    +  protected $configFactory;
    +
    +  /**
    +   * The messenger service.
    +   *
    +   * @var \Drupal\Core\Messenger\MessengerInterface
    +   */
    +  protected $messenger;

    It is not necessary to say they are services.

    +  /**
    +   * Constructs a new RouteAccessChecks object.
    +   *
    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   The config factory service.
    +   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
    +   *   The messenger service.
    +   */
    +  public function __construct(ConfigFactoryInterface $config_factory, MessengerInterface $messenger) {

    The class name is missing the namespace.

       /**
        * A custom access check.
        *
    +   * @param \Symfony\Component\Routing\Route $route
    +   *   The route being accessed.
    +   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
    +   *   The current route match.
        * @param \Drupal\Core\Session\AccountInterface $account
    -   *   Run access checks for this account.
    +   *   The user account trying to access the route.
    +   *
    +   * @return \Drupal\Core\Access\AccessResultInterface
    +   *   The access result indicating whether access is allowed or denied.
        */

    Since that documentation comment is edited, the short description should be corrected too: It should start with a verb; classes that implement AccessInterface use a description that starts with Checks access to the .
    For the parameter descriptions, I would do like EntityAccessCheck::access() does.

    -    // Always allow for adminsitrators
    +    // Always allow for adminsitrators.
         if (in_array('administrator', $user_roles)) {
           return AccessResult::allowed();
         }

    That comment is not necessary.

  • Assigned to nitin_lama
  • Issue was unassigned.
  • Assigned to imustakim
  • šŸ‡®šŸ‡³India imustakim Ahmedabad
  • Issue was unassigned.
  • šŸ‡®šŸ‡³India imustakim Ahmedabad

    Addressed mentioned points in #3 šŸ“Œ Fix the issues reported by phpcs Needs review .
    Please review.
    Only these warnings are showing up because of the constructor description including class namespace, assuming this can be ignored.

    FILE: /Users/specbee/Sites/Projects/menu_custom_access/src/Form/MenuCustomAccessConfigForm.php
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------
     50 | WARNING | Line exceeds 80 characters; contains 88 characters
    ----------------------------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/menu_custom_access/src/AccessChecks/RouteAccessChecks.php
    ---------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------
     34 | WARNING | Line exceeds 80 characters; contains 87 characters
    ---------------------------------------------------------------------------------------------
    
    Time: 124ms; Memory: 10MB
    
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India imustakim Ahmedabad

    Status changed.

  • Status changed to Needs work 2 months ago
  • Hi @imustakim,

    Applied the patch you provided, it was applied not-so successfully and multiple errors were still thrown. Please see below:

    menu_custom_access git:(main) āœ— curl https://www.drupal.org/files/issues/2023-06-18/3365858-7.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 21142  100 21142    0     0  56767      0 --:--:-- --:--:-- --:--:-- 58242
    patching file README.md
    patching file menu_custom_access.info.yml
    Hunk #1 FAILED at 3.
    1 out of 1 hunk FAILED -- saving rejects to file menu_custom_access.info.yml.rej
    patching file menu_custom_access.install
    patching file menu_custom_access.module
    patching file menu_custom_access.permissions.yml
    patching file menu_custom_access.routing.yml
    patching file menu_custom_access.services.yml
    patching file src/AccessChecks/RouteAccessChecks.php
    patching file src/Form/MenuCustomAccessConfigForm.php
    patching file src/Routing/AdminRouteSubscriber.php
    āžœ  menu_custom_access git:(main) āœ— cd ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig menu_custom_access
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue/web/modules/contrib/menu_custom_access/menu_custom_access.info.yml
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------------------
     1 | WARNING | Remove "project" from the info file, it will be added by drupal.org packaging automatically
     1 | WARNING | Remove "datestamp" from the info file, it will be added by drupal.org packaging automatically
     1 | WARNING | Remove "version" from the info file, it will be added by drupal.org packaging automatically
     6 | WARNING | All dependencies must be prefixed with the project name, for example "drupal:"
    -----------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue/web/modules/contrib/menu_custom_access/src/Form/MenuCustomAccessConfigForm.php
    -----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------------------------------
     50 | WARNING | [ ] Line exceeds 80 characters; contains 88 characters
     68 | ERROR   | [x] Multi-line function declarations must have a trailing comma after the last parameter
    -----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue/web/modules/contrib/menu_custom_access/src/AccessChecks/RouteAccessChecks.php
    ---------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------
      8 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Routing\Access\AccessInterface.
     34 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
    ---------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 208ms; Memory: 10MB

    Kindly check

    Thanks,
    Jake

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    Let's create a merge request, now that patches are no longer tested.

  • Assigned to hetal.solanki
  • Issue was unassigned.
  • šŸ‡®šŸ‡³India hetal.solanki

    @apaderno

    Do we need to create MR for phpcs issue?

    Thank you!!

  • Pipeline finished with Success
    2 months ago
    Total: 160s
    #228608
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
Production build 0.71.5 2024