Fix the issues reported by phpcs

Created on 12 November 2020, over 4 years ago
Updated 23 May 2023, almost 2 years ago

Problem/Motivation

I think the code base should pass the PHPCS validation.

PHP CODE SNIFFER REPORT SUMMARY                                                                  
-------------------------------------------------------------------------------------------------
FILE                                                                             ERRORS  WARNINGS
-------------------------------------------------------------------------------------------------
.../entity_legal-3.0.x/entity_legal.module                                       0        3       
.../entity_legal-3.0.x/src/EntityLegalDocumentInterface.php                      0        1       
.../entity_legal-3.0.x/src/EntityLegalDocumentListBuilder.php                    0        1       
.../entity_legal-3.0.x/src/EntityLegalDocumentVersionViewBuilder.php             0        1       
.../entity_legal-3.0.x/src/EntityLegalPluginManager.php                          0        1       
.../entity_legal-3.0.x/src/Controller/EntityLegalController.php                  0        3       
.../entity_legal-3.0.x/src/Entity/EntityLegalDocumentAcceptance.php              0        1       
.../entity_legal-3.0.x/src/EventSubscriber/EntityLegalSubscriber.php             0        2       
.../entity_legal-3.0.x/src/Form/EntityLegalDocumentAcceptanceForm.php            0        2       
.../entity_legal-3.0.x/src/Form/EntityLegalDocumentForm.php                      2       22      
.../entity_legal-3.0.x/src/Form/EntityLegalDocumentVersionForm.php               0        5       
.../entity_legal-3.0.x/src/Plugin/EntityLegal/Message.php                        0        1       
.../entity_legal-3.0.x/src/Plugin/EntityLegal/ProfileForm.php                    1        0       
.../entity_legal-3.0.x/src/Tests/EntityLegalDocumentAcceptanceTest.php           0        2       
.../entity_legal-3.0.x/src/Tests/EntityLegalMethodsTest.php                      0        1       
.../entity_legal-3.0.x/src/Tests/EntityLegalTestBase.php                         0        1       
.../entity_legal-3.0.x/tests/modules/entity_legal_test/entity_legal_test.module  1        0       
.../entity_legal-3.0.x/tests/src/Functional/RedirectMethodTest.php               1        1       
-------------------------------------------------------------------------------------------------
A TOTAL OF 5 ERRORS AND 48 WARNINGS WERE FOUND IN 18 FILES                                       
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX 5 OF THESE SNIFF VIOLATIONS AUTOMATICALLY                                         
-------------------------------------------------------------------------------------------------

Steps to reproduce

Standards: Drupal,DrupalPractice
bin/phpcs --report=summary docroot/modules/contrib/entity_legal

Proposed resolution

Fix them all.

Remaining tasks

Fix them all.

📌 Task
Status

Fixed

Version

4.0

Component

Code

Created by

🇭🇺Hungary Sweetchuck Budapest

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

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 about 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -        'name' => $map['versions'][$id],
    -        'document_name' => $document_version->bundle(),
    -        'label' => $document_version->label(),
    -        'acceptance_label' => $document_version->get('acceptance_label'),
    -        'created' => $document_version->get('created'),
    -        'changed' => $document_version->get('changed'),
    +        'name'                       => $map['versions'][$id],
    +        'document_name'              => $document_version->bundle(),
    +        'label'                      => $document_version->label(),
    +        'acceptance_label'           => $document_version->get('acceptance_label'),
    +        'created'                    => $document_version->get('created'),
    +        'changed'                    => $document_version->get('changed'),
    
    -    $entity_manager->getStorage(ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
    +    $entity_manager->getStorage(EntityLegalInterface::ENTITY_LEGAL_DOCUMENT_ACCEPTANCE_ENTITY_NAME)
           ->create([
    -        'aid' => $document_acceptance->id(),
    +        'aid'                   => $document_acceptance->id(),
             'document_version_name' => $map['versions'][$map['acceptances'][$id]],
    -        'uid' => $document_acceptance->get('uid'),
    -        'acceptance_date' => $document_acceptance->get('acceptance_date'),
    -        'data' => isset($document_acceptance->getFields()['data']) ? $document_acceptance->get('data') : '',
    +        'uid'                   => $document_acceptance->get('uid'),
    +        'acceptance_date'       => $document_acceptance->get('acceptance_date'),
    +        'data'                  => isset($document_acceptance->getFields()['data']) ? $document_acceptance->get('data') : '',
           ])->save();

    The code was already correctly formatted.

    -
    -/**
    - * Cleanup sensitive data.
    - */
    -function entity_legal_update_9001(array &$sandbox = NULL) {
    -  $storage = \Drupal::entityTypeManager()->getStorage('entity_legal_document_acceptance');
    -  if (!isset($sandbox['ids'])) {
    -    $sandbox['ids'] = array_keys($storage->getQuery()->execute());
    -    $sandbox['total'] = count($sandbox['ids']);
    -    $sandbox['current'] = 0;
    -  }
    -
    -  $ids_to_process = array_splice($sandbox['ids'], 0, 50);
    -  $sandbox['current'] += count($ids_to_process);
    -  /** @var \Drupal\entity_legal\EntityLegalDocumentAcceptanceInterface $entity */
    -  foreach ($storage->loadMultiple($ids_to_process) as $entity) {
    -    $entity->set('data', serialize([]))->save();
    -  }
    -
    -  $sandbox['#finished'] = (int) empty($sandbox['ids']);
    -
    -  return t('Processed @current out of @total', [
    -    '@current' => $sandbox['current'],
    -    '@total' => $sandbox['total'],
    -  ]);
    -}

    Removing a hook is not what the Drupal coding standards say to do. If that hook is a problem, a new issue needs to be opened for that. On drupal.org, issues are created with a single purpose, not to fix everything wrong in a module.

    +  /**
    +   * The Messenger service.
    +   *
    +   * @var \Drupal\Core\Messenger\MessengerInterface
    +   */
    +  protected $messenger;

    Messenger should be written messenger, since it is not at the beginning of a sentence.

    -      \Drupal::messenger()->addMessage('You are viewing an unpublished version of this legal document.', 'warning');
    +      $this->messenger->addMessage('You are viewing an unpublished version of this legal document.', 'warning');
    

    The string passed to addMessage() needs to be translatable. Yes, that is the same error done by the existing code, but since the code is being changed, that should be changed too.

    -    $published_version = $storage->load($id);
     
    -    $current_langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
    -
    -    if ($published_version->hasTranslation($current_langcode)) {
    -      $published_version = $published_version->getTranslation($current_langcode);
    -    }
    -
    -    return $published_version;
    +    return $storage->load($id);

    Is there any reason that code is removed? Is that a coding standards issue?

    - * Class EntityLegalSubscriber.
    + * Class of EntityLegalSubscriber.

    A documentation comment for a class needs to describe what the class purpose is. Adding of does not make the comment better (and Class of EntityLegalSubscriber does not make sense).

    +  /**
    +   * EntityLegalSubscriber constructor.
    +   *
    +   * @param \Drupal\entity_legal\EntityLegalPluginManager $entityLegalPluginManager
    +   *   EntityLegalPluginManager service.
    +   */
    +  public function __construct(EntityLegalPluginManager $entityLegalPluginManager) {
    +    $this->entityLegalPluginManager = $entityLegalPluginManager;
    +  }

    The class name must include its namespace.

       /**
        * Builds a new form instance.
        *
        * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $private_temp_store_factory
        *   The private temp store factory service.
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
    +   *   The entityTypeManager service.
        */

    Constructor documentation comments always say which class is constructed.

  • Status changed to Needs review almost 2 years ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    Build Successful
  • @claudiucristea opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    Build Successful
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    14 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    18 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    18 pass
  • Status changed to Fixed almost 2 years ago
  • 🇷🇴Romania claudiu.cristea Arad 🇷🇴

    Thank you all. Fixed.

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

Production build 0.71.5 2024