Fix the issues reported by phpcs

Created on 3 January 2023, almost 2 years ago
Updated 1 March 2024, 9 months ago

PHPCS report the following errors,


FILE: /json_ld_schema_ui/src/Form/EntitySchemaConfigurationForm.php
-----------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 4 WARNINGS AFFECTING 6 LINES
-----------------------------------------------------------------------------------------------------------------------------
  98 | WARNING | [ ] Unused variable $id.
 255 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 267 | ERROR   | [x] Array indentation error, expected 10 spaces but found 8
 268 | ERROR   | [x] Array indentation error, expected 10 spaces but found 8
 414 | WARNING | [ ] Unused variable $active_properties.
 460 | WARNING | [ ] Unused variable $active_properties.
-----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------


FILE: /json_ld_schema_ui/src/Form/EntitySchemaAddPropertyForm.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------------
 231 | WARNING | [ ] Unused variable $active_properties.
 249 | ERROR   | [x] list(...) is forbidden, use [...] instead.
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------


FILE: /json_ld_schema_ui/src/Entity/ContentSchemaSettings.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------
 207 | ERROR | [x] list(...) is forbidden, use [...] instead.
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------


FILE: /json_ld_schema_ui/src/Plugin/DataType/SchemaOverrides.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------------------------------
 39 | WARNING | Unused variable $schema_type.
 41 | WARNING | Unused variable $property_path.
--------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig /json_ld_schema_ui

Please just fix the errors and warnings, that could not be fixed automatically using PHPCBF

PHPCBF code fixing has been fixed on this issue : https://www.drupal.org/project/json_ld_schema_ui/issues/3330903 โ†’

๐Ÿ“Œ Task
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany SolimanHarkas

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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akram Khan Cuttack, Odisha

    Still there are issue remanning

    akram.khan@C02FC0PWML7M ~ % phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml /Users/akram.khan/Desktop/Contribution/drupal9.5.x/drupal/json_ld_schema_ui

    FILE: ...Contribution/drupal9.5.x/drupal/json_ld_schema_ui/json_ld_schema_ui.module
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
    --------------------------------------------------------------------------------
    8 | WARNING | [x] Unused use statement
    9 | WARNING | [x] Unused use statement
    12 | WARNING | [x] Unused use statement
    13 | WARNING | [x] Unused use statement
    14 | WARNING | [x] Unused use statement
    17 | WARNING | [x] Unused use statement
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------

    FILE: ...m.khan/Desktop/Contribution/drupal9.5.x/drupal/json_ld_schema_ui/README.md
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
    70 | WARNING | Line exceeds 80 characters; contains 101 characters
    --------------------------------------------------------------------------------

    FILE: ...l9.5.x/drupal/json_ld_schema_ui/src/Form/EntitySchemaConfigurationForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
    419 | WARNING | Unused variable $active_properties.
    465 | WARNING | Unused variable $active_properties.
    --------------------------------------------------------------------------------

    FILE: ...pal9.5.x/drupal/json_ld_schema_ui/src/Form/EntitySchemaAddPropertyForm.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    --------------------------------------------------------------------------------
    231 | WARNING | [ ] Unused variable $active_properties.
    249 | ERROR | [x] list(...) is forbidden, use [...] instead.
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------

    FILE: .../drupal9.5.x/drupal/json_ld_schema_ui/src/Entity/ContentSchemaSettings.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
    207 | ERROR | [x] list(...) is forbidden, use [...] instead.
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------

    FILE: ...upal9.5.x/drupal/json_ld_schema_ui/src/Plugin/DataType/SchemaOverrides.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
    39 | WARNING | Unused variable $schema_type.
    41 | WARNING | Unused variable $property_path.
    --------------------------------------------------------------------------------

    Time: 813ms; Memory: 12MB

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akram Khan Cuttack, Odisha

    added updated patch and fixed some PHPCS issue

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    The issue summary should always describe what the issue is trying to fix and, in the case, of coding standards issues, show which command has been used, which arguments have been used, and which report that command shown.

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

    The Needs work status is for the issue summary that does not report the arguments passed to phpcs.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Summary updated.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nayana_mvr

    Verified the patch #8. The patch applied cleanly but its showing a new warning message now:

    FILE: .../contrib/json_ld_schema_ui/src/Plugin/DataType/SchemaOverrides.php
    -----------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------
     41 | WARNING | Unused variable $override.
    -----------------------------------------------------------------------------------------------------------------------------
    
    Time: 665ms; Memory: 14MB

    All other issues are fixed.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +Settings > Settings_ (`/admin/config/search/schemaorg/settings`).
    +The default settings for the schema
     should be fine for most websites. Note that the settings are currently not
     properly validated, so changing them can break the functionality of the module.
    

    Moving The default settings for the schema on a new line is correct, but then the rest of the text need to be reformatted, as the line containing The default settings for the schema is too short.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia TanujJain-TJ

    after applying #8 got this phpcs error

    FILE: /src/Form/EntitySchemaConfigurationForm.php
    --------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     272 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
     273 | ERROR | [x] Array indentation error, expected 8 spaces but found 10
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: src/Plugin/DataType/SchemaOverrides.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     41 | WARNING | Unused variable $override.
    --------------------------------------------------------------------------------

    Adding a new patch to fix this error and for now commenting the code to remove unused variable error as it was todo, also addressing changes mentioned in #14.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Mahima_Mathur23

    Verified the patch.
    The changes raised by @apaderno have been incorporated and there are no more Phpcs errors.

    Moving to RTBC.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -    $active_properties = &$schema_properties;
         foreach (array_slice($property_path, 1, -1) as $property) {
           $active_properties = &$active_properties[$property]['properties'];
         }

    Since the line initializing $active_properties has been removed, how can $active_properties = &$active_properties[$property]['properties']; work?

             // Traverse the property path so we know where to set the values.
    -        $active_properties = &$schema_properties;
             foreach (array_slice(explode('|', $property_path), 1) as $property_label) {
               $active_properties = &$active_properties[$property_label]['properties'];
             }

    Similarly, how can $active_properties = &$active_properties[$property_label]['properties']; work?

    -    foreach ($value as $schema_type => $overrides) {
    -      // @todo Validate schema types here.
    -      foreach ($overrides as $property_path => $override) {
    -        // @todo Validate property path here.
    -      }
    -    }
    -
    +    // Commenting to remove phpcs error of unused variable
    +    // foreach ($value as $overrides) {
    +    // // @todo Validate schema types here.
    +    // foreach ($overrides as $override) {
    +    // // @todo Validate property path here.
    +    // }
    +    // }
    +    // change line indentation after removing comment.
         parent::setValue($value, $notify);

    No, code is not commented out just to avoid to get a PHP_CodeSniffer error.
    Furthermore, the commented out code is not even correctly indented.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia subhashuyadav Mumbai
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia subhashuyadav Mumbai

    Updated the patch as per #18 comment

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -
    -    // Traverse the property path so we know where to set the new one.
    -    $active_properties = &$schema_properties;
    -    foreach (array_slice(explode('|', $form_state->get('property_path')), 1) as $property) {
    -      $active_properties = &$active_properties[$property]['properties'];
    -    }
    -
    -    $property = $form_state->getValue('property');
    -    $property_type = $form_state->getValue('property_type');
    -    $property_label = $this->schemaData->getSchemaLabel($property);
    -
    -    // Simple values default to empty strings that can't be overridden.
    -    if ($property_type == '***simple***') {
    -      $active_properties[$property_label] = [
    -        'default_value' => '',
    -        'allow_override' => FALSE,
    -      ];
    -    }
    -    // Complex values default to setting the @type property of the subtype.
    -    else {
    -      list($sub_type_id, $hash) = explode('#', $property_type);
    -      if ($hash == 'enum') {
    -        $active_properties[$property_label] = [
    -          'default_value' => '',
    -          'allow_override' => FALSE,
    -          'enum_type' => $sub_type_id,
    -        ];
    -      }
    -      else {
    -        $sub_type_label = $this->schemaData->getSchemaLabel($sub_type_id);
    -        $active_properties[$property_label]['properties']['@type'] = [
    -          'default_value' => $sub_type_label,
    -          'allow_override' => FALSE,
    -        ];
    -      }
    -    }
    -
    -    $property_path = explode('|', $values['property_path']);
    -
    -    // Traverse the property path so we know which one to remove.
    -    $active_properties = &$schema_properties;
    -    foreach (array_slice($property_path, 1, -1) as $property) {
    -      $active_properties = &$active_properties[$property]['properties'];
    -    }
    -    $property = end($property_path);
     
    -    unset($active_properties[$property]);
    -      $php_safe_id = str_replace('.', '_', $schema_setting->id());
    -      $values = $form_state->getValue([$php_safe_id, 'properties']);
    -
           $schema_properties = $schema_setting->getSchemaProperties();
    -      foreach ($values as $property_path => $property_values) {
    -        if (empty($property_values['table'])) {
    -          continue;
    -        }
    -
    -        // Traverse the property path so we know where to set the values.
    -        $active_properties = &$schema_properties;
    -        foreach (array_slice(explode('|', $property_path), 1) as $property_label) {
    -          $active_properties = &$active_properties[$property_label]['properties'];
    -        }
    -
    -        foreach ($property_values['table'] as $property_label => $property_settings) {
    -          if (!isset($property_settings['default_value'])) {
    -            continue;
    -          }
    -
    -          $active_properties[$property_label]['default_value'] = $property_settings['default_value'];
    -          $active_properties[$property_label]['allow_override'] = (bool) $property_settings['allow_override'];
    -        }
    -      }
    -
    

    Why is all that code removed? It does not seem that is required by the PHP_CodeSniffer report shown in the issue summary.

    -    foreach ($value as $schema_type => $overrides) {
    -      // @todo Validate schema types here.
    -      foreach ($overrides as $property_path => $override) {
    -        // @todo Validate property path here.
    -      }
    -    }
    

    Why should that code, which contains also two @todo comments, be removed?

  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres

    This issue will be fixed on https://www.drupal.org/project/json_ld_schema_ui/issues/3330907 ๐Ÿ“Œ Fix the issues reported by phpcs Needs review .

    Closing for duplicated.

  • Status changed to Closed: duplicate 9 months ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain gxleano Cรกceres
Production build 0.71.5 2024